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

@@ -37,8 +37,8 @@ EventPipe::Read() noexcept
assert(r.IsDefined());
assert(w.IsDefined());
char buffer[256];
return r.Read(buffer, sizeof(buffer)) > 0;
std::byte buffer[256];
return r.Read(buffer) > 0;
}
void
@@ -47,7 +47,8 @@ EventPipe::Write() noexcept
assert(r.IsDefined());
assert(w.IsDefined());
w.Write("", 1);
static constexpr std::byte buffer[1]{};
w.Write(buffer);
}
#ifdef _WIN32