diff --git a/src/net/clientthread.h b/src/net/clientthread.h index d3e2e069..7009ed28 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -107,7 +107,7 @@ protected: void CancelTimers(); void InitGame(); - void SendPacket(boost::shared_ptr packet); + void SendSessionPacket(boost::shared_ptr packet); bool GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const; void RequestPlayerInfo(unsigned id, bool requestAvatar = false); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 298c42ec..620ef13a 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -123,14 +123,14 @@ ClientThread::SendKickPlayer(unsigned playerId) NetPacketKickPlayer::Data requestData; requestData.playerId = playerId; static_cast(request.get())->SetData(requestData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), request)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), request)); } void ClientThread::SendLeaveCurrentGame() { boost::shared_ptr request(new NetPacketLeaveCurrentGame); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), request)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), request)); } void @@ -144,7 +144,7 @@ ClientThread::SendStartEvent(bool fillUpWithCpuPlayers) try { static_cast(start.get())->SetData(startData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), start)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), start)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendStartEvent: " << e.what()); @@ -170,7 +170,7 @@ ClientThread::SendPlayerAction() { static_cast(action.get())->SetData(actionData); // Just dump the packet. - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), action)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), action)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendPlayerAction: " << e.what()); @@ -189,7 +189,7 @@ ClientThread::SendChatMessage(const std::string &msg) { static_cast(chat.get())->SetData(chatData); // Just dump the packet. - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), chat)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), chat)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendChatMessage: " << e.what()); @@ -208,7 +208,7 @@ ClientThread::SendJoinFirstGame(const std::string &password) try { static_cast(join.get())->SetData(joinData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), join)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), join)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendJoinFirstGame: " << e.what()); @@ -227,7 +227,7 @@ ClientThread::SendJoinGame(unsigned gameId, const std::string &password) try { static_cast(join.get())->SetData(joinData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), join)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), join)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendJoinGame: " << e.what()); @@ -247,7 +247,7 @@ ClientThread::SendCreateGame(const GameData &gameData, const std::string &name, try { static_cast(create.get())->SetData(createData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), create)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), create)); } catch (const NetException &e) { LOG_ERROR("ClientThread::SendCreateGame: " << e.what()); @@ -258,7 +258,7 @@ void ClientThread::SendResetTimeout() { boost::shared_ptr reset(new NetPacketResetTimeout); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), reset)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), reset)); } void @@ -268,7 +268,7 @@ ClientThread::SendAskKickPlayer(unsigned playerId) NetPacketAskKickPlayer::Data askData; askData.playerId = playerId; static_cast(ask.get())->SetData(askData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), ask)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), ask)); } void @@ -282,7 +282,7 @@ ClientThread::SendVoteKick(bool doKick) } voteData.vote = doKick ? KICK_VOTE_IN_FAVOUR : KICK_VOTE_AGAINST; static_cast(vote.get())->SetData(voteData); - m_ioService->post(boost::bind(&ClientThread::SendPacket, shared_from_this(), vote)); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), vote)); } void @@ -424,22 +424,18 @@ ClientThread::Main() boost::asio::io_service::work ioWork(*m_ioService); try { - { - boost::asio::io_service::work ioWork(*m_ioService); - m_ioService->run(); // Will only be aborted asynchronously. - } - // Close the socket. - GetContext().GetSessionData()->GetAsioSocket()->close(); - // Execute remaining ready handlers. - m_ioService->reset(); - m_ioService->poll(); - // Set a state which does not do anything. - SetState(CLIENT_FINAL_STATE::Instance()); + boost::asio::io_service::work ioWork(*m_ioService); + m_ioService->run(); // Will only be aborted asynchronously. } catch (const PokerTHException &e) { GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode()); } + // Close the socket. + boost::system::error_code ec; + GetContext().GetSessionData()->GetAsioSocket()->close(); + // Set a state which does not do anything. + SetState(CLIENT_FINAL_STATE::Instance()); // Cancel timers. GetStateTimer().cancel(); CancelTimers(); @@ -481,7 +477,7 @@ ClientThread::InitGame() } void -ClientThread::SendPacket(boost::shared_ptr packet) +ClientThread::SendSessionPacket(boost::shared_ptr packet) { // Put packets in a buffer until the session is established. if (IsSessionEstablished()) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index b7a1ed02..286d84ed 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -513,22 +513,17 @@ ServerLobbyThread::Main() RegisterTimers(); try { - { - boost::asio::io_service::work ioWork(*m_ioService); - m_ioService->run(); // Will only be aborted asynchronously. - } + boost::asio::io_service::work ioWork(*m_ioService); + m_ioService->run(); // Will only be aborted asynchronously. - // Clear all sessions. - m_sessionManager.Clear(); - m_gameSessionManager.Clear(); - // Execute remaining ready handlers. - m_ioService->reset(); - m_ioService->poll(); } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); LOG_ERROR(e.what()); } + // Clear all sessions. + m_sessionManager.Clear(); + m_gameSessionManager.Clear(); // Cancel pending timer callbacks. CancelTimers(); }