자세 조정
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"assert": "cpp",
|
"assert": "cpp",
|
||||||
"zstring": "cpp"
|
"zstring": "cpp",
|
||||||
|
"ostream": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,10 @@ add_executable(${PROJECT_NAME}
|
|||||||
)
|
)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../include
|
${CMAKE_CURRENT_SOURCE_DIR}/../include
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct Chattr::Socket_Init socket(AF_INET, SOCK_STREAM, 0);
|
struct Chattr::Socket_Init socket;
|
||||||
std::cout << "Hello, world!" << socket.get() << std::endl;
|
std::cout << "Hello, world!" << socket << std::endl;
|
||||||
}
|
}
|
||||||
@@ -4,47 +4,55 @@
|
|||||||
|
|
||||||
namespace Chattr::log {
|
namespace Chattr::log {
|
||||||
|
|
||||||
void critical(gsl::czstring msg) {
|
void critical(gsl::czstring msg, bool bShowDBGMessage) {
|
||||||
|
if (!bShowDBGMessage)
|
||||||
|
spdlog::critical("{}", msg);
|
||||||
|
else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
gsl::zstring msgbuf = nullptr;
|
gsl::zstring msgbuf = nullptr;
|
||||||
FormatMessageA(
|
FormatMessageA(
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
NULL,
|
NULL,
|
||||||
WSAGetLastError(),
|
WSAGetLastError(),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
msgbuf,
|
msgbuf,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||||
LocalFree(msgbuf);
|
LocalFree(msgbuf);
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
gsl::czstring msgbuf = strerror(errno);
|
gsl::czstring msgbuf = strerror(errno);
|
||||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||||
#else
|
#else
|
||||||
#error "이 플랫폼은 지원되지 않습니다."
|
#error "이 플랫폼은 지원되지 않습니다."
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
std::exit(EXIT_FAILURE);
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(gsl::czstring msg) {
|
void error(gsl::czstring msg, bool bShowDBGMessage) {
|
||||||
|
if (!bShowDBGMessage)
|
||||||
|
spdlog::critical("{}", msg);
|
||||||
|
else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
gsl::zstring msgbuf = nullptr;
|
gsl::zstring msgbuf = nullptr;
|
||||||
FormatMessageA(
|
FormatMessageA(
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
NULL,
|
NULL,
|
||||||
WSAGetLastError(),
|
WSAGetLastError(),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
msgbuf,
|
msgbuf,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
spdlog::error("[{}] {}", msg, msgbuf);
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||||
LocalFree(msgbuf);
|
LocalFree(msgbuf);
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
gsl::czstring msgbuf = strerror(errno);
|
gsl::czstring msgbuf = strerror(errno);
|
||||||
spdlog::error("[{}] {}", msg, msgbuf);
|
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||||
#else
|
#else
|
||||||
#error "이 플랫폼은 지원되지 않습니다."
|
#error "이 플랫폼은 지원되지 않습니다."
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,18 +4,28 @@
|
|||||||
|
|
||||||
namespace Chattr {
|
namespace Chattr {
|
||||||
|
|
||||||
Socket_Init::Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol) {
|
Socket_Init::Socket_Init(const SOCKET& socket) {
|
||||||
|
sock_ = socket;
|
||||||
|
valid_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Socket_Init::Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol)
|
||||||
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||||
log::critical("WSAStartup()");
|
log::critical("WSAStartup()", true);
|
||||||
#endif
|
#endif
|
||||||
sock_ = socket(domain, type, protocol);
|
sock_ = socket(domain, type, protocol);
|
||||||
if (sock_ == INVALID_SOCKET)
|
if (sock_ == INVALID_SOCKET)
|
||||||
log::critical("socket()");
|
log::critical("socket()", true);
|
||||||
|
|
||||||
|
valid_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket_Init::~Socket_Init() {
|
Socket_Init::~Socket_Init() {
|
||||||
|
if (!valid_)
|
||||||
|
return;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
closesocket(sock_);
|
closesocket(sock_);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@@ -24,6 +34,11 @@ Socket_Init::~Socket_Init() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET Socket_Init::get() const { return sock_; }
|
Socket_Init::operator SOCKET() const {
|
||||||
|
if (valid_)
|
||||||
|
return sock_;
|
||||||
|
log::critical("No valid socket created.", false);
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
namespace Chattr::log {
|
namespace Chattr::log {
|
||||||
void critical(gsl::czstring msg);
|
void critical(gsl::czstring msg, bool bShowDBGMessage);
|
||||||
void error(gsl::czstring msg);
|
void error(gsl::czstring msg, bool bShowDBGMessage);
|
||||||
}
|
}
|
||||||
@@ -5,14 +5,17 @@ namespace Chattr {
|
|||||||
|
|
||||||
struct Socket_Init {
|
struct Socket_Init {
|
||||||
public:
|
public:
|
||||||
|
Socket_Init() {}
|
||||||
Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol);
|
Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol);
|
||||||
~Socket_Init();
|
~Socket_Init();
|
||||||
|
|
||||||
|
Socket_Init(const SOCKET& socket);
|
||||||
Socket_Init(const Socket_Init&) = delete;
|
Socket_Init(const Socket_Init&) = delete;
|
||||||
Socket_Init& operator=(const Socket_Init&) = delete;
|
Socket_Init& operator=(const Socket_Init&) = delete;
|
||||||
|
|
||||||
SOCKET get() const;
|
operator SOCKET() const;
|
||||||
private:
|
private:
|
||||||
|
bool valid_ = false;
|
||||||
SOCKET sock_;
|
SOCKET sock_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,13 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#define SOCKET std::int32_t
|
#define SOCKET std::int32_t
|
||||||
#define INVALID_SOCKET -1
|
#define INVALID_SOCKET -1
|
||||||
#else
|
#else
|
||||||
#error "<EFBFBD><EFBFBD> <20>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>."
|
#error "이 플랫폼은 지원되지 않습니다."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gsl/gsl>
|
#include <gsl/gsl>
|
||||||
Reference in New Issue
Block a user