Browse Source

线程控制重连,记录ping值

chensongchao 6 years ago
parent
commit
76c2af1719
3 changed files with 7 additions and 5 deletions
  1. 3 2
      websocket/wsClient.cpp
  2. 3 2
      websocket/wsClient.h
  3. 1 1
      websocket/wsClientMgr.cpp

+ 3 - 2
websocket/wsClient.cpp

@@ -85,8 +85,9 @@ namespace YA
 			}
 			else
 			{
-				__connet_time = tool_time::now_to_seconds();
-				__recv_ping_time = __connet_time;
+			    unsigned int cur_time = tool_time::now_to_seconds();
+				__connet_time = cur_time;
+				__recv_ping_time = cur_time;
 				nRet = 0;
 			}
 		}

+ 3 - 2
websocket/wsClient.h

@@ -26,6 +26,7 @@ websocket客户端类
 #include <mutex>
 #include <condition_variable>
 #include <map>
+#include<atomic>
 
 #include <rapidjson/writer.h>
 #include <rapidjson/stringbuffer.h>
@@ -57,8 +58,8 @@ namespace YA
 		std::map<std::string, MSG_HANDLE_FUNC_TYPE> __MsgFuncList;//消息处理函数列表(key是命令,value是处理函数)
 		std::recursive_mutex __send_lock;//发送锁
 		jsonBuilder __jsBuilder;//json构造器
-		unsigned int __connet_time;		//连接时间
-		unsigned int __recv_ping_time;	//接受ping消息的时间
+		std::atomic<unsigned int> __connet_time;		//连接时间
+		std::atomic<unsigned int> __recv_ping_time;	//接受ping消息的时间
 	protected:
 		/**
 		* @brief		重置状态函数。

+ 1 - 1
websocket/wsClientMgr.cpp

@@ -201,7 +201,7 @@ namespace YA
 			}
 			//重连
 			Disconnet(w);
-			std::this_thread::sleep_for(std::chrono::seconds(1));
+			std::this_thread::sleep_for(std::chrono::milliseconds(10));
 			Reconnect(w);
 		}
 	}