diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 1040b72c..1181979c 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -168,8 +168,8 @@ NetworkMessageType NetworkInterface::getNextMessageType(int waitMilliseconds) { ((waitMilliseconds <= 0 && socket->hasDataToRead() == true) || (waitMilliseconds > 0 && socket->hasDataToReadWithWait(waitMilliseconds) == true))) { //peek message type - //int dataSize = socket->getDataToRead(); - //if(dataSize >= (int)sizeof(messageType)) { + int dataSize = socket->getDataToRead(); + if(dataSize >= (int)sizeof(messageType)) { //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataSize); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] before recv\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -179,7 +179,7 @@ NetworkMessageType NetworkInterface::getNextMessageType(int waitMilliseconds) { int bytesReceived = socket->receive(&messageType, sizeof(messageType), true); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,bytesReceived,messageType,sizeof(messageType)); //} - //} + } //else { // if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize); //} diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 3668f69f..17d2e2f7 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1052,7 +1052,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) bool Socket::hasDataToRead() { - //MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); + MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); return Socket::hasDataToRead(sock) ; } @@ -1095,7 +1095,7 @@ bool Socket::hasDataToRead(PLATFORM_SOCKET socket) } bool Socket::hasDataToReadWithWait(int waitMicroseconds) { - //MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); + MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); return Socket::hasDataToReadWithWait(sock,waitMicroseconds) ; } @@ -1525,19 +1525,20 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError // safeMutexSocketDestructorFlag.ReleaseLock(); //MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize)); - //MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); + //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) { + 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("#1 PEEK err = %d lastSocketError = %d ms: %lld\n",err,lastSocketError,(long long int)recvTimer.getMillis()); @@ -1547,6 +1548,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError //} // } + safeMutex.ReleaseLock(); } //safeMutex.ReleaseLock(); @@ -1580,7 +1582,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError break; } */ - //if(Socket::isReadable(true) == true) { + if(Socket::isReadable(true) == true) { // MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE); // if(this->inSocketDestructor == true) { @@ -1591,17 +1593,17 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError // safeMutexSocketDestructorFlag.ReleaseLock(); //MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize)); - //MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); + 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()); @@ -1609,14 +1611,14 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError //printf("Socket peek delayed checking for sock = %d err = %d\n",sock,err); - //safeMutex.ReleaseLock(); + safeMutex.ReleaseLock(); if(err <= 0) { sleep(0); } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err); - //} + } //else { //printf("Socket peek delayed [NOT READABLE] checking for sock = %d err = %d\n",sock,err); //} @@ -1712,7 +1714,7 @@ bool Socket::isReadable(bool lockMutex) { MutexSafeWrapper safeMutex(NULL,CODE_AT_LINE); if(lockMutex == true) { - //safeMutex.setMutex(dataSynchAccessorRead,CODE_AT_LINE); + safeMutex.setMutex(dataSynchAccessorRead,CODE_AT_LINE); } FD_SET(sock, &set); int i = select((int)sock + 1, &set, NULL, NULL, &tv); @@ -1747,7 +1749,7 @@ bool Socket::isWritable(struct timeval *timeVal, bool lockMutex) { MutexSafeWrapper safeMutex(NULL,CODE_AT_LINE); if(lockMutex == true) { - //safeMutex.setMutex(dataSynchAccessorWrite,CODE_AT_LINE); + safeMutex.setMutex(dataSynchAccessorWrite,CODE_AT_LINE); } FD_SET(sock, &set); int i = select((int)sock + 1, NULL, &set, NULL, &tv);