From 227f39ccf9dbace6d1089feec1fa07de501632e9 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 11 Jan 2011 20:02:07 +0000 Subject: [PATCH] - bugfixes for connection slot disconnect handling --- source/glest_game/network/connection_slot.cpp | 53 ++++++++++++++----- source/glest_game/network/connection_slot.h | 2 + 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 46db5eed..c938d933 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -89,6 +89,23 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) { //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } +void ConnectionSlotThread::purgeAllEvents() { + MutexSafeWrapper safeMutex(&triggerIdMutex); + eventList.clear(); + safeMutex.ReleaseLock(); +} + +void ConnectionSlotThread::setAllEventsCompleted() { + MutexSafeWrapper safeMutex(&triggerIdMutex); + for(int i = 0; i < eventList.size(); ++i) { + ConnectionSlotEvent &slotEvent = eventList[i]; + if(slotEvent.eventCompleted == false) { + slotEvent.eventCompleted = true; + } + } + safeMutex.ReleaseLock(); +} + void ConnectionSlotThread::purgeCompletedEvents() { MutexSafeWrapper safeMutex(&triggerIdMutex); //event->eventCompleted = true; @@ -158,22 +175,28 @@ void ConnectionSlotThread::execute() { MutexSafeWrapper safeMutex(&triggerIdMutex); int eventCount = eventList.size(); if(eventCount > 0) { - ConnectionSlotEvent *event = NULL; + ConnectionSlotEvent eventCopy; + eventCopy.eventId = -1; for(int i = 0; i < eventList.size(); ++i) { ConnectionSlotEvent &slotEvent = eventList[i]; if(slotEvent.eventCompleted == false) { - event = &slotEvent; + eventCopy = slotEvent; break; } } safeMutex.ReleaseLock(); - if(event != NULL) { + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + + if(eventCopy.eventId > 0) { ExecutingTaskSafeWrapper safeExecutingTaskMutex(this); - this->slotInterface->slotUpdateTask(event); - setTaskCompleted(event->eventId); + this->slotInterface->slotUpdateTask(&eventCopy); + setTaskCompleted(eventCopy.eventId); } } else { @@ -298,6 +321,12 @@ void ConnectionSlot::update(bool checkForNewClients) { this->gotLagCountWarning = false; this->versionString = ""; + //if(this->slotThreadWorker == NULL) { + // this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex); + // this->slotThreadWorker->setUniqueID(__FILE__); + // this->slotThreadWorker->start(); + //} + serverInterface->updateListen(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); } @@ -734,12 +763,11 @@ void ConnectionSlot::validateConnection() { void ConnectionSlot::close() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(BaseThread::shutdownAndWait(slotThreadWorker) == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete slotThreadWorker; + if(this->slotThreadWorker != NULL) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + this->slotThreadWorker->setAllEventsCompleted(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } - slotThreadWorker = NULL; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -770,9 +798,10 @@ Mutex * ConnectionSlot::getServerSynchAccessor() { } void ConnectionSlot::signalUpdate(ConnectionSlotEvent *event) { - assert(slotThreadWorker != NULL); - - slotThreadWorker->signalUpdate(event); + //assert(slotThreadWorker != NULL); + if(slotThreadWorker != NULL) { + slotThreadWorker->signalUpdate(event); + } } bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) { diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index 7c5f6bcd..445be7bd 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -92,6 +92,8 @@ public: int getSlotIndex() const {return slotIndex; } void purgeCompletedEvents(); + void purgeAllEvents(); + void setAllEventsCompleted(); }; // =====================================================