cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_CONNECTTIMEOUT and

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Fri, 23 Jan 2004 13:32:14 +0100 (CET)

On Thu, 22 Jan 2004, Jerry G. Chiuan wrote:

> I have 3 questions while using CURLOPT_CONNECTTIMEOUT:
> (ps: On my XP machine, the system timeout is 100 sec...)

I guess that is XP as in Windows XP.

> Q1:
> we don't need to worry about clean up *without* using CURLOPT_CONNECTTIMEOUT
> ( or our timeout is *longer* than system timeout) since system call will
> time out and take care of clean-up, do we?

You never have to worry about cleaning up curl's timeouts, no matter what
length you set and no matter if the timeout timed out or not.

> BUT, if we used CURLOPT_CONNECTTIMEOUT, e.g. 5(sec) which is *shorter* than
> system timeout, do we need to worry about clean up?

No. You still have to call curl_easy_cleanup() of course.

> Does it actually also use time-outing system calls like CURLOPT_TIMEOUT
> does?, and we don't need to worry about clean up ourselves. connection would
> be deleted by system.

CURLOPT_CONNECTTIMEOUT sets a timeout for the "connect phase", which means
that if the timeout doesn't happen until curl has connected, it will not time
out anything.

CURLOPT_TIMEOUT sets a timeout for the entire transfer, so if the transfer is
still in progress when the timer times out, the the transfer is aborted.

Cleaning up is done by curl itself and your curl_easy_cleanup() call.

Just note that if you don't build curl with ares support on windows, curl
cannot abort the name resolve call. So a slow name lookup might cause
curl_easy_perform() to take a longer time than the maximum time-out you set
with

> While we set CURLOPT_NOSIGNAL as non-zero, does curl still use signal to
> enable time-outing system calls while we set up CURLOPT_TIMEOUT and
> CURLOPT_CONNECTTIMEOUT?

With CURLOPT_NOSIGNAL set non-zero, curl will not use any signals and thus it
won't abort functions using alarm() or similar.

> If not, how does curl enable it?

It doesn't, so if you want full and fine-grained time-out support you should
build curl to use ares for name lookups. The name lookup is the only function
call that isn't performed in a non-blockning manner by a default-build curl.

> Q2:
> basically, there are 2 cases we need to take care of timeout for:
> (1) try to "connect" to an invalid IP
> (2) try to "connect" to a valid IP but there is no http server running on it
>
> I tried CURLOPT_CONNECTTIMEOUT and found it only works for case(2), it will
> return back within even shorter than 5(sec), I don't know why?!

curl returns as soon as it hits an error, if that is faster than your time-out
then that is what happens. curl does not retry connections, it only makes one
attempt (on each IP returned by the resolver).

> BUT for case(1), it still times out based on system timeout ( time out after
> 100 sec ) what can I do for case(1), can we use use CURLOPT_CONNECT for
> case(1)?

In what way is the IP "invalid" ? If that is a slow name lookup happening,
then there's the limits as explained above.

If not, then CURLOPT_CONNECTTIMEOUT should time-out the operation.

-- 
    Daniel Stenberg -- http://curl.haxx.se/ -- http://daniel.haxx.se/
   [[ Do not send mails to this email address. They won't reach me. ]]
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
Received on 2004-01-23