Handle listen/accept/send/receive in afd_endpoint

This commit is contained in:
Igor Pissolati
2025-05-20 00:56:22 -03:00
parent 0f4cc3365c
commit f5ed0752e3
9 changed files with 412 additions and 11 deletions

View File

@@ -3,6 +3,11 @@
namespace network
{
socket_wrapper::socket_wrapper(SOCKET s)
: socket_(s)
{
}
socket_wrapper::socket_wrapper(const int af, const int type, const int protocol)
: socket_(af, type, protocol)
{
@@ -23,11 +28,32 @@ namespace network
return this->socket_.is_ready(in_poll);
}
bool socket_wrapper::is_listening()
{
return this->socket_.is_listening();
}
bool socket_wrapper::bind(const address& addr)
{
return this->socket_.bind(addr);
}
bool socket_wrapper::listen(int backlog)
{
return this->socket_.listen(backlog);
}
std::unique_ptr<i_socket> socket_wrapper::accept(address& address)
{
const auto s = this->socket_.accept(address);
if (s == INVALID_SOCKET)
{
return nullptr;
}
return std::make_unique<socket_wrapper>(s);
}
sent_size socket_wrapper::send(const std::span<const std::byte> data)
{
return ::send(this->socket_.get_socket(), reinterpret_cast<const char*>(data.data()),