- try to improve network performance

This commit is contained in:
Mark Vejvoda 2013-03-23 23:18:50 +00:00
parent 01b757a743
commit d703f7605b
3 changed files with 22 additions and 19 deletions

View File

@ -79,8 +79,11 @@ void ClientInterfaceThread::execute() {
Chrono chrono; Chrono chrono;
// Set socket to blocking // Set socket to blocking
// if(clientInterface != NULL && clientInterface->getSocket(true) != NULL) {
// clientInterface->getSocket(true)->setBlock(true);
// }
if(clientInterface != NULL && clientInterface->getSocket(true) != NULL) { if(clientInterface != NULL && clientInterface->getSocket(true) != NULL) {
clientInterface->getSocket(true)->setBlock(true); clientInterface->getSocket(true)->setBlock(false);
} }
for(;this->clientInterface != NULL;) { for(;this->clientInterface != NULL;) {

View File

@ -2157,17 +2157,17 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
if(bOkToStart == true) { if(bOkToStart == true) {
bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true");
if(useInGameBlockingClientSockets == 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__); // 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) { // for(int i= 0; i < GameConstants::maxPlayers; ++i) {
int factionIndex = gameSettings->getFactionIndexForStartLocation(i); // int factionIndex = gameSettings->getFactionIndexForStartLocation(i);
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); // MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot= slots[i]; // ConnectionSlot *connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected()) { // if(connectionSlot != NULL && connectionSlot->isConnected()) {
connectionSlot->getSocket()->setBlock(true); // connectionSlot->getSocket()->setBlock(true);
} // }
} // }
} // }
bool requiresUPNPTrigger = false; 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__); 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); addSlot(i);
connectionSlot = slots[i]; connectionSlot = slots[i];
if(useInGameBlockingClientSockets == true) { // if(useInGameBlockingClientSockets == true) {
connectionSlot->getSocket()->setBlock(true); // connectionSlot->getSocket()->setBlock(true);
} // }
connectionSlot->setCanAcceptConnections(true); connectionSlot->setCanAcceptConnections(true);
} }
else if(connectionSlot != NULL && else if(connectionSlot != NULL &&

View File

@ -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(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) { if(isSocketValid() == true) {
// Chrono recvTimer(true); // Chrono recvTimer(true);
//SafeSocketBlockToggleWrapper safeUnblock(this, false); SafeSocketBlockToggleWrapper safeUnblock(this, false);
errno = 0; errno = 0;
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK); err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
lastSocketError = getLastSocketError(); lastSocketError = getLastSocketError();
if(pLastSocketError != NULL) { if(pLastSocketError != NULL) {
*pLastSocketError = lastSocketError; *pLastSocketError = lastSocketError;
} }
//safeUnblock.Restore(); safeUnblock.Restore();
// if(recvTimer.getMillis() > 1000 || (err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN)) { // 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()); // 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); MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
// Chrono recvTimer(true); // Chrono recvTimer(true);
//SafeSocketBlockToggleWrapper safeUnblock(this, false); SafeSocketBlockToggleWrapper safeUnblock(this, false);
errno = 0; errno = 0;
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK); err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
lastSocketError = getLastSocketError(); lastSocketError = getLastSocketError();
if(pLastSocketError != NULL) { if(pLastSocketError != NULL) {
*pLastSocketError = lastSocketError; *pLastSocketError = lastSocketError;
} }
//safeUnblock.Restore(); safeUnblock.Restore();
// if(recvTimer.getMillis() > 1000 || (err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN)) { // 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()); // printf("#2 PEEK err = %d lastSocketError = %d ms: %lld\n",err,lastSocketError,(long long int)recvTimer.getMillis());