From b805308a42d0e716cf46c7948178176f28066d67 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 15 Mar 2013 00:31:51 +0000 Subject: [PATCH] - bugfixes for detecting client disconnection --- source/glest_game/network/connection_slot.cpp | 7 +++++++ source/shared_lib/sources/platform/posix/socket.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 989d5820..092728af 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -1458,6 +1458,8 @@ void ConnectionSlot::close() { //printf("Closing connection slot!\n"); //} + //printf("ConnectionSlot::close() #1 this->getSocket() = %p\n",this->getSocket()); + this->gotIntro = false; this->skipLagCheck = false; this->joinGameInProgress = false; @@ -1475,9 +1477,14 @@ void ConnectionSlot::close() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("ConnectionSlot::close() #2 this->getSocket() = %p\n",this->getSocket()); + MutexSafeWrapper safeMutex(mutexCloseConnection,CODE_AT_LINE); bool updateServerListener = (this->getSocket() != NULL); + + //printf("ConnectionSlot::close() #3 this->getSocket() = %p updateServerListener = %d\n",this->getSocket(),updateServerListener); + this->deleteSocket(); safeMutex.ReleaseLock(); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 3510578b..1cad2d4a 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -949,7 +949,7 @@ Socket::~Socket() { } void Socket::disconnectSocket() { - //printf("Socket disconnecting\n"); + //printf("Socket disconnecting sock = %d\n",sock); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock); @@ -1511,6 +1511,11 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError // 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()); + + //if(err != dataSize) { + // printf("#1 PEEK err = %d lastSocketError = %d\n",err,lastSocketError); + //} + // } } safeMutex.ReleaseLock(); @@ -1782,7 +1787,9 @@ bool Socket::isConnected() { //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) { + //if(err <= 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN) { + if(err < 0 || (err == 0 && peekDataBytes != 0) || + ((err == 0 || err == -1) && peekDataBytes == 0 && lastSocketError != 0 && lastSocketError != PLATFORM_SOCKET_TRY_AGAIN)) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR Peek failed, err = %d for socket: %d, error = %s, lastSocketError = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,getLastSocketErrorFormattedText().c_str(),lastSocketError); if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] ERROR Peek failed, err = %d for socket: %d, error = %s, lastSocketError = %d\n",__FILE__,__FUNCTION__,__LINE__,err,sock,getLastSocketErrorFormattedText().c_str(),lastSocketError); return false;