From a1f4748bbc6816c41ee6ed0dcc93509814436789 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 3 Dec 2023 18:56:23 +0200 Subject: [PATCH] Fix socket shutdown --- lib/serializer/Connection.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/serializer/Connection.cpp b/lib/serializer/Connection.cpp index c4c98f4f6..de5f3b85d 100644 --- a/lib/serializer/Connection.cpp +++ b/lib/serializer/Connection.cpp @@ -221,6 +221,8 @@ int CConnection::read(void * data, unsigned size) CConnection::~CConnection() { + close(); + if(handler) { // ugly workaround to avoid self-join if last strong reference to shared_ptr that owns this class has been released in this very thread, e.g. on netpack processing @@ -229,8 +231,6 @@ CConnection::~CConnection() else handler->detach(); } - - close(); } template @@ -246,6 +246,15 @@ void CConnection::close() { if(socket) { + try + { + socket->shutdown(boost::asio::ip::tcp::socket::shutdown_receive); + } + catch (const boost::system::system_error & e) + { + logNetwork->error("error closing socket: %s", e.what()); + } + socket->close(); socket.reset(); }