From a05760d2a4654607cac9e2cf6be246a80f87a042 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 22 Jun 2010 15:03:57 +0000 Subject: [PATCH] - threading bugfixes from the client join menu --- source/glest_game/menu/menu_state_join_game.cpp | 12 +++++++++--- source/glest_game/menu/menu_state_join_game.h | 1 + .../shared_lib/sources/platform/posix/socket.cpp | 15 ++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index dc322993c..c89bff1c3 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -45,13 +45,14 @@ const string MenuStateJoinGame::serverFileName= "servers.ini"; MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect, Ip serverIp): MenuState(program, mainMenu, "join-game") { + abortAutoFind = false; + autoConnectToServer = false; Lang &lang= Lang::getInstance(); Config &config= Config::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); networkManager.end(); networkManager.init(nrClient); - abortAutoFind = false; - + serversSavedFile = serverFileName; if(getGameReadWritePath() != "") { serversSavedFile = getGameReadWritePath() + serversSavedFile; @@ -147,6 +148,7 @@ void MenuStateJoinGame::DiscoveredServers(std::vector serverList) { //serverList.push_back("test2"); // + autoConnectToServer = false; buttonAutoFindServers.setEnabled(true); if(serverList.size() > 0) { string bestIPMatch = ""; @@ -167,7 +169,7 @@ void MenuStateJoinGame::DiscoveredServers(std::vector serverList) { listBoxFoundServers.setItems(serverList); } else { - connectToServer(); + autoConnectToServer = true; } } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -431,6 +433,10 @@ void MenuStateJoinGame::update() //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } + else if(autoConnectToServer == true) { + autoConnectToServer = false; + connectToServer(); + } if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); } diff --git a/source/glest_game/menu/menu_state_join_game.h b/source/glest_game/menu/menu_state_join_game.h index cdb4cc6e3..de9bea0b6 100644 --- a/source/glest_game/menu/menu_state_join_game.h +++ b/source/glest_game/menu/menu_state_join_game.h @@ -60,6 +60,7 @@ private: string serversSavedFile; bool abortAutoFind; + bool autoConnectToServer; public: MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect= false, Ip serverIp= Ip()); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index cc3e22475..649f4900a 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1202,11 +1202,9 @@ void ClientSocket::stopBroadCastClientThread() { if(broadCastClientThread != NULL) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - BaseThread::shutdownAndWait(broadCastClientThread); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete broadCastClientThread; broadCastClientThread = NULL; + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1446,14 +1444,15 @@ void BroadCastClientSocketThread::execute() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast Client thread is exiting\n"); - // Here we callback into the implementer class if(discoveredServersCB != NULL) { discoveredServersCB->DiscoveredServers(foundServers); } + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast Client thread is exiting\n"); + setRunningStatus(false); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -1482,11 +1481,9 @@ void ServerSocket::stopBroadCastThread() { if(broadCastThread != NULL) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - BaseThread::shutdownAndWait(broadCastThread); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete broadCastThread; broadCastThread = NULL; + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);