Fixed a rare crash case when authserver socket was forcefully closed during read

Closes #12634
This commit is contained in:
leak
2014-07-27 17:33:56 +02:00
parent eabf0f44dd
commit e502e01f5d

View File

@@ -56,7 +56,16 @@ public:
void ReadData(std::size_t size, std::size_t bufferOffset)
{
_socket.read_some(boost::asio::buffer(&_readBuffer[bufferOffset], size));
boost::system::error_code error;
_socket.read_some(boost::asio::buffer(&_readBuffer[bufferOffset], size), error);
if (error)
{
TC_LOG_DEBUG("network", "Socket::ReadData: %s errored with: %i (%s)", GetRemoteIpAddress().to_string().c_str(), error.value(), error.message().c_str());
CloseSocket();
}
}
void AsyncWrite(PacketType const& data)
@@ -68,11 +77,11 @@ public:
bool IsOpen() const { return _socket.is_open(); }
void CloseSocket()
{
boost::system::error_code socketError;
_socket.close(socketError);
if (socketError)
boost::system::error_code error;
_socket.close(error);
if (error)
TC_LOG_DEBUG("network", "Socket::CloseSocket: %s errored when closing socket: %i (%s)", GetRemoteIpAddress().to_string().c_str(),
socketError.value(), socketError.message().c_str());
error.value(), error.message().c_str());
}
uint8* GetReadBuffer() { return _readBuffer; }