일단 서버구현 끝
This commit is contained in:
15
include/Socket/Address.hpp
Normal file
15
include/Socket/Address.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
struct Address {
|
||||
union {
|
||||
struct sockaddr sockaddr;
|
||||
struct sockaddr_in sockaddr_in;
|
||||
struct sockaddr_in6 sockaddr_in6;
|
||||
};
|
||||
socklen_t length;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include "Address.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
@@ -9,22 +10,27 @@ public:
|
||||
Socket(int domain, int type, int protocol);
|
||||
~Socket();
|
||||
|
||||
void init(int domain, int type, int protocol);
|
||||
|
||||
operator SOCKET() const;
|
||||
void move(const SOCKET);
|
||||
|
||||
void bind(int __fd, const sockaddr *__addr);
|
||||
void bind(int __fd, const sockaddr *__addr, socklen_t __len);
|
||||
void bind(const sockaddr *__addr);
|
||||
void bind(const sockaddr *__addr, socklen_t __len);
|
||||
|
||||
//IPV4
|
||||
void bind(int __fd, const sockaddr_in *__addr);
|
||||
void bind(int __fd, const sockaddr_in *__addr, socklen_t __len);
|
||||
void bind(const sockaddr_in *__addr);
|
||||
void bind(const sockaddr_in *__addr, socklen_t __len);
|
||||
|
||||
//IPV6
|
||||
void bind(int __fd, const sockaddr_in6 *__addr);
|
||||
void bind(int __fd, const sockaddr_in6 *__addr, socklen_t __len);
|
||||
void bind(const sockaddr_in6 *__addr);
|
||||
void bind(const sockaddr_in6 *__addr, socklen_t __len);
|
||||
|
||||
Socket(const Socket&) = delete;
|
||||
Socket& operator=(const Socket&) = delete;
|
||||
private:
|
||||
|
||||
struct Address bindAddr;
|
||||
protected:
|
||||
bool valid_ = false;
|
||||
SOCKET sock_ = INVALID_SOCKET;
|
||||
};
|
||||
|
||||
15
include/Socket/TCPSocket.hpp
Normal file
15
include/Socket/TCPSocket.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "Socket.hpp"
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
class TCPSocket : public Socket {
|
||||
public:
|
||||
using Socket::init;
|
||||
void init(int domain);
|
||||
void listen(int __n);
|
||||
void accept(TCPSocket& newSock, Address& addr);
|
||||
};
|
||||
|
||||
}
|
||||
20
include/Utils/ConfigManager.hpp
Normal file
20
include/Utils/ConfigManager.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include <json/json.h>
|
||||
|
||||
namespace Chattr {
|
||||
class ConfigManager {
|
||||
public:
|
||||
struct Config {
|
||||
Json::Value configJsonRoot;
|
||||
std::uint32_t ipVersion = 0;
|
||||
std::uint32_t listenPort = 0;
|
||||
spdlog::level::level_enum logLevel = spdlog::level::off;
|
||||
gsl::czstring logFileName = "";
|
||||
std::uint32_t logfileSize = 0;
|
||||
std::uint32_t logfileCount = 0;
|
||||
};
|
||||
|
||||
static Config load();
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <ws2bth.h>
|
||||
#include <windows.h>
|
||||
#elif __linux__
|
||||
#include <sys/types.h>
|
||||
|
||||
Reference in New Issue
Block a user