48 lines
999 B
C++
48 lines
999 B
C++
#pragma once
|
|
#include "address.h"
|
|
|
|
namespace Network {
|
|
|
|
struct Address;
|
|
|
|
class Socket {
|
|
public:
|
|
Socket();
|
|
Socket(int domain, int type, int protocol);
|
|
~Socket();
|
|
|
|
int init(int domain, int type, int protocol);
|
|
void destruct();
|
|
|
|
operator SOCKET();
|
|
void set(const SOCKET __sock, int __domain);
|
|
int setsockopt(int level, int optname, const char* optval, int optlen);
|
|
|
|
int bind(Address __addr);
|
|
int connect(Network::Address& serveraddr);
|
|
|
|
int recvfrom(void* __restrict __buf, size_t __n, int __flags,
|
|
struct Address& __addr);
|
|
int sendto(const void* __buf, size_t __n, int __flags, struct Address __addr);
|
|
|
|
Socket(const Socket&);
|
|
Socket& operator=(const Socket&);
|
|
|
|
Socket(Socket&&) noexcept;
|
|
Socket& operator=(Socket&&) noexcept;
|
|
|
|
struct Address bindAddr = {};
|
|
struct Address remoteAddr = {};
|
|
|
|
int domain = 0;
|
|
SOCKET sock = INVALID_SOCKET;
|
|
|
|
std::mutex readMutex;
|
|
std::mutex writeMutex;
|
|
|
|
private:
|
|
bool valid_ = false;
|
|
};
|
|
|
|
} // namespace Socket
|