From 9db918c7c29a82e3935b6064c000395dc138c4df Mon Sep 17 00:00:00 2001 From: Cloaked9000 Date: Tue, 20 Dec 2016 10:07:40 +0000 Subject: [PATCH] Added fr::TcpSocket::shutdown to shutdown a socket --- include/frnetlib/TcpSocket.h | 10 ++++++++++ src/TcpSocket.cpp | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/include/frnetlib/TcpSocket.h b/include/frnetlib/TcpSocket.h index 281ef64..3ccb835 100644 --- a/include/frnetlib/TcpSocket.h +++ b/include/frnetlib/TcpSocket.h @@ -91,6 +91,16 @@ public: */ int32_t get_socket_descriptor() const override; + /*! + * Calls the shutdown syscall on the socket. + * So you can receive data but not send. + * + * This can be called on a blocking socket to force + * it to immediately return (you might want to do this if + * you're exiting and need the blocking socket to return). + */ + void shutdown(); + protected: std::string unprocessed_buffer; std::unique_ptr recv_buffer; diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index f483e70..d039486 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -157,4 +157,9 @@ namespace fr return socket_descriptor; } + void TcpSocket::shutdown() + { + ::shutdown(socket_descriptor, 0); + } + } \ No newline at end of file