StringTokenizer 복구
This commit is contained in:
@@ -1,100 +1,20 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
struct Address {
|
||||
Address() {
|
||||
zeroFill();
|
||||
}
|
||||
Address();
|
||||
Address(int type, gsl::czstring presentationAddr, std::uint16_t port);
|
||||
|
||||
Address(int type, gsl::czstring presentationAddr, std::uint16_t port) {
|
||||
set(type, presentationAddr, port);
|
||||
}
|
||||
void zeroFill();
|
||||
void set(int type, gsl::czstring presentationAddr, std::uint16_t port);
|
||||
void set(int type, in_addr_t addr, std::uint16_t port);
|
||||
void set(int type, in_addr addr, std::uint16_t port);
|
||||
void set(int type, in6_addr addr, std::uint16_t port);
|
||||
void setType(int type);
|
||||
|
||||
void zeroFill() {
|
||||
memset(&addr_in6, 0, sizeof(addr_in6));
|
||||
}
|
||||
|
||||
void set(int type, gsl::czstring presentationAddr, std::uint16_t port) {
|
||||
zeroFill();
|
||||
|
||||
if (type == AF_INET) {
|
||||
addr_in.sin_family = AF_INET;
|
||||
::inet_pton(AF_INET, presentationAddr, &addr_in.sin_addr);
|
||||
addr_in.sin_port = htons(port);
|
||||
length = sizeof(sockaddr_in);
|
||||
} else if (type == AF_INET6) {
|
||||
addr_in6.sin6_family = AF_INET6;
|
||||
::inet_pton(AF_INET6, presentationAddr, &addr_in6.sin6_addr);
|
||||
addr_in6.sin6_port = htons(port);
|
||||
length = sizeof(sockaddr_in6);
|
||||
}
|
||||
}
|
||||
|
||||
void set(int type, in_addr_t addr, std::uint16_t port) {
|
||||
zeroFill();
|
||||
|
||||
if (type == AF_INET) {
|
||||
addr_in.sin_family = AF_INET;
|
||||
addr_in.sin_addr.s_addr = htonl(addr);
|
||||
addr_in.sin_port = htons(port);
|
||||
length = sizeof(sockaddr_in);
|
||||
}
|
||||
}
|
||||
|
||||
void set(int type, in_addr addr, std::uint16_t port) {
|
||||
zeroFill();
|
||||
|
||||
if (type == AF_INET) {
|
||||
addr_in.sin_family = AF_INET;
|
||||
addr_in.sin_addr = addr;
|
||||
addr_in.sin_port = htons(port);
|
||||
length = sizeof(sockaddr_in);
|
||||
}
|
||||
}
|
||||
|
||||
void set(int type, in6_addr addr, std::uint16_t port) {
|
||||
zeroFill();
|
||||
|
||||
if (type == AF_INET6) {
|
||||
addr_in6.sin6_family = AF_INET6;
|
||||
addr_in6.sin6_addr = addr;
|
||||
addr_in6.sin6_port = htons(port);
|
||||
length = sizeof(sockaddr_in6);
|
||||
}
|
||||
}
|
||||
|
||||
operator std::string() {
|
||||
std::optional<std::uint16_t> port = getPort();
|
||||
|
||||
if (!port)
|
||||
return std::string();
|
||||
|
||||
if (length == sizeof(addr_in)) {
|
||||
char addrStr[INET_ADDRSTRLEN];
|
||||
::inet_ntop(AF_INET, &addr_in.sin_addr, addrStr, sizeof(addrStr));
|
||||
|
||||
return std::format("{}:{}", addrStr, port.value());
|
||||
} else if (length == sizeof(addr_in6)) {
|
||||
char addrStr[INET6_ADDRSTRLEN];
|
||||
::inet_ntop(AF_INET6, &addr_in6.sin6_addr, addrStr, sizeof(addrStr));
|
||||
|
||||
return std::format("{}:{}", addrStr, port.value());
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::optional<std::uint16_t> getPort() {
|
||||
if (length == sizeof(addr_in))
|
||||
return ntohs(addr_in.sin_port);
|
||||
else if (length == sizeof(addr_in6))
|
||||
return ntohs(addr_in6.sin6_port);
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
operator std::string();
|
||||
std::optional<std::uint16_t> getPort();
|
||||
|
||||
union {
|
||||
struct sockaddr addr;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace Chattr::log {
|
||||
void setDefaultLogger(spdlog::level::level_enum logLevel, gsl::czstring logFileName, std::uint32_t logFileSize, std::uint32_t logFileCount);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include "Address.hpp"
|
||||
#include "Socket/Address.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
struct Address;
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
Socket() = default;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "Socket.hpp"
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include "Socket/Log.hpp"
|
||||
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
struct WSAManager {
|
||||
|
||||
WSAManager() {
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
log::critical("WSAStartup()");
|
||||
#endif
|
||||
}
|
||||
|
||||
~WSAManager() {
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
WSAManager();
|
||||
~WSAManager();
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user