From 6acf5e9e673abf7aadf7c79ec45485ec6069aa69 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 29 Jan 2013 00:10:27 +0000 Subject: [PATCH] - attempt to fix ftpclient error on shutdown shown by nig --- .../menu/menu_state_connected_game.cpp | 113 +++++++++++++++--- source/glest_game/menu/menu_state_mods.cpp | 36 ++++-- 2 files changed, 121 insertions(+), 28 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 08a13ec8..a40c1121 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -697,11 +697,30 @@ MenuStateConnectedGame::~MenuStateConnectedGame() { } if(ftpClientThread != NULL) { - ftpClientThread->setCallBackObject(NULL); - if(ftpClientThread->shutdownAndWait() == true) { - delete ftpClientThread; - ftpClientThread = NULL; - } + ftpClientThread->setCallBackObject(NULL); + ftpClientThread->signalQuit(); + sleep(0); + if(ftpClientThread->canShutdown(true) == true && + ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s %d] Error cannot shutdown ftpClientThread\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + //publishToMasterserverThread->cleanup(); + } + + ftpClientThread = NULL; + +// ftpClientThread->setCallBackObject(NULL); +// if(ftpClientThread->shutdownAndWait() == true) { +// delete ftpClientThread; +// ftpClientThread = NULL; +// } } cleanupMapPreviewTexture(); @@ -1243,10 +1262,29 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ } else if(buttonCancelDownloads.mouseClick(x,y)) { if(ftpClientThread != NULL && fileFTPProgressList.empty() == false) { - ftpClientThread->setCallBackObject(NULL); - if(ftpClientThread->shutdownAndWait() == true) { - delete ftpClientThread; - } + + ftpClientThread->setCallBackObject(NULL); + ftpClientThread->signalQuit(); + sleep(0); + if(ftpClientThread->canShutdown(true) == true && + ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s %d] Error cannot shutdown ftpClientThread\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + //publishToMasterserverThread->cleanup(); + } + ftpClientThread = NULL; + +// ftpClientThread->setCallBackObject(NULL); +// if(ftpClientThread->shutdownAndWait() == true) { +// delete ftpClientThread; +// } fileFTPProgressList.clear(); getMissingMapFromFTPServerInProgress = false; @@ -2142,11 +2180,30 @@ void MenuStateConnectedGame::returnToJoinMenu() { } if(ftpClientThread != NULL) { - ftpClientThread->setCallBackObject(NULL); - if(ftpClientThread->shutdownAndWait() == true) { - delete ftpClientThread; - ftpClientThread = NULL; - } + + ftpClientThread->setCallBackObject(NULL); + ftpClientThread->signalQuit(); + sleep(0); + if(ftpClientThread->canShutdown(true) == true && + ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s %d] Error cannot shutdown ftpClientThread\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + //publishToMasterserverThread->cleanup(); + } + ftpClientThread = NULL; + +// ftpClientThread->setCallBackObject(NULL); +// if(ftpClientThread->shutdownAndWait() == true) { +// delete ftpClientThread; +// ftpClientThread = NULL; +// } } if(returnMenuInfo == jmSimple) { @@ -3089,11 +3146,29 @@ void MenuStateConnectedGame::update() { } if(ftpClientThread != NULL) { - ftpClientThread->setCallBackObject(NULL); - if(ftpClientThread->shutdownAndWait() == true) { - delete ftpClientThread; - ftpClientThread = NULL; - } + ftpClientThread->setCallBackObject(NULL); + ftpClientThread->signalQuit(); + sleep(0); + if(ftpClientThread->canShutdown(true) == true && + ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s %d] Error cannot shutdown ftpClientThread\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + //publishToMasterserverThread->cleanup(); + } + ftpClientThread = NULL; + +// ftpClientThread->setCallBackObject(NULL); +// if(ftpClientThread->shutdownAndWait() == true) { +// delete ftpClientThread; +// ftpClientThread = NULL; +// } } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index bdf6314f..9fc3b858 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -1135,15 +1135,33 @@ void MenuStateMods::cleanUp() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(ftpClientThread != NULL) { - ftpClientThread->signalQuit(); - ftpClientThread->setCallBackObject(NULL); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - if( ftpClientThread->shutdownAndWait() == true) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete ftpClientThread; - } - ftpClientThread = NULL; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + ftpClientThread->setCallBackObject(NULL); + ftpClientThread->signalQuit(); + sleep(0); + if(ftpClientThread->canShutdown(true) == true && + ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s %d] Error cannot shutdown ftpClientThread\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + //publishToMasterserverThread->cleanup(); + } + ftpClientThread = NULL; + +// ftpClientThread->signalQuit(); +// ftpClientThread->setCallBackObject(NULL); +// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); +// if( ftpClientThread->shutdownAndWait() == true) { +// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); +// delete ftpClientThread; +// } +// ftpClientThread = NULL; +// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);