wsamanager 분리
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "Socket/TCPSocket.hpp"
|
#include "Socket/TCPSocket.hpp"
|
||||||
#include "Socket/Log.hpp"
|
#include "Socket/Log.hpp"
|
||||||
|
#include "Socket/WSAManager.hpp"
|
||||||
#include "Utils/ConfigManager.hpp"
|
#include "Utils/ConfigManager.hpp"
|
||||||
#include "Utils/Thread.hpp"
|
#include "Utils/Thread.hpp"
|
||||||
#include "Utils/StringTokenizer.hpp"
|
#include "Utils/StringTokenizer.hpp"
|
||||||
@@ -9,6 +10,9 @@
|
|||||||
void _TCPClient(Chattr::TCPSocket sock, Chattr::Address addr);
|
void _TCPClient(Chattr::TCPSocket sock, Chattr::Address addr);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
struct Chattr::WSAManager wsaManager;
|
||||||
|
#endif
|
||||||
auto config = Chattr::ConfigManager::load();
|
auto config = Chattr::ConfigManager::load();
|
||||||
Chattr::log::setDefaultLogger(config.logLevel, config.logFileName, config.logfileSize, config.logfileCount);
|
Chattr::log::setDefaultLogger(config.logLevel, config.logFileName, config.logfileSize, config.logfileCount);
|
||||||
|
|
||||||
|
|||||||
@@ -4,20 +4,7 @@
|
|||||||
|
|
||||||
namespace Chattr {
|
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) {
|
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);
|
init(domain, type, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +29,7 @@ void Socket::destruct() {
|
|||||||
if (!valid_)
|
if (!valid_)
|
||||||
return;
|
return;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
closesocket(sock_);
|
::closesocket(sock_);
|
||||||
WSACleanup();
|
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
::close(sock_);
|
::close(sock_);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace Chattr {
|
|||||||
|
|
||||||
class Socket {
|
class Socket {
|
||||||
public:
|
public:
|
||||||
Socket();
|
Socket() = default;
|
||||||
Socket(int domain, int type, int protocol);
|
Socket(int domain, int type, int protocol);
|
||||||
~Socket();
|
~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 <ws2tcpip.h>
|
||||||
#include <ws2bth.h>
|
#include <ws2bth.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#define in_addr_t ULONG
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user