Handle interrupted/retry error code in read handler.
This commit is contained in:
@@ -527,9 +527,9 @@ ServerLobbyThread::CancelTimers()
|
||||
void
|
||||
ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId sessionId, size_t bytesRead)
|
||||
{
|
||||
try
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
{
|
||||
if (!ec)
|
||||
try
|
||||
{
|
||||
// Find the session.
|
||||
SessionWrapper session = m_sessionManager.GetSessionById(sessionId);
|
||||
@@ -538,6 +538,8 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
|
||||
if (session.sessionData)
|
||||
{
|
||||
ReceiveBuffer &buf = session.sessionData->GetReceiveBuffer();
|
||||
if (!ec)
|
||||
{
|
||||
if (buf.recvBufUsed + bytesRead > RECV_BUF_SIZE)
|
||||
LOG_ERROR("Session " << session.sessionData->GetId() << " - Internal error: Receive buffer overflow!");
|
||||
buf.recvBufUsed += bytesRead;
|
||||
@@ -584,17 +586,21 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
}
|
||||
else if (ec == boost::asio::error::interrupted || ec == boost::asio::error::try_again)
|
||||
{
|
||||
session.sessionData->GetAsioSocket()->async_read_some(
|
||||
boost::asio::buffer(buf.recvBuf + buf.recvBufUsed, RECV_BUF_SIZE - buf.recvBufUsed),
|
||||
boost::bind(
|
||||
&ServerLobbyThread::HandleRead,
|
||||
this,
|
||||
boost::asio::placeholders::error,
|
||||
sessionId,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
else if (ec != boost::asio::error::operation_aborted)
|
||||
{
|
||||
LOG_ERROR("Connection closed: " << ec);
|
||||
// On error: Close this session.
|
||||
// Find the session.
|
||||
SessionWrapper session = m_sessionManager.GetSessionById(sessionId);
|
||||
if (!session.sessionData)
|
||||
session = m_gameSessionManager.GetSessionById(sessionId);
|
||||
if (session.sessionData)
|
||||
{
|
||||
boost::shared_ptr<ServerGame> game = InternalGetGameFromId(session.sessionData->GetGameId());
|
||||
if (game)
|
||||
game->ErrorRemoveSession(session);
|
||||
@@ -607,6 +613,7 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
|
||||
LOG_ERROR("Session " << sessionId << " - unhandled exception in HandleRead: " << e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::HandlePacket(SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
|
||||
Reference in New Issue
Block a user