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:

committed by
Max Kellermann

parent
cad35a83fb
commit
491cc8f54d
@@ -420,14 +420,25 @@ SocketDescriptor::Send(std::span<const std::byte> src, int flags) const noexcept
|
||||
}
|
||||
|
||||
ssize_t
|
||||
SocketDescriptor::Read(void *buffer, std::size_t length) const noexcept
|
||||
SocketDescriptor::ReadNoWait(std::span<std::byte> dest) const noexcept
|
||||
{
|
||||
int flags = 0;
|
||||
#ifndef _WIN32
|
||||
flags |= MSG_DONTWAIT;
|
||||
#endif
|
||||
|
||||
return Receive({static_cast<std::byte *>(buffer), length}, flags);
|
||||
return Receive(dest, flags);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
SocketDescriptor::WriteNoWait(std::span<const std::byte> src) const noexcept
|
||||
{
|
||||
int flags = 0;
|
||||
#ifndef _WIN32
|
||||
flags |= MSG_DONTWAIT;
|
||||
#endif
|
||||
|
||||
return Send(src, flags);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
Reference in New Issue
Block a user