54 using Ptr = std::shared_ptr<Socket>;
89 Socket(Family family, Type type, int32_t protocol = IPPROTO_IP)
noexcept;
94 virtual int32_t bind(
Address::Ptr address) noexcept;
95 virtual int32_t connect(
Address::Ptr address) noexcept;
96 virtual int32_t listen(int32_t backlog) const noexcept;
97 [[nodiscard]] virtual
Socket::Ptr accept() const;
98 virtual int32_t shutdown(ShutdownMode mode) const;
99 bool setNonblocking() const noexcept;
106 int64_t
read(
void *buffer,
size_t length) override;
113 int64_t
write(const
void *buffer,
size_t length) override;
122 int64_t send(
void *buffer,
size_t length, const
IPAddress::Ptr &to, int32_t flags) const;
131 int64_t recv(
void *buffer,
size_t length, const
IPAddress::Ptr &from, int32_t flags) const;
134 int64_t peek(
void *buffer,
size_t length) override;
136 int64_t trunc(
size_t length) override;
140 value = func(value); \
141 return write(&value, sizeof(value));
145 auto len = read(&value, sizeof(value)); \
146 value = func(value); \
153 void close()
override;
162 static socket_t socket(
int family,
int type,
int protocol)
noexcept;
164 static int bind(
socket_t socket,
const sockaddr *addr, socklen_t addr_len)
noexcept;
166 static socket_t accept(
socket_t socket, sockaddr *addr =
nullptr, socklen_t *len =
nullptr) noexcept;
168 static
int connect(
socket_t socket, const sockaddr *addr, socklen_t addr_len) noexcept;
170 static int64_t
write(
socket_t socket, const
void *buffer,
size_t len,
int flags) noexcept;
172 static int64_t
read(
socket_t socket,
void *buffer,
size_t len,
int flags) noexcept;
174 static
int listen(
socket_t socket,
int backlog) noexcept;
176 static
int setNonblocking(
socket_t socket) noexcept;