io/FileDescriptor: add readv()/writev() wrappers

This commit is contained in:
Max Kellermann 2024-11-12 08:48:27 +01:00 committed by Max Kellermann
parent fc4a579d83
commit 6dce8dcaa5
2 changed files with 26 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#ifndef _WIN32 #ifndef _WIN32
#include <poll.h> #include <poll.h>
#include <sys/uio.h> // for struct iovec
#endif #endif
#ifndef O_NOCTTY #ifndef O_NOCTTY
@ -295,6 +296,18 @@ FileDescriptor::FullWrite(std::span<const std::byte> src) const
#ifndef _WIN32 #ifndef _WIN32
ssize_t
FileDescriptor::Read(std::span<const struct iovec> v) const noexcept
{
return readv(fd, v.data(), v.size());
}
ssize_t
FileDescriptor::Write(std::span<const struct iovec> v) const noexcept
{
return writev(fd, v.data(), v.size());
}
int int
FileDescriptor::Poll(short events, int timeout) const noexcept FileDescriptor::Poll(short events, int timeout) const noexcept
{ {

View File

@ -14,6 +14,7 @@
#include <wchar.h> #include <wchar.h>
#endif #endif
struct iovec;
class UniqueFileDescriptor; class UniqueFileDescriptor;
/** /**
@ -271,6 +272,18 @@ public:
void FullWrite(std::span<const std::byte> src) const; void FullWrite(std::span<const std::byte> src) const;
#ifndef _WIN32 #ifndef _WIN32
/**
* Wrapper for readv().
*/
[[nodiscard]]
ssize_t Read(std::span<const struct iovec> v) const noexcept;
/**
* Wrapper for writev().
*/
[[nodiscard]]
ssize_t Write(std::span<const struct iovec> v) const noexcept;
[[nodiscard]] [[nodiscard]]
int Poll(short events, int timeout) const noexcept; int Poll(short events, int timeout) const noexcept;