瀏覽代碼

Don't close the server socket while another thread is using it.

Frank Zago 16 年之前
父節點
當前提交
e0c600b963
共有 2 個文件被更改,包括 9 次插入3 次删除
  1. 8 3
      client/Client.cpp
  2. 1 0
      client/Client.h

+ 8 - 3
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<boost::mutex>(*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<CLoadFile> &h, const int version );
-template void CClient::serialize( COSer<CSaveFile> &h, const int version );
+template void CClient::serialize( COSer<CSaveFile> &h, const int version );

+ 1 - 0
client/Client.h

@@ -58,6 +58,7 @@ public:
 	std::set<CCallback*> callbacks; //callbacks given to player interfaces
 	std::map<ui8,CGameInterface *> playerint;
 	CConnection *serv;
+	bool must_close;
 	SharedMem *shared;
 	BattleAction *curbaction;