Browse Source

线程控制重连webserver

chensongchao 6 years ago
parent
commit
546972b2e6
2 changed files with 9 additions and 3 deletions
  1. 6 2
      websocket/web_connect.cpp
  2. 3 1
      websocket/wsClientMgr.cpp

+ 6 - 2
websocket/web_connect.cpp

@@ -2,6 +2,7 @@
 
 #include<thread>
 #include<chrono>
+#include <tool_time.h>
 
 #include"log.h"
 #include"wsClientMgr.h"
@@ -67,7 +68,10 @@ void web_connect::_beatheart_thread()
     while (true)
     {
         std::this_thread::sleep_for(std::chrono::seconds(3));
-        if(_beatheart_count==0)//一次都没收到web的心跳信号
+
+        swsClientMgr.CheckClientConnect(tool_time::now_to_seconds());
+
+        /*if(_beatheart_count==0)//一次都没收到web的心跳信号
         {
             log_info("没有收到web心跳信号");
             continue;
@@ -99,6 +103,6 @@ void web_connect::_beatheart_thread()
                 log_info("重连web ok");
                 break;
             }
-        }
+        }*/
     }
 }

+ 3 - 1
websocket/wsClientMgr.cpp

@@ -166,11 +166,12 @@ namespace YA
     {
 		if (nullptr != ws)
 		{
+			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());
 			}
-			log_info("wsClinet Reconnect : id[%d],url[%s]", ws->GetID(), ws->get_uri().c_str());
 		}
     }
 
@@ -197,6 +198,7 @@ namespace YA
 			}
 			//重连
 			Disconnet(w);
+			std::this_thread::sleep_for(std::chrono::seconds(1));
 			Reconnect(w);
 		}
 	}