curl / Mailing Lists / curl-library / Single Mail


Re: max_fd if curl_multi_fdset() is called directly after curl_multi_add_handle()

From: Daniel Stenberg <>
Date: Wed, 8 Nov 2017 14:37:31 +0100 (CET)

On Wed, 8 Nov 2017, Wolfgang Steinwender wrote:

> Documentation for curl_multi_fdset:
> When libcurl returns -1 in max_fd [..]
> You then need to wait a while before you proceed and call curl_multi_perform
> anyway. How long to wait? We suggest 100 milliseconds at least [..]
> But: If i call curl_multi_fdset() directly after curl_multi_add_handle(),
> max_fd is always -1. If I wait 100ms in this case, start of the transfer is
> delayed by 100ms. I don't think that is required.

You're right.

Maybe we should improve how that is explained. When you figure out what file
descriptors to wait for, you should also ask libcurl for the *maximum* time to
wait. curl_multi_timeout() tells you that.

In this case, when you have just called curl_multi_add_handle(),
curl_multi_timeout() will return saying you shouldn't wait at all but you
should call libcurl immediately as it has things to do. In this moment in
time, the -1 value in max_fd is less of a concern.

> In the examples I can see after curl_multi_add_handle(): /* we start some
> action by calling perform right away */ curl_multi_perform(multi_handle,
> &still_running);
> Is this always required after curl_multi_add_handle()?

Well, you can assume that after you add a handle there will be "things to do"
for libcurl so calling it right away might not be documented but I would say
that it seems like a pretty logical next step.

> A solution could be that curl_multi_fdset() returns max_fd = 0 directly
> after curl_multi_add_handle().

No. curl_multi_fdset() returns information about what file descriptors to wait
on, and immediately after you've called curl_multi_add_handle() there is no
file descriptor to wait for so it MUST return -1 there.

Received on 2017-11-08