Browse Source

线程控制重连webserver

chensongchao 6 years ago
parent
commit
bd529388b0

+ 7 - 7
websocket/web_connect.cpp

@@ -14,11 +14,11 @@ web_connect::web_connect()
 {
 }
 
-std::atomic<int> web_connect::_beatheart_count;
+//std::atomic<int> web_connect::_beatheart_count;
 
 void web_connect::init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
 {
-    MsgFuncList.insert( std::make_pair( "beatheart", &web_connect::_beatheart_callback ) );
+    //MsgFuncList.insert( std::make_pair( "beatheart", &web_connect::_beatheart_callback ) );
 
     swsClientMgr.Build( uri_list, MsgFuncList );
 
@@ -57,11 +57,11 @@ bool web_connect::connect()
     return true;
 }
 
-void web_connect::_beatheart_callback( int ID, std::string const& name,
-                    sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
-{
-    _beatheart_count=BEATHEART_COUNT_NUM;
-}
+//void web_connect::_beatheart_callback( int ID, std::string const& name,
+//                    sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
+//{
+//    _beatheart_count=BEATHEART_COUNT_NUM;
+//}
 
 void web_connect::_beatheart_thread()
 {

+ 2 - 3
websocket/web_connect.h

@@ -23,12 +23,11 @@ public:
     static void close();
 
 private:
-    static void _beatheart_callback( int ID, std::string const& name,
-                           sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
+    //static void _beatheart_callback( int ID, std::string const& name,sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
 
     static void _beatheart_thread();
 
-    static std::atomic<int> _beatheart_count;
+    //static std::atomic<int> _beatheart_count;
 };
 
 #endif // WEB_CONNECT_H

+ 2 - 2
websocket/wsClient.cpp

@@ -20,7 +20,7 @@ namespace YA
 
 	wsClient::~wsClient()
 	{
-
+		__wsclient.sync_close();
 	}
 
 	
@@ -253,7 +253,7 @@ namespace YA
 
 	void wsClient::close()
 	{
-		__wsclient.sync_close();
+		__wsclient.close();
 	}
 
 	std::string wsClient::GetLastError()

+ 7 - 4
websocket/wsClientMgr.cpp

@@ -1,5 +1,6 @@
 #include "wsClientMgr.h"
 #include "log.h"
+#include<thread>
 
 namespace YA
 {
@@ -166,11 +167,13 @@ namespace YA
     {
 		if (nullptr != ws)
 		{
+//			std_info("wsClinet Reconnect : id[%d],url[%s]", ws->GetID(), ws->get_uri().c_str());
 			log_info("wsClinet Reconnect : id[%d],url[%s]", ws->GetID(), ws->get_uri().c_str());
 			if (ws->connect() == 0)
 			{
 				ws->login();
 				log_info("wsClinet Reconnect : id[%d],url[%s] Success.", ws->GetID(), ws->get_uri().c_str());
+//				std_info("wsClinet Reconnect : id[%d],url[%s] Success.", ws->GetID(), ws->get_uri().c_str());
 			}
 		}
     }
@@ -184,15 +187,15 @@ namespace YA
     }
 
     // @brief 检测是否有连接断开,并重连
-	void wsClientMgr::CheckClientConnect(uint32 cur_time)
+	void wsClientMgr::CheckClientConnect(unsigned int cur_time)
 	{
 		std::lock_guard<std::recursive_mutex> lock( __lock );
 
 		for( std::shared_ptr<wsClient>& w : __wsClientList)
 		{
-			uint32 t = w->GetPingTime();
-			// 间隔小于10秒 认为是正常
-			if (w->IsConnected() && (t == 0 || cur_time - t < 10))
+			unsigned int t = w->GetPingTime();
+			// 间隔小于15秒 认为是正常
+			if (w->IsConnected() && (t == 0 || cur_time - t < 15))
 			{
 				continue;
 			}

+ 1 - 1
websocket/wsClientMgr.h

@@ -127,7 +127,7 @@ namespace YA
         * @brief 检测是否有连接断开,并重连
         * @param  [in] cur_time : 当前时刻 (秒)
         */
-        void CheckClientConnect(uint32 cur_time);
+        void CheckClientConnect(unsigned int cur_time);
 
 	private:
 		/**