일단 bind까지 구현 완료료
This commit is contained in:
71
.vscode/settings.json
vendored
71
.vscode/settings.json
vendored
@@ -2,6 +2,75 @@
|
||||
"files.associations": {
|
||||
"assert": "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"
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,12 @@
|
||||
|
||||
int main() {
|
||||
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;
|
||||
}
|
||||
@@ -9,11 +9,11 @@ Socket_Init::Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t pr
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
log::critical("WSAStartup()", true);
|
||||
log::critical("WSAStartup()");
|
||||
#endif
|
||||
sock_ = socket(domain, type, protocol);
|
||||
if (sock_ == INVALID_SOCKET)
|
||||
log::critical("socket()", true);
|
||||
log::critical("socket()");
|
||||
|
||||
valid_ = true;
|
||||
}
|
||||
@@ -36,4 +36,10 @@ Socket_Init::operator SOCKET() const {
|
||||
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()");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace Chattr::log {
|
||||
void critical(gsl::czstring msg, bool bShowDBGMessage);
|
||||
void error(gsl::czstring msg, bool bShowDBGMessage);
|
||||
void critical(gsl::czstring msg, bool bShowDBGMessage = true);
|
||||
void error(gsl::czstring msg, bool bShowDBGMessage = true);
|
||||
}
|
||||
@@ -8,10 +8,12 @@ public:
|
||||
Socket_Init(std::int32_t domain, std::int32_t type, std::int32_t protocol);
|
||||
~Socket_Init();
|
||||
|
||||
operator SOCKET() const;
|
||||
|
||||
void bind(int __fd, const sockaddr *__addr, socklen_t __len);
|
||||
|
||||
Socket_Init(const Socket_Init&) = delete;
|
||||
Socket_Init& operator=(const Socket_Init&) = delete;
|
||||
|
||||
operator SOCKET() const;
|
||||
private:
|
||||
bool valid_ = false;
|
||||
SOCKET sock_ = INVALID_SOCKET;
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <windows.h>
|
||||
#elif __linux__
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user