cURL / Mailing Lists / curl-library / Single Mail


Re: CURLM Chain of events

From: Daniel Stenberg <>
Date: Sat, 23 Jan 2016 00:04:04 +0100 (CET)

On Fri, 22 Jan 2016, surf via curl-library wrote:

>> You can add and remove easy handles as you see fit and libcurl will update
>> your socket and timer callbacks accordingly.
> Pardon my ignorance, putting aside internal implementation details why do I
> need to explicitly call curl_multi_socket_action(curl_m_handle,
> CURL_SOCKET_TIMEOUT right after curl_multi_add_handle in order to kick start
> the library and not when adding or removing easy handles afterwards. Is
> there a design motivation here or is that just how it currently works?

Because when you add a handle "in run-time", you're already running timeouts
and you're acting on socket activity, so when you add a new handle it'll add a
new internal timeout expiry to trigger in one millisecond so the next call
you'd do to libcurl it will get the new transfer going.

But yes, you might actually get the new transfer to take off slightly faster
if you call curl_multi_socket_action(CURL_SOCKET_TIMEOUT) right after

> Same question with respect to the timeout_callback. It seems like I'm
> supposed to install a non-repeating timer for the sole purpose of calling
> curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...).


> Why doesn't libcurl handle this internally. Is it a design goal to
> externalize the timer to allow support for different timer implementations ?

Well, primarly it is because libcurl can't handle it internally since it runs
in the same thread as the event loop and your application owns and runs that.
When the application code runs, libcurl doesn't run anything.

And yes also since you own and run the event loop you can select whichever
implementation you like.

>> (The book is still work in progress so all kinds of feedback is
>> appreciated)
> Where would be an appropriate place to post feedback?

Either here on the mailing list, or if you rather prefer it, you can submit
issues or pull-requests in the dedicated book github repo:

List admin:
Received on 2016-01-23