자세 조정
This commit is contained in:
@@ -4,47 +4,55 @@
|
||||
|
||||
namespace Chattr::log {
|
||||
|
||||
void critical(gsl::czstring msg) {
|
||||
void critical(gsl::czstring msg, bool bShowDBGMessage) {
|
||||
if (!bShowDBGMessage)
|
||||
spdlog::critical("{}", msg);
|
||||
else {
|
||||
#ifdef _WIN32
|
||||
gsl::zstring msgbuf = nullptr;
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
WSAGetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
LocalFree(msgbuf);
|
||||
gsl::zstring msgbuf = nullptr;
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
WSAGetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
LocalFree(msgbuf);
|
||||
#elif __linux__
|
||||
gsl::czstring msgbuf = strerror(errno);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
gsl::czstring msgbuf = strerror(errno);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
#else
|
||||
#error "이 플랫폼은 지원되지 않습니다."
|
||||
#endif
|
||||
}
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void error(gsl::czstring msg) {
|
||||
void error(gsl::czstring msg, bool bShowDBGMessage) {
|
||||
if (!bShowDBGMessage)
|
||||
spdlog::critical("{}", msg);
|
||||
else {
|
||||
#ifdef _WIN32
|
||||
gsl::zstring msgbuf = nullptr;
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
WSAGetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
spdlog::error("[{}] {}", msg, msgbuf);
|
||||
LocalFree(msgbuf);
|
||||
gsl::zstring msgbuf = nullptr;
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
WSAGetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
LocalFree(msgbuf);
|
||||
#elif __linux__
|
||||
gsl::czstring msgbuf = strerror(errno);
|
||||
spdlog::error("[{}] {}", msg, msgbuf);
|
||||
gsl::czstring msgbuf = strerror(errno);
|
||||
spdlog::critical("[{}] {}", msg, msgbuf);
|
||||
#else
|
||||
#error "이 플랫폼은 지원되지 않습니다."
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,18 +4,28 @@
|
||||
|
||||
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
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
log::critical("WSAStartup()");
|
||||
log::critical("WSAStartup()", true);
|
||||
#endif
|
||||
sock_ = socket(domain, type, protocol);
|
||||
if (sock_ == INVALID_SOCKET)
|
||||
log::critical("socket()");
|
||||
log::critical("socket()", true);
|
||||
|
||||
valid_ = true;
|
||||
}
|
||||
|
||||
Socket_Init::~Socket_Init() {
|
||||
if (!valid_)
|
||||
return;
|
||||
#ifdef _WIN32
|
||||
closesocket(sock_);
|
||||
WSACleanup();
|
||||
@@ -24,6 +34,11 @@ Socket_Init::~Socket_Init() {
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user