diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-03-31 12:45:26 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-03-31 12:45:26 +0000 |
commit | ea0cf7c87b88810e4de39b5fd6c68dfc20909251 (patch) | |
tree | a2eb1da41b98f923cc3490a7d514249955868a52 /lib | |
parent | a56164c8e0653082945b248730f3a2c36b7b9d2a (diff) |
Dirk Manske found out the Curl_wait_for_resolv() timed out too early.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hostip.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index ef2574d62..0ce07be81 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -614,9 +614,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn, CURLcode rc=CURLE_OK; struct SessionHandle *data = conn->data; struct timeval now = Curl_tvnow(); - bool timedout = FALSE; long timeout = 300; /* default name resolve timeout in seconds */ - long elapsed = 0; /* time taken so far */ /* now, see if there's a connect timeout or a regular timeout to use instead of the default one */ @@ -626,33 +624,29 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn, timeout = conn->data->set.timeout; /* Wait for the name resolve query to complete. */ - while (1) { + while (timeout > 0) { int nfds=0; fd_set read_fds, write_fds; struct timeval *tvp, tv, store; int count; - store.tv_sec = (int)(timeout - elapsed); + store.tv_sec = (int)timeout; store.tv_usec = 0; FD_ZERO(&read_fds); FD_ZERO(&write_fds); nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds); if (nfds == 0) + /* no file descriptors means we're done waiting */ break; - tvp = ares_timeout(data->state.areschannel, - &store, &tv); + tvp = ares_timeout(data->state.areschannel, &store, &tv); count = select(nfds, &read_fds, &write_fds, NULL, tvp); if (count < 0 && errno != EINVAL) break; - else if(!count) { - /* timeout */ - timedout = TRUE; - break; - } + ares_process(data->state.areschannel, &read_fds, &write_fds); - elapsed = Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */ + timeout -= Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */ } /* Operation complete, if the lookup was successful we now have the entry @@ -663,7 +657,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn, if(!conn->async.dns) { /* a name was not resolved */ - if(timedout || (conn->async.status == ARES_ETIMEOUT)) { + if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) { failf(data, "Resolving host timed out: %s", conn->name); rc = CURLE_OPERATION_TIMEDOUT; } |