cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to set transaction timeout?

From: <johansen_at_sun.com>
Date: Mon, 15 Mar 2010 13:25:40 -0700

On Mon, Mar 15, 2010 at 06:06:57PM +0530, debojyoti.pal_at_wipro.com wrote:
> Hi,
>
> Is there any way to set the transaction timeout? There is one timeout
> for connection and another timeout for aborting transaction, which means
> that up to the specified amount of time, the transaction will continue
> and then will come out no matter whether the transaction is completed or
> not.
>
> But what I am looking for is different. This is required in the
> following case:
> Suppose through Curl I am downloading some big chunk of data, but since
> the connection is slow data comes to me at delayed interval, then my
> application would have to wait long time. But if I can set the
> transaction timeout for X second, then my application would wait for X
> seconds only and then come out if I don't receive data within period X.

I'm not sure I understand what you're looking for based upon your
description; however, there are a couple of different options.

The CURLOPT_TIMEOUT sets a limit on the total amount of time a
transaction may take. If your timeout is 30 seconds, and any part of
the operation takes longer than 30 seconds (data transfer included) then
your applicication will get a timeout error.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTTIMEOUT

CURLOPT_CONNECTTIMEOUT puts a limit on the amount of time the
application will wait for a connection before giving up.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT

The low speed time and limit allow you to set a lower bound on the
performance of your connection, and then give up with a timeout error if
the transfer is too slow. I used this timeout to terminate slow
transfers in my application. I configured the speed limit to 1 K/s, and
the timeout to 30 seconds. If the application receives less than 1 k/s
over a 30 second period of time, curl will generate a timeout.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTLOWSPEEDTIME
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTLOWSPEEDLIMIT

You can tune this for your environment, or make it adapative based upon
observed performance. The curl_easy_getinfo() function allows you to
get a bunch of useful statistics about performance.

HTH,

-j
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-03-15