Skip to content

Commit

Permalink
io/FileDescriptor: add readv()/writev() wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Nov 12, 2024
1 parent b6325af commit 6d5e9e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/io/FileDescriptor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#ifndef _WIN32
#include <poll.h>
#include <sys/uio.h> // for struct iovec
#endif

#ifndef O_NOCTTY
Expand Down Expand Up @@ -295,6 +296,18 @@ FileDescriptor::FullWrite(std::span<const std::byte> src) const

#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
FileDescriptor::Poll(short events, int timeout) const noexcept
{
Expand Down
13 changes: 13 additions & 0 deletions src/io/FileDescriptor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wchar.h>
#endif

struct iovec;
class UniqueFileDescriptor;

/**
Expand Down Expand Up @@ -271,6 +272,18 @@ public:
void FullWrite(std::span<const std::byte> src) const;

#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]]
int Poll(short events, int timeout) const noexcept;

Expand Down

0 comments on commit 6d5e9e3

Please sign in to comment.