]> git.mxchange.org Git - simgear.git/commitdiff
Fix for HTTP/curl waiting on update
authorJames Turner <zakalawe@mac.com>
Wed, 8 Jun 2016 14:43:59 +0000 (15:43 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
This improves responsiveness of TerraSync with small files and general
throughout dramatically.

simgear/io/HTTPClient.cxx
simgear/scene/tsync/terrasync.cxx

index 2e3192f6ff4fba49a1fe0fa3e71ed893aeb62017..bc0a84fec591f22573b863a7e9a2ff93ea94b00e 100644 (file)
@@ -161,7 +161,15 @@ void Client::setMaxPipelineDepth(unsigned int depth)
 
 void Client::update(int waitTimeout)
 {
-    int remainingActive, messagesInQueue;
+    if (d->requests.empty()) {
+        // curl_multi_wait returns immediately if there's no requests active,
+        // but that can cause high CPU usage for us.
+        SGTimeStamp::sleepForMSec(waitTimeout);
+        return;
+    }
+
+    int remainingActive, messagesInQueue, numFds;
+    curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds);
     curl_multi_perform(d->curlMulti, &remainingActive);
 
     CURLMsg* msg;
@@ -202,7 +210,6 @@ void Client::update(int waitTimeout)
           SG_LOG(SG_IO, SG_ALERT, "unknown CurlMSG:" << msg->msg);
       }
     } // of curl message processing loop
-    SGTimeStamp::sleepForMSec(waitTimeout);
 }
 
 void Client::makeRequest(const Request_ptr& r)
index bc8b14ac23f51a34a78dc40b5976c2687f08daea..56aa2cc870ac4f5f4e231d2b4dc785a780cb848f 100644 (file)
@@ -570,7 +570,7 @@ void SGTerraSync::WorkerThread::runInternal()
 {
     while (!_stop) {
         try {
-            _http.update(100);
+            _http.update(10);
         } catch (sg_exception& e) {
             SG_LOG(SG_TERRASYNC, SG_WARN, "failure doing HTTP update" << e.getFormattedMessage());
         }