From c9fb0160dc94a4419fb07cf9d050a18ebab09661 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 25 Dec 2015 14:08:54 -0800 Subject: [PATCH] - attempt to fix hand in windwos network games --- .../glest_game/network/network_interface.cpp | 2 +- source/glest_game/network/network_message.h | 2 +- .../sources/platform/posix/socket.cpp | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 8ff4d2360..394f0d11e 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -128,7 +128,7 @@ NetworkMessageType NetworkInterface::getNextMessageType(int waitMilliseconds) //peek message type 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] socket->getDataToRead() dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataSize); int iPeek = socket->peek(&messageType, sizeof(messageType)); diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index d94fb42f1..83aa59f7a 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -115,7 +115,7 @@ public: void dump_packet(string label, const void* data, int dataSize, bool isSend); protected: - //bool peek(Socket* socket, void* data, int dataSize); + bool receive(Socket* socket, void* data, int dataSize,bool tryReceiveUntilDataSizeMet); void send(Socket* socket, const void* data, int dataSize); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 0bf023e25..90d4f2489 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1524,14 +1524,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()); @@ -1588,14 +1588,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()); @@ -1615,8 +1615,8 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError 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()); } - else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 SOCKET appears to be invalid [%d] lastSocketError [%d] err [%d] mustGetData [%d]\n",__FILE__,__FUNCTION__,__LINE__,sock,lastSocketError,err,mustGetData); + else if (err == 0) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 SOCKET appears to be invalid [%d] lastSocketError [%d] err [%d] mustGetData [%d] dataSize [%d]\n",__FILE__,__FUNCTION__,__LINE__,sock,lastSocketError,err,mustGetData,dataSize); } //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); @@ -1626,7 +1626,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError //printf("** #1 Socket peek error for sock = %d err = %d lastSocketError = %d\n",sock,err,lastSocketError); int iErr = lastSocketError; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTING SOCKET for socket [%d], err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,socket,err,getLastSocketErrorFormattedText(&iErr).c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTING SOCKET for socket [%d], err = %d, dataSize = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,sock,err,dataSize,getLastSocketErrorFormattedText(&iErr).c_str()); //printf("Peek #3 err = %d\n",err); //lastSocketError = getLastSocketError(); if(mustGetData == true || lastSocketError != PLATFORM_SOCKET_TRY_AGAIN) { @@ -1635,7 +1635,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError int iErr = lastSocketError; disconnectSocket(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data for socket [%d], err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,socket,err,getLastSocketErrorFormattedText(&iErr).c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data for socket [%d], err = %d, dataSize = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,sock,err,dataSize,getLastSocketErrorFormattedText(&iErr).c_str()); } } @@ -1787,7 +1787,7 @@ bool Socket::isConnected() { char tmp=0; int peekDataBytes=1; int lastSocketError=0; - //int err = peek(&tmp, 1, false, &lastSocketError); + int err = peek(&tmp, peekDataBytes, false, &lastSocketError); //if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) { //if(err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN) {