Handle interrupted/retry error code in read handler.

This commit is contained in:
lotodore
2009-07-30 21:47:30 +00:00
parent e6c1043993
commit b81d357f1a
+15 -8
View File
@@ -527,9 +527,9 @@ ServerLobbyThread::CancelTimers()
void void
ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId sessionId, size_t bytesRead) 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. // Find the session.
SessionWrapper session = m_sessionManager.GetSessionById(sessionId); SessionWrapper session = m_sessionManager.GetSessionById(sessionId);
@@ -538,6 +538,8 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
if (session.sessionData) if (session.sessionData)
{ {
ReceiveBuffer &buf = session.sessionData->GetReceiveBuffer(); ReceiveBuffer &buf = session.sessionData->GetReceiveBuffer();
if (!ec)
{
if (buf.recvBufUsed + bytesRead > RECV_BUF_SIZE) if (buf.recvBufUsed + bytesRead > RECV_BUF_SIZE)
LOG_ERROR("Session " << session.sessionData->GetId() << " - Internal error: Receive buffer overflow!"); LOG_ERROR("Session " << session.sessionData->GetId() << " - Internal error: Receive buffer overflow!");
buf.recvBufUsed += bytesRead; buf.recvBufUsed += bytesRead;
@@ -584,17 +586,21 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
boost::asio::placeholders::bytes_transferred)); 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) else if (ec != boost::asio::error::operation_aborted)
{ {
LOG_ERROR("Connection closed: " << ec); LOG_ERROR("Connection closed: " << ec);
// On error: Close this session. // 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()); boost::shared_ptr<ServerGame> game = InternalGetGameFromId(session.sessionData->GetGameId());
if (game) if (game)
game->ErrorRemoveSession(session); game->ErrorRemoveSession(session);
@@ -606,6 +612,7 @@ ServerLobbyThread::HandleRead(const boost::system::error_code &ec, SessionId ses
{ {
LOG_ERROR("Session " << sessionId << " - unhandled exception in HandleRead: " << e.what()); LOG_ERROR("Session " << sessionId << " - unhandled exception in HandleRead: " << e.what());
} }
}
} }
void void