add necessary CMake files
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct WSA {
|
||||
WSADATA wsa;
|
||||
|
||||
explicit WSA(WORD version = MAKEWORD(2, 2));
|
||||
~WSA() noexcept;
|
||||
};
|
||||
|
||||
struct AddrInfoPtr {
|
||||
struct addrinfo *info;
|
||||
|
||||
AddrInfoPtr() noexcept;
|
||||
~AddrInfoPtr() noexcept;
|
||||
|
||||
addrinfo** operator&() noexcept;
|
||||
addrinfo& operator*() noexcept;
|
||||
addrinfo* operator->() noexcept;
|
||||
const addrinfo& operator*() const noexcept;
|
||||
|
||||
operator addrinfo*() noexcept;
|
||||
};
|
||||
|
||||
struct AddrInfo {
|
||||
struct addrinfo info;
|
||||
|
||||
AddrInfo() noexcept;
|
||||
~AddrInfo() noexcept = default;
|
||||
|
||||
addrinfo* operator->() noexcept;
|
||||
addrinfo* operator&() noexcept;
|
||||
|
||||
operator const addrinfo&() const noexcept;
|
||||
operator addrinfo&() noexcept;
|
||||
|
||||
AddrInfoPtr get_addrinfo(PCSTR node, PCSTR service);
|
||||
};
|
||||
|
||||
struct Socket {
|
||||
enum AddrAction {
|
||||
NO_ACTION,
|
||||
CONNECT,
|
||||
BIND,
|
||||
};
|
||||
|
||||
SOCKET s;
|
||||
struct sockaddr addr;
|
||||
|
||||
explicit Socket(SOCKET init = INVALID_SOCKET) noexcept;
|
||||
~Socket() noexcept;
|
||||
|
||||
operator SOCKET() const noexcept;
|
||||
|
||||
explicit operator bool() const noexcept;
|
||||
bool is_valid() const noexcept;
|
||||
|
||||
void from_addrinfo(const struct addrinfo &info, AddrAction action = NO_ACTION);
|
||||
|
||||
Socket accept_client() const noexcept;
|
||||
|
||||
void stop_send() const;
|
||||
|
||||
int send_data(const Buffer &data) const;
|
||||
int recv_data(Buffer &data) const;
|
||||
};
|
||||
|
||||
struct Buffer {
|
||||
std::unique_ptr<char[]> data;
|
||||
int size;
|
||||
|
||||
Buffer(int len);
|
||||
|
||||
char* get();
|
||||
const char* get() const;
|
||||
|
||||
int len() const;
|
||||
};
|
||||
Reference in New Issue
Block a user