From 099c67f93cf49cda90be55606e1b744c47624b92 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Apr 2013 14:48:07 +0300 Subject: improve network class. --- src/net/ea/network.cpp | 19 +++++++++---------- src/net/ea/network.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/net') diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index 00c83d3b0..c7441d579 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -144,10 +144,8 @@ void Network::flush() if (!mOutSize || mState != CONNECTED) return; - int ret; - SDL_mutexP(mMutex); - ret = TcpNet::send(mSocket, mOutBuffer, mOutSize); + int ret = TcpNet::send(mSocket, mOutBuffer, mOutSize); DEBUGLOG(std::string("Send ").append(toString(mOutSize)).append(" bytes")); if (ret < static_cast(mOutSize)) { @@ -158,7 +156,7 @@ void Network::flush() SDL_mutexV(mMutex); } -void Network::skip(int len) +void Network::skip(const int len) { SDL_mutexP(mMutex); mToSkip += len; @@ -189,8 +187,9 @@ bool Network::realConnect() if (TcpNet::resolveHost(&ipAddress, mServer.hostname.c_str(), mServer.port) == -1) { - std::string errorMessage = std::string(_("Unable to resolve host \"")) - .append(mServer.hostname).append("\""); + const std::string errorMessage = std::string( + _("Unable to resolve host \"")).append( + mServer.hostname).append("\""); setError(errorMessage); logger->log("TcpNet::ResolveHost: %s", errorMessage.c_str()); return false; @@ -210,7 +209,6 @@ bool Network::realConnect() ipToString(ipAddress.host), ipAddress.port); mState = CONNECTED; - return true; } @@ -237,7 +235,6 @@ void Network::receive() // to escape the loop const int numReady = TcpNet::checkSockets( set, (static_cast(500))); - int ret; switch (numReady) { case -1: @@ -247,6 +244,7 @@ void Network::receive() break; case 1: + { // Receive data from the socket SDL_mutexP(mMutex); if (mInSize > BUFFER_LIMIT) @@ -256,8 +254,8 @@ void Network::receive() continue; } - ret = TcpNet::recv(mSocket, mInBuffer + mInSize, - BUFFER_SIZE - mInSize); + int ret = TcpNet::recv(mSocket, mInBuffer + mInSize, + BUFFER_SIZE - mInSize); if (!ret) { @@ -291,6 +289,7 @@ void Network::receive() } SDL_mutexV(mMutex); break; + } default: // more than one socket is ready.. diff --git a/src/net/ea/network.h b/src/net/ea/network.h index ea56848ee..5e957346b 100644 --- a/src/net/ea/network.h +++ b/src/net/ea/network.h @@ -66,7 +66,7 @@ class Network int getInSize() const A_WARN_UNUSED { return mInSize; } - void skip(int len); + void skip(const int len); void flush(); -- cgit v1.2.3-70-g09d2