net/SocketDescriptor: add {Read,Write}NoWait()

It was surprising that Read() was non-blocking, but there was no
blocking version of it.  Let's make the non-blocking behavior explicit
and change Read() to be blocking.

In order to find existing callers easily with compiler errors, this
also refactors Read()/Write() to take a std::span parameter.
This commit is contained in:
Max Kellermann
2023-09-27 09:32:48 +02:00
committed by Max Kellermann
parent cad35a83fb
commit 491cc8f54d
7 changed files with 48 additions and 19 deletions

View File

@@ -9,7 +9,7 @@
inline BufferedSocket::ssize_t
BufferedSocket::DirectRead(std::span<std::byte> dest) noexcept
{
const auto nbytes = GetSocket().Read((char *)dest.data(), dest.size());
const auto nbytes = GetSocket().ReadNoWait(dest);
if (nbytes > 0) [[likely]]
return nbytes;

View File

@@ -11,7 +11,7 @@
inline FullyBufferedSocket::ssize_t
FullyBufferedSocket::DirectWrite(std::span<const std::byte> src) noexcept
{
const auto nbytes = GetSocket().Write((const char *)src.data(), src.size());
const auto nbytes = GetSocket().WriteNoWait(src);
if (nbytes < 0) [[unlikely]] {
const auto code = GetSocketError();
if (IsSocketErrorSendWouldBlock(code))