From 57c7d58f793d031b6c88686d1413c7750b7222d2 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 7 Aug 2020 17:47:34 +0100 Subject: [PATCH] HTTP: Use curl_multi_wait everywhere Also check the result of the curl methods, in case they fail --- simgear/io/HTTPClient.cxx | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 66c0f578..6578befa 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -183,32 +183,22 @@ void Client::update(int waitTimeout) } int remainingActive, messagesInQueue; -#if defined(SG_MAC) - // Mac 10.8 libCurl lacks this, let's keep compat for now - fd_set curlReadFDs, curlWriteFDs, curlErrorFDs; - int maxFD; - curl_multi_fdset(d->curlMulti, - &curlReadFDs, - &curlWriteFDs, - &curlErrorFDs, - &maxFD); - - struct timeval timeout; - long t; - - curl_multi_timeout(d->curlMulti, &t); - if ((t < 0) || (t > waitTimeout)) { - t = waitTimeout; + int numFds; + CURLMcode mc = curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds); + if (mc != CURLM_OK) { + SG_LOG(SG_IO, SG_WARN, "curl_multi_wait failed:" << curl_multi_strerror(mc)); + return; } - timeout.tv_sec = t / 1000; - timeout.tv_usec = (t % 1000) * 1000; - ::select(maxFD, &curlReadFDs, &curlWriteFDs, &curlErrorFDs, &timeout); -#else - int numFds; - curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds); -#endif - curl_multi_perform(d->curlMulti, &remainingActive); + mc = curl_multi_perform(d->curlMulti, &remainingActive); + if (mc == CURLM_CALL_MULTI_PERFORM) { + // we could loop here, but don't want to get blocked + // also this shouldn't ocurr in any modern libCurl + curl_multi_perform(d->curlMulti, &remainingActive); + } else if (mc != CURLM_OK) { + SG_LOG(SG_IO, SG_WARN, "curl_multi_perform failed:" << curl_multi_strerror(mc)); + return; + } CURLMsg* msg; while ((msg = curl_multi_info_read(d->curlMulti, &messagesInQueue))) {