curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Problem where timer callback keeps setting a 0 timer

From: Sean Burford via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 4 Dec 2019 16:03:18 +1100

Hi,

On Wed, Dec 4, 2019 at 3:37 PM Jeff Mears via curl-library <
curl-library_at_cool.haxx.se> wrote:

> I have a background thread that starts and stops libcurl downloads using
> the "multi" interface. It has a poll() loop that waits for something to
> happen on either one of libcurl's sockets or on a loopback socket that is
> used to interrupt poll().
>
> After running for a bit, there is a periodic HTTP request we send. When
> these start, libcurl calls our CURLMOPT_TIMERFUNCTION with a timeout of 0.
> So the poll() loop starts polling with hot CPU.
>

Reading the man page
<https://curl.haxx.se/libcurl/c/CURLMOPT_TIMERFUNCTION.html>, it looks like
calls to the timer function request a single shot timer. Your description
makes it sound like you set up a periodic timer that fires every timeout_ms
milliseconds. It shouldn't be necessary for curl to provide a -1
cancellation because the timer was meant to be a single shot, it's only
specified to fire once.

The example on the man page may be a source of confusion. The example uses
g_timeout_add() to set up a periodic timer that is cancelled when the timer
callback returns false. However the example timer callback always returns
false, making this a single shot timer. If you didn't notice the timer
callback return value (at the end of timeout_cb in the example) you might
assume that the timer is meant to be periodic.

The download then completes. We curl_multi_remove_handle() then
> curl_easy_cleanup() in our handling of the curl_multi_info_read() messages.
>
> However, at this point, even though libcurl has no active downloads on the
> multi handle, we never get a timer callback to set the timeout back to -1,
> so our poll() loop continues running hot.
>
> Am I doing something wrong? For now, I'm going to set the timeout to -1
> when curl_multi_socket_action(CURL_SOCKET_TIMEOUT) returns 0 running
> handles to stop the thread running hot.
>

Thanks,
Sean

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-12-04