From e0c600b963b6bebd0e15d8c932552ba1e0f8db5f Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Sat, 6 Jun 2009 15:17:07 +0000 Subject: [PATCH] Don't close the server socket while another thread is using it. --- client/Client.cpp | 11 ++++++++--- client/Client.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/Client.cpp b/client/Client.cpp index 4b9ae3a40..12fe82460 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -87,6 +87,7 @@ void CClient::init() serv = NULL; gs = NULL; cb = NULL; + must_close = false; try { shared = new SharedMem(); @@ -124,6 +125,11 @@ void CClient::run() CPack *pack; while(1) { + if (must_close) { + serv->close(); + tlog3 << "Our socket has been closed.\n"; + return; + } //get the package from the server { @@ -162,8 +168,7 @@ void CClient::close() boost::unique_lock(*serv->wmx); *serv << &CloseServer(); tlog3 << "Sent closing signal to the server\n"; - serv->close(); - tlog3 << "Our socket has been closed.\n"; + must_close = true; } void CClient::save(const std::string & fname) @@ -399,4 +404,4 @@ void CClient::serialize( Handler &h, const int version ) } template void CClient::serialize( CISer &h, const int version ); -template void CClient::serialize( COSer &h, const int version ); \ No newline at end of file +template void CClient::serialize( COSer &h, const int version ); diff --git a/client/Client.h b/client/Client.h index 12ad80e7c..07c76825a 100644 --- a/client/Client.h +++ b/client/Client.h @@ -58,6 +58,7 @@ public: std::set callbacks; //callbacks given to player interfaces std::map playerint; CConnection *serv; + bool must_close; SharedMem *shared; BattleAction *curbaction;