From d703f7605bfa6e0665c12822522a5f617f421432 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 23 Mar 2013 23:18:50 +0000 Subject: [PATCH] - try to improve network performance --- .../glest_game/network/client_interface.cpp | 5 +++- .../glest_game/network/server_interface.cpp | 28 +++++++++---------- .../sources/platform/posix/socket.cpp | 8 +++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 6ce5d050..1c1ed192 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -79,8 +79,11 @@ void ClientInterfaceThread::execute() { Chrono chrono; // Set socket to blocking +// if(clientInterface != NULL && clientInterface->getSocket(true) != NULL) { +// clientInterface->getSocket(true)->setBlock(true); +// } if(clientInterface != NULL && clientInterface->getSocket(true) != NULL) { - clientInterface->getSocket(true)->setBlock(true); + clientInterface->getSocket(true)->setBlock(false); } for(;this->clientInterface != NULL;) { diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 8777603a..3fde8ace 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -2157,17 +2157,17 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { if(bOkToStart == true) { bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); - if(useInGameBlockingClientSockets == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - for(int i= 0; i < GameConstants::maxPlayers; ++i) { - int factionIndex = gameSettings->getFactionIndexForStartLocation(i); - MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); - ConnectionSlot *connectionSlot= slots[i]; - if(connectionSlot != NULL && connectionSlot->isConnected()) { - connectionSlot->getSocket()->setBlock(true); - } - } - } +// if(useInGameBlockingClientSockets == true) { +// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); +// for(int i= 0; i < GameConstants::maxPlayers; ++i) { +// int factionIndex = gameSettings->getFactionIndexForStartLocation(i); +// MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); +// ConnectionSlot *connectionSlot= slots[i]; +// if(connectionSlot != NULL && connectionSlot->isConnected()) { +// connectionSlot->getSocket()->setBlock(true); +// } +// } +// } bool requiresUPNPTrigger = false; if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -2273,9 +2273,9 @@ void ServerInterface::checkListenerSlots() { addSlot(i); connectionSlot = slots[i]; - if(useInGameBlockingClientSockets == true) { - connectionSlot->getSocket()->setBlock(true); - } +// if(useInGameBlockingClientSockets == true) { +// connectionSlot->getSocket()->setBlock(true); +// } connectionSlot->setCanAcceptConnections(true); } else if(connectionSlot != NULL && diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 5df10090..22ebe94c 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1500,14 +1500,14 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); if(isSocketValid() == true) { // Chrono recvTimer(true); - //SafeSocketBlockToggleWrapper safeUnblock(this, false); + SafeSocketBlockToggleWrapper safeUnblock(this, false); errno = 0; err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); lastSocketError = getLastSocketError(); if(pLastSocketError != NULL) { *pLastSocketError = lastSocketError; } - //safeUnblock.Restore(); + safeUnblock.Restore(); // if(recvTimer.getMillis() > 1000 || (err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN)) { // printf("#1 PEEK err = %d lastSocketError = %d ms: %lld\n",err,lastSocketError,(long long int)recvTimer.getMillis()); @@ -1563,14 +1563,14 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); // Chrono recvTimer(true); - //SafeSocketBlockToggleWrapper safeUnblock(this, false); + SafeSocketBlockToggleWrapper safeUnblock(this, false); errno = 0; err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); lastSocketError = getLastSocketError(); if(pLastSocketError != NULL) { *pLastSocketError = lastSocketError; } - //safeUnblock.Restore(); + safeUnblock.Restore(); // if(recvTimer.getMillis() > 1000 || (err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN)) { // printf("#2 PEEK err = %d lastSocketError = %d ms: %lld\n",err,lastSocketError,(long long int)recvTimer.getMillis());