浏览代码

Fix socket shutdown

Ivan Savenko 1 年之前
父节点
当前提交
a1f4748bbc
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      lib/serializer/Connection.cpp

+ 11 - 2
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<class T>
@@ -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();
 	}