From: James Turner Date: Wed, 8 Jun 2016 14:43:59 +0000 (+0100) Subject: Fix for HTTP/curl waiting on update X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=84e5142195f5d3b2bf40b11119991457d7f8558b;p=simgear.git Fix for HTTP/curl waiting on update This improves responsiveness of TerraSync with small files and general throughout dramatically. --- diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 2e3192f6..bc0a84fe 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -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) diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index bc8b14ac..56aa2cc8 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -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()); }