From fd923d5d96e33d5a677139a9fdfe5e8349b07638 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Aug 2018 11:31:58 +0200 Subject: [PATCH] net/SocketDescriptor: add Shutdown() --- src/net/SocketDescriptor.cxx | 22 ++++++++++++++++++++++ src/net/SocketDescriptor.hxx | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/net/SocketDescriptor.cxx b/src/net/SocketDescriptor.cxx index 46c6a2240..8d7779ca0 100644 --- a/src/net/SocketDescriptor.cxx +++ b/src/net/SocketDescriptor.cxx @@ -488,3 +488,25 @@ SocketDescriptor::Write(const void *buffer, size_t length, return ::sendto(Get(), (const char *)buffer, length, flags, address.GetAddress(), address.GetSize()); } + +#ifndef _WIN32 + +void +SocketDescriptor::Shutdown() noexcept +{ + shutdown(Get(), SHUT_RDWR); +} + +void +SocketDescriptor::ShutdownRead() noexcept +{ + shutdown(Get(), SHUT_RD); +} + +void +SocketDescriptor::ShutdownWrite() noexcept +{ + shutdown(Get(), SHUT_WR); +} + +#endif diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx index 89eb2abd9..212e10c7c 100644 --- a/src/net/SocketDescriptor.hxx +++ b/src/net/SocketDescriptor.hxx @@ -241,6 +241,12 @@ public: */ ssize_t Write(const void *buffer, size_t length, SocketAddress address) noexcept; + +#ifndef _WIN32 + void Shutdown() noexcept; + void ShutdownRead() noexcept; + void ShutdownWrite() noexcept; +#endif }; static_assert(std::is_trivial::value, "type is not trivial");