diff --git a/src/net/SocketDescriptor.cxx b/src/net/SocketDescriptor.cxx index 8cdce6f6e..b86a07dfa 100644 --- a/src/net/SocketDescriptor.cxx +++ b/src/net/SocketDescriptor.cxx @@ -417,6 +417,12 @@ SocketDescriptor::Receive(std::span dest, int flags) const noexcept return ::recv(Get(), (char *)dest.data(), dest.size(), flags); } +ssize_t +SocketDescriptor::Receive(struct msghdr &msg, int flags) const noexcept +{ + return ::recvmsg(Get(), &msg, flags); +} + ssize_t SocketDescriptor::Send(std::span src, int flags) const noexcept { @@ -427,6 +433,16 @@ SocketDescriptor::Send(std::span src, int flags) const noexcept return ::send(Get(), (const char *)src.data(), src.size(), flags); } +ssize_t +SocketDescriptor::Send(const struct msghdr &msg, int flags) const noexcept +{ +#ifdef __linux__ + flags |= MSG_NOSIGNAL; +#endif + + return ::sendmsg(Get(), &msg, flags); +} + ssize_t SocketDescriptor::ReadNoWait(std::span dest) const noexcept { diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx index 03a994bb0..029c4ed83 100644 --- a/src/net/SocketDescriptor.hxx +++ b/src/net/SocketDescriptor.hxx @@ -303,6 +303,12 @@ public: [[nodiscard]] ssize_t Receive(std::span dest, int flags=0) const noexcept; + /** + * Wrapper for recvmsg(). + */ + [[nodiscard]] + ssize_t Receive(struct msghdr &msg, int flags=0) const noexcept; + /** * Wrapper for send(). * @@ -311,6 +317,14 @@ public: [[nodiscard]] ssize_t Send(std::span src, int flags=0) const noexcept; + /** + * Wrapper for sendmsg(). + * + * MSG_NOSIGNAL is implicitly added (if available). + */ + [[nodiscard]] + ssize_t Send(const struct msghdr &msg, int flags=0) const noexcept; + [[nodiscard]] ssize_t Read(std::span dest) const noexcept { return Receive(dest);