mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 00:48:56 +01:00
Core/Network: Fix some possible exceptions on socket.close()
Ref #12634
This commit is contained in:
@@ -161,7 +161,7 @@ void AuthSession::AsyncReadHeader()
|
||||
}
|
||||
else
|
||||
{
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -176,7 +176,7 @@ void AuthSession::AsyncReadData(bool (AuthSession::*handler)(), size_t dataSize,
|
||||
{
|
||||
if (!(*this.*handler)())
|
||||
{
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void AuthSession::AsyncReadData(bool (AuthSession::*handler)(), size_t dataSize,
|
||||
}
|
||||
else
|
||||
{
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -195,7 +195,7 @@ void AuthSession::AsyncWrite(std::size_t length)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -935,3 +935,11 @@ void AuthSession::SetVSFields(const std::string& rI)
|
||||
OPENSSL_free(v_hex);
|
||||
OPENSSL_free(s_hex);
|
||||
}
|
||||
|
||||
void AuthSession::CloseSocket()
|
||||
{
|
||||
boost::system::error_code socketError;
|
||||
_socket.close(socketError);
|
||||
if (socketError)
|
||||
TC_LOG_DEBUG("server.authserver", "Account '%s' errored when closing socket: %i (%s)", _login.c_str(), socketError.value(), socketError.message());
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ private:
|
||||
void AsyncReadData(bool (AuthSession::*handler)(), size_t dataSize, size_t bufferOffset);
|
||||
void AsyncWrite(size_t length);
|
||||
|
||||
void CloseSocket();
|
||||
|
||||
void SetVSFields(const std::string& rI);
|
||||
|
||||
|
||||
@@ -78,8 +78,7 @@ void WorldSocket::AsyncReadHeader()
|
||||
else
|
||||
{
|
||||
// _socket.is_open() till returns true even after calling close()
|
||||
boost::system::error_code socketError;
|
||||
_socket.close(socketError);
|
||||
CloseSocket();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -155,8 +154,7 @@ void WorldSocket::AsyncReadData(size_t dataSize)
|
||||
else
|
||||
{
|
||||
// _socket.is_open() till returns true even after calling close()
|
||||
boost::system::error_code socketError;
|
||||
_socket.close(socketError);
|
||||
CloseSocket();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -202,7 +200,7 @@ void WorldSocket::AsyncWrite(std::vector<uint8> const& data)
|
||||
AsyncWrite(_writeQueue.front());
|
||||
}
|
||||
else
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -475,7 +473,7 @@ void WorldSocket::HandlePing(WorldPacket& recvPacket)
|
||||
TC_LOG_ERROR("network", "WorldSocket::HandlePing: %s kicked for over-speed pings (address: %s)",
|
||||
_worldSession->GetPlayerInfo().c_str(), GetRemoteIpAddress().c_str());
|
||||
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -494,7 +492,7 @@ void WorldSocket::HandlePing(WorldPacket& recvPacket)
|
||||
TC_LOG_ERROR("network", "WorldSocket::HandlePing: peer sent CMSG_PING, but is not authenticated or got recently kicked, address = %s",
|
||||
GetRemoteIpAddress().c_str());
|
||||
|
||||
_socket.close();
|
||||
CloseSocket();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -502,3 +500,13 @@ void WorldSocket::HandlePing(WorldPacket& recvPacket)
|
||||
packet << ping;
|
||||
return AsyncWrite(packet);
|
||||
}
|
||||
|
||||
void WorldSocket::CloseSocket()
|
||||
{
|
||||
boost::system::error_code socketError;
|
||||
_socket.close(socketError);
|
||||
if (socketError)
|
||||
TC_LOG_DEBUG("network", "WorldSocket::CloseSocket: Player '%s' (%s) errored when closing socket: %i (%s)",
|
||||
_worldSession ? _worldSession->GetPlayerInfo().c_str() : "unknown", GetRemoteIpAddress().c_str(),
|
||||
socketError.value(), socketError.message());
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); };
|
||||
uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); }
|
||||
|
||||
void CloseSocket() { _socket.close(); };
|
||||
bool IsOpen() { return _socket.is_open(); };
|
||||
void CloseSocket();
|
||||
bool IsOpen() const { return _socket.is_open(); }
|
||||
|
||||
void AsyncWrite(WorldPacket const& packet);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user