summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-09 14:48:07 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-09 14:48:07 +0300
commit099c67f93cf49cda90be55606e1b744c47624b92 (patch)
tree43a07082db3961e7aa121813ec52c6add0de6df8 /src/net
parent8d1a43609fcf67bbffb26ab52fdb07f095f602b8 (diff)
downloadmanaverse-099c67f93cf49cda90be55606e1b744c47624b92.tar.gz
manaverse-099c67f93cf49cda90be55606e1b744c47624b92.tar.bz2
manaverse-099c67f93cf49cda90be55606e1b744c47624b92.tar.xz
manaverse-099c67f93cf49cda90be55606e1b744c47624b92.zip
improve network class.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/network.cpp19
-rw-r--r--src/net/ea/network.h2
2 files changed, 10 insertions, 11 deletions
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<int>(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<uint32_t>(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();