HTTP: Use curl_multi_wait everywhere

Also check the result of the curl methods, in case they fail
This commit is contained in:
James Turner 2020-08-07 17:47:34 +01:00 committed by Automatic Release Builder
parent ab8795f6dc
commit d0f24229b2

View File

@ -183,32 +183,22 @@ void Client::update(int waitTimeout)
} }
int remainingActive, messagesInQueue; int remainingActive, messagesInQueue;
#if defined(SG_MAC) int numFds;
// Mac 10.8 libCurl lacks this, let's keep compat for now CURLMcode mc = curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds);
fd_set curlReadFDs, curlWriteFDs, curlErrorFDs; if (mc != CURLM_OK) {
int maxFD; SG_LOG(SG_IO, SG_WARN, "curl_multi_wait failed:" << curl_multi_strerror(mc));
curl_multi_fdset(d->curlMulti, return;
&curlReadFDs,
&curlWriteFDs,
&curlErrorFDs,
&maxFD);
struct timeval timeout;
long t;
curl_multi_timeout(d->curlMulti, &t);
if ((t < 0) || (t > waitTimeout)) {
t = waitTimeout;
} }
timeout.tv_sec = t / 1000; mc = curl_multi_perform(d->curlMulti, &remainingActive);
timeout.tv_usec = (t % 1000) * 1000; if (mc == CURLM_CALL_MULTI_PERFORM) {
::select(maxFD, &curlReadFDs, &curlWriteFDs, &curlErrorFDs, &timeout); // we could loop here, but don't want to get blocked
#else // also this shouldn't ocurr in any modern libCurl
int numFds;
curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds);
#endif
curl_multi_perform(d->curlMulti, &remainingActive); 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; CURLMsg* msg;
while ((msg = curl_multi_info_read(d->curlMulti, &messagesInQueue))) { while ((msg = curl_multi_info_read(d->curlMulti, &messagesInQueue))) {