curl-library
Re: AllowServerConnect timeout quesion
Date: Wed, 4 Feb 2004 08:35:18 +0100 (CET)
On Tue, 3 Feb 2004, giladbu wrote:
> Great! I checked the following change, and worked fine for me. The change is
> in bold.
This is pretty much as I was thinking too. A few comments:
1. I don't see bold, I read plain text mails:
http://curl.haxx.se/mail/etiquette.html#html
Please use 'diff -u' when you provide patches.
2. There's also the general timeout option that should be acknowledged, imho
3. The timeout given in both the timeout options is a timeout that is measured
from the beginning of the curl_easy_perform() operation. If you set the
connecttimeout to 10 and it takes 8 seconds to reach to the PASV/PORT
command, then you should only allow 2 seconds for the server to connect...
I therefore suggest this slightly different version instead:
diff -u -r1.223 ftp.c
--- lib/ftp.c 3 Feb 2004 09:52:32 -0000 1.223
+++ lib/ftp.c 4 Feb 2004 07:35:08 -0000
@@ -133,13 +133,25 @@
struct timeval dt;
struct SessionHandle *data = conn->data;
int sock = conn->sock[SECONDARYSOCKET];
+ struct timeval now = Curl_tvnow();
+ int timespent = Curl_tvdiff(Curl_tvnow(), now)/1000;
+ int timeout = data->set.connecttimeout?data->set.connecttimeout:
+ (data->set.timeout?data->set.timeout: 0);
FD_ZERO(&rdset);
FD_SET(sock, &rdset);
+
+ if(timeout) {
+ timeout -= timespent;
+ if(timeout<=0) {
+ failf(data, "Timed out before server could connect to us");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+ }
- /* we give the server 10 seconds to connect to us */
- dt.tv_sec = 10;
+ /* we give the server 60 seconds to connect to us, or a custom timeout */
+ dt.tv_sec = timeout?timeout:60;
dt.tv_usec = 0;
switch (select(sock+1, &rdset, NULL, NULL, &dt)) {
-- 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/osdnReceived on 2004-02-04