cURL / Mailing Lists / curl-library / Single Mail

curl-library

about separate connect timeout and total timeout

From: 부합 <hqin6_at_163.com>
Date: Fri, 30 Aug 2013 11:04:32 +0800 (CST)

hi,

When I use libcurl, I want separate connect timeout and total timeout. Because when I use keep-alive for connection, I want to set the different time for connect timeout and transfer timeout. But curl just has CURLOPT_CONNECTTIMEOUT_MS & CURLOPT_TIMEOUT_MS which is set just for connect timeout and total timeout.

For example, keep-alive, I want to connect an addr, and it will spend 40ms in network from client to server. If I set total timeout is 60ms, then I can't get anything from server, because tcp connect will spend 40ms and the real data transfer will spend 40ms. But if I can set connect timeout to 60ms and transfer timeout to 60ms, so I can connect the server and get some real data, because tcp connect can complete in 60ms, and transfer data can cpmplete in 60ms too.

I can't set the CURLOPT_TIMEOUT_MS too long, because I must protect my client.

like this:

10:49:51.284599 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [S], seq 1236844807, win 14600, options [mss 1460,sackOK,TS val 209760 ecr 0,nop,wscale 7], length 0
10:49:51.324330 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [S.], seq 1363489447, ack 1236844808, win 64240, options [mss 1460], length 0
10:49:51.324392 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [.], ack 1, win 14600, length 0 -----------------------------------here is tcp connect end, spent 40ms
10:49:51.324616 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [P.], seq 1:75, ack 1, win 14600, length 74
10:49:51.324902 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [.], ack 75, win 64240, length 0
10:49:51.366567 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [P.], seq 1:570, ack 75, win 64240, length 569
10:49:51.366646 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [.], ack 570, win 15363, length 0 --------------------------here is transfer end, spent 42ms

if keep alive: the transfer will continue in the same connection.

10:49:51.324616 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [P.], seq 1:75, ack 1, win 14600, length 74
10:49:51.324902 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [.], ack 75, win 64240, length 0
10:49:51.366567 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [P.], seq 1:570, ack 75, win 64240, length 569
10:49:51.366646 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [.], ack 570, win 15363, length 0 --------------------------here is transfer end, spent 42ms

10:49:51.324616 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [P.], seq 1:75, ack 1, win 14600, length 74
10:49:51.324902 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [.], ack 75, win 64240, length 0
10:49:51.366567 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [P.], seq 1:570, ack 75, win 64240, length 569
10:49:51.366646 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [.], ack 570, win 15363, length 0 --------------------------here is transfer end, spent 42ms

10:49:51.324616 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [P.], seq 1:75, ack 1, win 14600, length 74
10:49:51.324902 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [.], ack 75, win 64240, length 0
10:49:51.366567 IP hg-in-f100.1e100.net.http > ubuntu.local.36923: Flags [P.], seq 1:570, ack 75, win 64240, length 569
10:49:51.366646 IP ubuntu.local.36923 > hg-in-f100.1e100.net.http: Flags [.], ack 570, win 15363, length 0 --------------------------here is transfer end, spent 42ms

in this case, connect timeout will be used only once, but transfer timeout will be used more than once. If I set CURLOPT_CONNECTTIMEOUT_MS 60ms and set CURLOPT_TIMEOUT_MS 70ms, I can never connect this server. If I set CURLOPT_TIMEOUT_MS enough long , it can work, but I just want control the transfer time.

so , I want curl can have an interface for this case to set transfer timeout.

how do you think ?

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-08-30