wsamanager 분리

This commit is contained in:
2025-04-26 17:21:54 +09:00
parent 81d912cc5e
commit 1418cf6880
5 changed files with 28 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
#include "Socket/TCPSocket.hpp"
#include "Socket/Log.hpp"
#include "Socket/WSAManager.hpp"
#include "Utils/ConfigManager.hpp"
#include "Utils/Thread.hpp"
#include "Utils/StringTokenizer.hpp"
@@ -9,6 +10,9 @@
void _TCPClient(Chattr::TCPSocket sock, Chattr::Address addr);
int main() {
#ifdef _WIN32
struct Chattr::WSAManager wsaManager;
#endif
auto config = Chattr::ConfigManager::load();
Chattr::log::setDefaultLogger(config.logLevel, config.logFileName, config.logfileSize, config.logfileCount);

View File

@@ -4,20 +4,7 @@
namespace Chattr {
Socket::Socket() {
#ifdef _WIN32
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
log::critical("WSAStartup()");
#endif
}
Socket::Socket(int domain, int type, int protocol) {
#ifdef _WIN32
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
log::critical("WSAStartup()");
#endif
init(domain, type, protocol);
}
@@ -42,8 +29,7 @@ void Socket::destruct() {
if (!valid_)
return;
#ifdef _WIN32
closesocket(sock_);
WSACleanup();
::closesocket(sock_);
#elif __linux__
::close(sock_);
#endif

View File

@@ -6,7 +6,7 @@ namespace Chattr {
class Socket {
public:
Socket();
Socket() = default;
Socket(int domain, int type, int protocol);
~Socket();

View File

@@ -0,0 +1,21 @@
#pragma once
#include "precomp.hpp"
#include "Socket/Log.hpp"
#ifdef _WIN32
namespace Chattr {
struct WSAManager {
WSAManager() {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
log::critical("WSAStartup()");
}
~WSAManager() {
WSACleanup();
}
};
}
#endif

View File

@@ -5,6 +5,7 @@
#include <ws2tcpip.h>
#include <ws2bth.h>
#include <windows.h>
#define in_addr_t ULONG
#elif __linux__
#include <sys/types.h>
#include <sys/socket.h>