diff options
author | Gokhan Sengun <gokhansengun@gmail.com> | 2011-12-19 14:35:20 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-12-20 20:30:02 +0100 |
commit | c834213ad52c52431e9ca597862dc81839cabe84 (patch) | |
tree | 678dfd82d3129b8aef8a0222defc55244003203b /lib/connect.c | |
parent | 5527417afae062d7a2b12ee80730a0ab22b86eab (diff) | |
download | curl-c834213ad52c52431e9ca597862dc81839cabe84.tar.gz |
FTP: perform active connections non-blocking
1- Two new error codes are introduced.
CURLE_FTP_ACCEPT_FAILED to be set whenever ACCEPTing fails because of
FTP server connected.
CURLE_FTP_ACCEPT_TIMEOUT to be set whenever ACCEPTing timeouts.
Neither of these errors are considered fatal and control connection
remains OK because it could just be a firewall blocking server to
connect to the client.
2- One new setopt option was introduced.
CURLOPT_ACCEPTTIMEOUT_MS
It sets the maximum amount of time FTP client is going to wait for a
server to connect. Internal default accept timeout is 60 seconds.
Diffstat (limited to 'lib/connect.c')
-rw-r--r-- | lib/connect.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/connect.c b/lib/connect.c index bcd538406..cc835808b 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -99,6 +99,34 @@ singleipconnect(struct connectdata *conn, bool *connected); /* + * Curl_timeleft_accept() returns the amount of milliseconds left allowed for + * waiting server to connect. If the value is negative, the timeout time has + * already elapsed. + * + * The start time is stored in progress.t_acceptdata - as set with + * Curl_pgrsTime(..., TIMER_STARTACCEPT); + * + */ +long Curl_timeleft_accept(struct SessionHandle *data) +{ + long timeout_ms = DEFAULT_ACCEPT_TIMEOUT; + struct timeval now; + + if(data->set.accepttimeout > 0) + timeout_ms = data->set.accepttimeout; + + now = Curl_tvnow(); + + /* subtract elapsed time */ + timeout_ms -= Curl_tvdiff(now, data->progress.t_acceptdata); + if(!timeout_ms) + /* avoid returning 0 as that means no timeout! */ + return -1; + + return timeout_ms; +} + +/* * Curl_timeleft() returns the amount of milliseconds left allowed for the * transfer/connection. If the value is negative, the timeout time has already * elapsed. |