curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_add_handle and subsequent timer

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 13 Nov 2017 08:26:26 +0100 (CET)

On Mon, 13 Nov 2017, Maksim Dmitrichenko via curl-library wrote:

> I've noticed that call to curl_multi_add_handle() triggers appropriate timer
> function callback with timeout of 1 ms.

The timeout is actually at 0ms these days.

> Only after that timeout added easy handle starts to perform.

That's not really how libcurl works. The timeout is the maximum time you
should wait until you call a libcurl perform function to avoid that it delays
some operation. You can always - at your choice - decide to call libcurl
earlier or later than the timeout suggests.

The timeout value is the shortest time until there's a scheduled internal
activity for libcurl to do.

> The question is: why we need this timeout at all and if there is any way to
> skip this step and execute the handle immediately?

Sure!

The timeout that is set when you add a handle is there to make sure users
don't do go waiting around for something they call the perform function -
because libcurl is ready and has work already at that point. You can thus skip
the waiting and call libcurl right away if you want to, and libcurl will then
update the timeout value according to what it was able to do in this call.

libcurl has to set the timeout since you might already be running transfers
with N other handles so adding another handle to the mix needs to make sure
that the timeout expires "now" so that the new handle's transfer gets kicked
off properly.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2017-11-13