LibCore+LookupServer: Implement and use UDPServer::send

This commit is contained in:
sin-ack 2021-09-11 20:11:30 +00:00 committed by Ali Mohammad Pur
commit 0cca6cef95
Notes: sideshowbarker 2024-07-17 22:43:01 +09:00
5 changed files with 25 additions and 6 deletions

View file

@ -102,4 +102,18 @@ Optional<u16> UDPServer::local_port() const
return ntohs(address.sin_port);
}
ErrorOr<size_t> UDPServer::send(ReadonlyBytes buffer, sockaddr_in const& to)
{
if (m_fd < 0) {
return Error::from_errno(EBADF);
}
auto result = ::sendto(m_fd, buffer.data(), buffer.size(), 0, (sockaddr const*)&to, sizeof(to));
if (result < 0) {
return Error::from_errno(errno);
}
return result;
}
}