curl / Mailing Lists / curl-library / Single Mail


Re: curl_multi_perform callback busyloop

From: Daniel Stenberg <>
Date: Sat, 3 Dec 2016 23:56:48 +0100 (CET)

On Fri, 2 Dec 2016, Sergey Naumov wrote:

Please don't top-post. We're discussing many different things at once and it
makes a whole lot of more sense to quote and discuss the specific pieces
inlined one by one.

> I found out today what was the reason here: I had to rerun
> curl_multi_fdset() just after curl_multi_perform() in my callback to check
> whether we need to listen to different set of events.

This doesn't make me any less concerned. What callback are you talking about?
And of course you need to call curl_multi_fdset() if you want to figure out
what fdsets to wait for. Isn't that document or otherwise fairly obvious? What
would you wait for if you don't ask libcurl about it?

> But I still have a couple of questions:
> 1. Is it safe to assume that libcurl uses only 1 sockfd for HTTP? It seems
> to be true, just want to double-check.

No. That's a firm and strong NO. Do not make assumptions like that. HTTP can
(and will) use multiple sockets, depending on situation and build options.

> 2. For some reason when I'm emulating curl_easy_perform by
> curl_multi_perform, the following option no longer works:
> curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
> ...
> qh_curl_easy_perform(curl, &http_code); // <- emulated by multi-perform
> ...
> curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd); // <-- sockfd
> == -1 if emulation with multi-perform enabled
> It looks like CONNECT_ONLY option actually works and nothing is done except
> of connection establishmend / reusage, but sockfd is not available.

Without more details, like a source code that can be used to reproduce this,
it is really hard to tell why this happens. Could be a perfectly sensible
explanation, could be a bug. In your code or in libcurl.

> Right now I'm testing with curl-7.47.1, but planning to use any library
> since 7.25.0. Is there some way to make multi-perform not to close
> connection, or is it a bug and better just to force easy mode in this case?

They do the same things. The curl_easy_perform() function is itself just a
wrapper around the multi interface API.

I couldn't find any obvious bug fix in this area that has happened since
7.47.1 that would indicate that your problem might be different in the latest
version, but I would still urge you to try out the latest version first before
you dig too deep into this. And help us reproduce it so that we can
investigate a little from our ends!

List admin:
Received on 2016-12-03