summaryrefslogtreecommitdiff
path: root/src/net/ea/network.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-08 23:09:49 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-08 23:09:49 +0300
commit4f948c82ea95c6b9fac307f455fe91851e27017a (patch)
tree4eaa6aecdd68e2da17433517212b92028bf565e0 /src/net/ea/network.cpp
parent72e775bac71b2d4b5103a0e8a6f03875b1617321 (diff)
downloadManaVerse-4f948c82ea95c6b9fac307f455fe91851e27017a.tar.gz
ManaVerse-4f948c82ea95c6b9fac307f455fe91851e27017a.tar.bz2
ManaVerse-4f948c82ea95c6b9fac307f455fe91851e27017a.tar.xz
ManaVerse-4f948c82ea95c6b9fac307f455fe91851e27017a.zip
split network mutexe into read and write mutexes.
Diffstat (limited to 'src/net/ea/network.cpp')
-rw-r--r--src/net/ea/network.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 87ab01722..ab76fd220 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -61,7 +61,8 @@ Network::Network() :
mState(IDLE),
mError(),
mWorkerThread(nullptr),
- mMutex(SDL_CreateMutex()),
+ mMutexIn(SDL_CreateMutex()),
+ mMutexOut(SDL_CreateMutex()),
mSleep(config.getIntValue("networksleep"))
{
TcpNet::init();
@@ -72,8 +73,10 @@ Network::~Network()
if (mState != IDLE && mState != NET_ERROR)
disconnect();
- SDL_DestroyMutex(mMutex);
- mMutex = nullptr;
+ SDL_DestroyMutex(mMutexIn);
+ mMutexIn = nullptr;
+ SDL_DestroyMutex(mMutexOut);
+ mMutexOut = nullptr;
delete []mInBuffer;
delete []mOutBuffer;
@@ -146,25 +149,26 @@ void Network::flush()
if (!mOutSize || mState != CONNECTED)
return;
- SDL_mutexP(mMutex);
+ SDL_mutexP(mMutexOut);
const int ret = TcpNet::send(mSocket, mOutBuffer, mOutSize);
DEBUGLOG(std::string("Send ").append(toString(mOutSize)).append(" bytes"));
if (ret < static_cast<int>(mOutSize))
{
+ SDL_mutexV(mMutexOut);
setError("Error in TcpNet::send(): " +
std::string(TcpNet::getError()));
}
mOutSize = 0;
- SDL_mutexV(mMutex);
+ SDL_mutexV(mMutexOut);
}
void Network::skip(const int len)
{
- SDL_mutexP(mMutex);
+ SDL_mutexP(mMutexIn);
mToSkip += len;
if (!mInSize)
{
- SDL_mutexV(mMutex);
+ SDL_mutexV(mMutexIn);
return;
}
@@ -179,7 +183,7 @@ void Network::skip(const int len)
mToSkip -= mInSize;
mInSize = 0;
}
- SDL_mutexV(mMutex);
+ SDL_mutexV(mMutexIn);
}
bool Network::realConnect()
@@ -252,10 +256,10 @@ void Network::receive()
case 1:
{
// Receive data from the socket
- SDL_mutexP(mMutex);
+ SDL_mutexP(mMutexIn);
if (mInSize > BUFFER_LIMIT)
{
- SDL_mutexV(mMutex);
+ SDL_mutexV(mMutexIn);
SDL_Delay(100);
continue;
}
@@ -294,7 +298,7 @@ void Network::receive()
}
}
}
- SDL_mutexV(mMutex);
+ SDL_mutexV(mMutexIn);
break;
}