From 03862948e218fb1bfd4591cd12f2262a785d51be Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 4 Jun 2013 03:47:04 +0000 Subject: [PATCH] bugfix to cleanup closing client connections quickly --- source/glest_game/network/connection_slot.cpp | 24 ++++++++++++------- .../glest_game/network/server_interface.cpp | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 6b7e808a..c0b30e55 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -457,8 +457,11 @@ ConnectionSlot::~ConnectionSlot() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //printf("#1 Ending client SLOT: %d slotThreadWorker: %p\n",playerIndex,slotThreadWorker); - - if(slotThreadWorker != NULL && slotThreadWorker->getRunningStatus() == false) { + if(slotThreadWorker != NULL) { + slotThreadWorker->signalQuit(); + } + if(slotThreadWorker != NULL && slotThreadWorker->canShutdown(false) == true && + slotThreadWorker->getRunningStatus() == false) { //printf("#2 Ending client SLOT: %d\n",playerIndex); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -466,12 +469,17 @@ ConnectionSlot::~ConnectionSlot() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //else if(BaseThread::shutdownAndWait(slotThreadWorker) == true) { - if(slotThreadWorker != NULL && slotThreadWorker->canShutdown(true) == true) { - //printf("#3 Ending client SLOT: %d\n",playerIndex); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete slotThreadWorker; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + else if(slotThreadWorker != NULL && slotThreadWorker->canShutdown(true) == true) { + if(slotThreadWorker->getRunningStatus() == false) { + //printf("#3 Ending client SLOT: %d\n",playerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + delete slotThreadWorker; + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + else { + slotThreadWorker->setDeleteSelfOnExecutionDone(true); + slotThreadWorker->setDeleteAfterExecute(true); + } } //printf("#4 Ending client SLOT: %d\n",playerIndex); slotThreadWorker = NULL; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 23bf31ec..8536f17c 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -478,6 +478,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { safeMutexSlot.ReleaseLock(); safeMutex.ReleaseLock(); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(slot != NULL) slot->close(); delete slot; if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); updateListen();