1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fix socket shutdown

This commit is contained in:
Ivan Savenko 2023-12-03 18:56:23 +02:00
parent 773071fee3
commit a1f4748bbc

View File

@ -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();
}