From d78f647839745145421776d72f967e51c28ed063 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Nov 2024 08:48:27 +0100 Subject: [PATCH] io/FileDescriptor: add readv()/writev() wrappers --- src/io/FileDescriptor.cxx | 13 +++++++++++++ src/io/FileDescriptor.hxx | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/io/FileDescriptor.cxx b/src/io/FileDescriptor.cxx index 5d326b1a..031579cc 100644 --- a/src/io/FileDescriptor.cxx +++ b/src/io/FileDescriptor.cxx @@ -13,6 +13,7 @@ #ifndef _WIN32 #include +#include // for struct iovec #endif #ifndef O_NOCTTY @@ -295,6 +296,18 @@ FileDescriptor::FullWrite(std::span src) const #ifndef _WIN32 +ssize_t +FileDescriptor::Read(std::span v) const noexcept +{ + return readv(fd, v.data(), v.size()); +} + +ssize_t +FileDescriptor::Write(std::span v) const noexcept +{ + return writev(fd, v.data(), v.size()); +} + int FileDescriptor::Poll(short events, int timeout) const noexcept { diff --git a/src/io/FileDescriptor.hxx b/src/io/FileDescriptor.hxx index 458cd816..6bb9c45c 100644 --- a/src/io/FileDescriptor.hxx +++ b/src/io/FileDescriptor.hxx @@ -14,6 +14,7 @@ #include #endif +struct iovec; class UniqueFileDescriptor; /** @@ -271,6 +272,18 @@ public: void FullWrite(std::span src) const; #ifndef _WIN32 + /** + * Wrapper for readv(). + */ + [[nodiscard]] + ssize_t Read(std::span v) const noexcept; + + /** + * Wrapper for writev(). + */ + [[nodiscard]] + ssize_t Write(std::span v) const noexcept; + [[nodiscard]] int Poll(short events, int timeout) const noexcept;