cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Setting individual timeouts while using curl multi API.

From: <koettermarkus_at_gmx.de>
Date: Tue, 18 Aug 2009 06:16:12 +0200

Daniel Stenberg wrote:
> On Tue, 21 Jul 2009, Pranav O. Sharma wrote:
>
>> Everything works fine when the remote server sends a response within a
>> given time interval. However, I want to set timeouts so that we don't
>> end up waiting forever. I tried setting timeouts using
>> CURLOPT_TIMEOUT_MS and CURLOPT_CONNECTTIMEOUT in each easy handle.
>
> This inability is documented in KNOWN_BUGS as problem #62.

I've had the same problem, and thats what I got:

  * if an easy has a CURLOPT_TIMEOUT*, there is an splay node (hopefully)
  * if we call curl_multi_socket_action(CURL_SOCKET_TIMEOUT), and the
splay node is in the past, curl removes it
  * the timeout does not have to happen, as the 'next' timeout may be in
the future
  * curl does not make sure to install an splay node afterwards if required
  * the timeout from the future passes by, but we can't trigger curl to
'see' the timeout, as there is no splay node in the tree for the easy
handle (the server closing the connection may help)

I had a look where to Curl_expire ... and there were many places where I
felt I'd miss a proper Curl_expire.
In general, I the splay tree to be rather confusing, as you can have a
pending node in the splay tree, but no real timeout for a handle, as you
forgot to update the splay tree, but updated the handles actual timeout
values for a specific action.

pushing structs with easy handles and callbacks into the splay tree, and
removing them and updating them, would get rid of this problem.

Like this:
struct curl_timer
{
void (*curl_timer_cb)(void *);
void *data;
double when;
double repeat;
}

similar to libev's ev_timers.
http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_timer_code_relative_and_opti
If you want to start a timer, curl_timer_start, got action and the timer
has to be restarted, curl_timer_again, timer can be stopped as it is not
needed any longer, curl_timer_stop.

It will take lots of effort, but will make the code much easier to
maintain on the long run.

So ...for now... I decided to be more generic, fix CURLOPT_TIMEOUT, as
it will work for most cases.

Patch is attached.

Markus

Received on 2009-08-18