wsamanager 분리
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Chattr {
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
Socket();
|
||||
Socket() = default;
|
||||
Socket(int domain, int type, int protocol);
|
||||
~Socket();
|
||||
|
||||
|
||||
21
include/Socket/WSAManager.hpp
Normal file
21
include/Socket/WSAManager.hpp
Normal 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
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user