cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLMOPT_TIMERFUNCTION

From: Joshua Kwan <jkwan_at_vmware.com>
Date: Fri, 11 Sep 2009 13:26:35 -0700

Hi Joe,

On 9/11/09 12:50, "Joe Eggleston" <joe_at_arbor.net> wrote:
> My questions:
> 1. Is it safe to assume that curl will only schedule one timeout at a
> time? So, if the callback is called with a positive timeout request, I
> can safely delete/replace any previously scheduled pending timeout?

This is correct.

> 2. Does curl expect timeouts to be persistent? I.e., if the timeout
> occurs, should a new timeout be scheduled using the previously
> specified timeout value? Or, can I assume that curl will call the
> callback to explicitly schedule a new timeout?

Let cURL take care of it. For example, if there's no pending transfers,
there's no need for a timeout.

> 3. What's the difference in behavior between timeouts of 0 and -1? I
> assume that -1 means I should delete any scheduled timeout. Does 0
> imply the same, but in addition I should call
> curl_multi_socket_action() with CURL_SOCKET_TIMEOUT? If so, why
> wouldn't curl just handle this internally?

I'm not sure about this myself. My code does this (and I'm not sure if it's
strictly correct, but it works for me:)

   if (milliseconds == 0) {
      /* If cURL wants to be called immediately, make it so. */
      CurlTimerCallback(myState);
      return 0;
   } else if (milliseconds == -1) {
      /* If cURL doesn't specify an explicit timeout use a sane one. */
      milliseconds = DEFAULT_TIMEOUT_MS;
   }

/* set the timer for 'milliseconds' time */

-- 
Joshua Kwan
Received on 2009-09-11