diff --git a/src/net/clientstate.h b/src/net/clientstate.h index 41f4c5fc..f6843fc9 100644 --- a/src/net/clientstate.h +++ b/src/net/clientstate.h @@ -42,7 +42,7 @@ public: virtual void Enter(boost::shared_ptr client) = 0; virtual void Exit(boost::shared_ptr client) = 0; - virtual void HandleRead(const boost::system::error_code& ec, boost::shared_ptr client, size_t bytesRead) = 0; + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) = 0; }; // State: Initialization. @@ -57,7 +57,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: // Protected constructor - this is a singleton. @@ -76,15 +76,16 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: - void HandleResolve( - const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator endpoint_iterator, - boost::shared_ptr client); // Protected constructor - this is a singleton. ClientStateStartResolve(); + + void HandleResolve( + const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator endpoint_iterator, + boost::shared_ptr client); }; // State: Start download of the server list. @@ -99,7 +100,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: @@ -118,7 +119,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} void SetDownloadHelper(boost::shared_ptr helper); @@ -146,7 +147,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} void SetDownloadHelper(boost::shared_ptr helper); @@ -173,7 +174,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: @@ -191,7 +192,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: @@ -213,7 +214,7 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} void SetRemoteEndpoint(boost::asio::ip::tcp::resolver::iterator endpointIterator); @@ -243,10 +244,9 @@ public: virtual void Enter(boost::shared_ptr client); virtual void Exit(boost::shared_ptr client); - virtual void HandleRead(const boost::system::error_code& /*ec*/, boost::shared_ptr /*client*/, size_t /*bytesRead*/) {} + virtual void HandlePacket(boost::shared_ptr /*client*/, boost::shared_ptr /*tmpPacket*/) {} protected: - // Protected constructor - this is a singleton. ClientStateStartSession(); }; @@ -257,12 +257,11 @@ class AbstractClientStateReceiving : public ClientState public: virtual ~AbstractClientStateReceiving(); - virtual void HandleRead(const boost::system::error_code& ec, boost::shared_ptr client, size_t bytesRead); + virtual void HandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket); protected: AbstractClientStateReceiving(); - void HandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket); virtual void InternalHandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket) = 0; }; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 29c35c6a..88750fba 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -701,30 +701,6 @@ AbstractClientStateReceiving::~AbstractClientStateReceiving() { } -void -AbstractClientStateReceiving::HandleRead(const boost::system::error_code& ec, boost::shared_ptr client, size_t bytesRead) -{ - if (!ec) - { - ReceiveBuffer &buf = client->GetContext().GetSessionData()->GetReceiveBuffer(); - buf.recvBufUsed += bytesRead; - client->GetReceiver().ScanPackets(buf); - - while (!buf.receivedPackets.empty()) - { - boost::shared_ptr packet = buf.receivedPackets.front(); - buf.receivedPackets.pop_front(); - if (packet) - HandlePacket(client, packet); - } - } - else - { - if (ec != boost::asio::error::operation_aborted) - throw NetException(__FILE__, __LINE__, ERR_SOCK_CONN_RESET, 0); - } -} - void AbstractClientStateReceiving::HandlePacket(boost::shared_ptr client, boost::shared_ptr tmpPacket) { diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index cc1421a2..88808416 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -312,9 +312,26 @@ ClientThread::StartAsyncRead() void ClientThread::HandleRead(const boost::system::error_code& ec, size_t bytesRead) { - GetState().HandleRead(ec, shared_from_this(), bytesRead); if (!ec) + { + ReceiveBuffer &buf = GetContext().GetSessionData()->GetReceiveBuffer(); + buf.recvBufUsed += bytesRead; + GetReceiver().ScanPackets(buf); + + while (!buf.receivedPackets.empty()) + { + boost::shared_ptr packet = buf.receivedPackets.front(); + buf.receivedPackets.pop_front(); + if (packet) + GetState().HandlePacket(shared_from_this(), packet); + } StartAsyncRead(); + } + else + { + if (ec != boost::asio::error::operation_aborted) + throw NetException(__FILE__, __LINE__, ERR_SOCK_CONN_RESET, 0); + } } void