일단 bind까지 구현 완료료

This commit is contained in:
2025-04-21 23:16:30 +09:00
parent 7f53703f60
commit 819bd5362e
6 changed files with 94 additions and 8 deletions

71
.vscode/settings.json vendored
View File

@@ -2,6 +2,75 @@
"files.associations": { "files.associations": {
"assert": "cpp", "assert": "cpp",
"zstring": "cpp", "zstring": "cpp",
"ostream": "cpp" "ostream": "cpp",
"cctype": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"format": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__verbose_abort": "cpp",
"ios": "cpp",
"locale": "cpp",
"print": "cpp",
"queue": "cpp",
"stack": "cpp"
} }
} }

View File

@@ -4,5 +4,12 @@
int main() { int main() {
struct Chattr::Socket_Init sock(AF_INET, SOCK_DGRAM, 0); struct Chattr::Socket_Init sock(AF_INET, SOCK_DGRAM, 0);
std::cout << "Hello, world!" << sock << std::endl;
struct sockaddr_in serveraddr = {};
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = htons(9010);
sock.bind(sock, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
std::cout << sock << std::endl;
} }

View File

@@ -9,11 +9,11 @@ Socket_Init::Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t pr
#ifdef _WIN32 #ifdef _WIN32
WSADATA wsa; WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
log::critical("WSAStartup()", true); log::critical("WSAStartup()");
#endif #endif
sock_ = socket(domain, type, protocol); sock_ = socket(domain, type, protocol);
if (sock_ == INVALID_SOCKET) if (sock_ == INVALID_SOCKET)
log::critical("socket()", true); log::critical("socket()");
valid_ = true; valid_ = true;
} }
@@ -36,4 +36,10 @@ Socket_Init::operator SOCKET() const {
return INVALID_SOCKET; return INVALID_SOCKET;
}; };
void Socket_Init::bind(int __fd, const sockaddr *__addr, socklen_t __len) {
int retVal = ::bind(__fd, __addr, __len);
if (retVal == INVALID_SOCKET)
log::critical("bind()");
}
} }

View File

@@ -2,6 +2,6 @@
#include "precomp.hpp" #include "precomp.hpp"
namespace Chattr::log { namespace Chattr::log {
void critical(gsl::czstring msg, bool bShowDBGMessage); void critical(gsl::czstring msg, bool bShowDBGMessage = true);
void error(gsl::czstring msg, bool bShowDBGMessage); void error(gsl::czstring msg, bool bShowDBGMessage = true);
} }

View File

@@ -8,10 +8,12 @@ public:
Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol); Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol);
~Socket_Init(); ~Socket_Init();
operator SOCKET() const;
void bind(int __fd, const sockaddr *__addr, socklen_t __len);
Socket_Init(const Socket_Init&) = delete; Socket_Init(const Socket_Init&) = delete;
Socket_Init& operator=(const Socket_Init&) = delete; Socket_Init& operator=(const Socket_Init&) = delete;
operator SOCKET() const;
private: private:
bool valid_ = false; bool valid_ = false;
SOCKET sock_ = INVALID_SOCKET; SOCKET sock_ = INVALID_SOCKET;

View File

@@ -2,11 +2,13 @@
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h> #include <windows.h>
#elif __linux__ #elif __linux__
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h>
#define SOCKET int #define SOCKET int
#define INVALID_SOCKET -1 #define INVALID_SOCKET -1
#else #else