From 1acbeba426dc35a7983bb118b7b98b837bbabae7 Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 15 Jun 2009 06:42:52 +0000 Subject: [PATCH] Close the socket before client termination, don't let asio close it later because the callbacks might no longer be valid. --- src/net/common/clientthread.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index c72d2d34..cc1421a2 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -422,6 +422,11 @@ ClientThread::Main() 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(); } catch (const PokerTHException &e) { GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode()); @@ -443,6 +448,7 @@ ClientThread::RegisterTimers() boost::bind( &ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error)); + // TODO: send directly without additional buffer. m_sendTimer.expires_from_now( boost::posix_time::milliseconds(CLIENT_SEND_LOOP_MSEC)); m_sendTimer.async_wait(