Browse Source

Z991239-1017 #comment fea Detect url出错,加入异常

陈良瑜80374463 4 years ago
parent
commit
a9481c70db
2 changed files with 33 additions and 24 deletions
  1. 31 24
      Module/mod_chromium/CSocketClient.cpp
  2. 2 0
      ThirdParty/Include/requests/requests/Url.cpp

+ 31 - 24
Module/mod_chromium/CSocketClient.cpp

@@ -24,37 +24,44 @@ bool checkHttpThreadFun(const std::string url) {
 
 std::pair<bool, std::string> DetectActiveHttp(std::vector<std::string> urlArr)
 {
-	std::vector<boost::shared_future<bool>> threadArr;
+	try {
+		std::vector<boost::shared_future<bool>> threadArr;
 
-	for (const auto it : urlArr)
-		threadArr.push_back(boost::async(boost::bind(checkHttpThreadFun, it)));
+		for (const auto it : urlArr)
+			threadArr.push_back(boost::async(boost::bind(checkHttpThreadFun, it)));
 
-	boost::this_thread::sleep_for(boost::chrono::seconds(1));
-	//boost::wait_for_any(threadArr.begin(), threadArr.end());
-	std::vector<std::string> vaildArr;
-	for (size_t i = 0; i < threadArr.size(); i++)
-	{
-		if (threadArr[i].is_ready())
+		boost::this_thread::sleep_for(boost::chrono::seconds(1));
+		//boost::wait_for_any(threadArr.begin(), threadArr.end());
+		std::vector<std::string> vaildArr;
+		for (size_t i = 0; i < threadArr.size(); i++)
 		{
-			DbgEx("Detect url %s %s", urlArr[i].c_str(), threadArr[i].get() ? "sucess" : "failed");
-			if (threadArr[i].get())
-				vaildArr.push_back(urlArr[i]);
+			if (threadArr[i].is_ready())
+			{
+				DbgEx("Detect url %s %s", urlArr[i].c_str(), threadArr[i].get() ? "sucess" : "failed");
+				if (threadArr[i].get())
+					vaildArr.push_back(urlArr[i]);
+			}
+
+			else
+				DbgEx("Detect url %s timeout", urlArr[i].c_str());
 		}
-			
-		else
-			DbgEx("Detect url %s timeout", urlArr[i].c_str());
-	}
-	
 
-	if (vaildArr.size() > 0)
-	{
-		boost::mt19937 rng(time(0));
-		boost::uniform_int<>  rdgen(0, vaildArr.size() - 1);
-		auto pos = rdgen(rng);
-		return std::make_pair(true, vaildArr[pos]);//随机数
+
+		if (vaildArr.size() > 0)
+		{
+			boost::mt19937 rng(time(0));
+			boost::uniform_int<>  rdgen(0, vaildArr.size() - 1);
+			auto pos = rdgen(rng);
+			return std::make_pair(true, vaildArr[pos]);//随机数
+		}
+		else
+			return std::make_pair(false, "");
 	}
-	else
+	catch(std::exception &e){
+		DbgEx("DetectActiveHttp exception, %s", e.what());
 		return std::make_pair(false, "");
+	}
+	
 }
 
 namespace Chromium{

+ 2 - 0
ThirdParty/Include/requests/requests/Url.cpp

@@ -41,6 +41,8 @@ Url::Url(const String &url)
         {
             queries_ = std::move(pathQueries[0]);
         }
+        else if (pathQueries.size() == 0)
+            return;
         else
         {
             path_.append(pathQueries[0]);