46 lines
1001 B
C++
46 lines
1001 B
C++
#pragma once
|
|
#include "address.h"
|
|
|
|
namespace Socket {
|
|
|
|
struct Address;
|
|
|
|
class UDPSocket {
|
|
public:
|
|
UDPSocket() = default;
|
|
UDPSocket(int domain, int type, int protocol);
|
|
~UDPSocket();
|
|
|
|
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 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);
|
|
|
|
UDPSocket(const UDPSocket&);
|
|
UDPSocket(UDPSocket&&) noexcept;
|
|
UDPSocket& operator=(const UDPSocket&);
|
|
UDPSocket& operator=(UDPSocket&&) noexcept;
|
|
|
|
struct Address bindAddr = {};
|
|
struct Address remoteAddr = {};
|
|
|
|
int domain = 0;
|
|
SOCKET sock = INVALID_SOCKET;
|
|
|
|
std::mutex readMutex;
|
|
std::mutex writeMutex;
|
|
|
|
protected:
|
|
bool valid_ = false;
|
|
};
|
|
|
|
} // namespace Socket
|