From 079dbf808a1d5ba4005a8feb8c26a9cb073ad458 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 24 Mar 2013 05:16:56 +0000 Subject: [PATCH] - try to improve network performance --- .../glest_game/network/client_interface.cpp | 6 ++-- .../glest_game/network/server_interface.cpp | 28 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 7da32168..c8d5ebcf 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -304,7 +304,7 @@ void ClientInterface::connect(const Ip &ip, int port) { clientSocket->setBlock(false); clientSocket->connect(ip, port); connectedTime = time(NULL); - clientSocket->setBlock(true); + //clientSocket->setBlock(true); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END - socket = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,clientSocket->getSocketId()); } @@ -901,7 +901,7 @@ void ClientInterface::updateFrame(int *checkFrame) { Chrono chrono; chrono.start(); - int waitMicroseconds = (checkFrame == NULL ? 0 : 0); + int waitMicroseconds = (checkFrame == NULL ? 10 : 0); int simulateLag = Config::getInstance().getInt("SimulateClientLag","0"); bool done= false; while(done == false && this->quitThread == false) { @@ -1785,7 +1785,7 @@ NetworkMessageType ClientInterface::waitForMessage(int waitMicroseconds) return msg; } // Sleep every x milli-seconds we wait to let other threads work - else if(chrono.getMillis() % 100 == 0) { + else if(chrono.getMillis() % 20 == 0) { sleep(5); } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 3fde8ace..8777603a 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 &&