X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fasyn-ares.c;h=281fb03c8b1a07a1a0d416d2af63f9a385b12802;hb=73566f8a573abaaa17c61ec59743141d2e9fac42;hp=c038c2a3f157b6a7b7d203c2e5cc6eebe7ec83c5;hpb=24b9957402f17c422eeeb3386bf049feeb342e78;p=platform%2Fupstream%2Fcurl.git diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index c038c2a..281fb03 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -358,12 +358,20 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, struct timeval now = Curl_tvnow(); struct Curl_dns_entry *temp_entry; + if(entry) + *entry = NULL; /* clear on entry */ + timeout = Curl_timeleft(data, &now, TRUE); + if(timeout < 0) { + /* already expired! */ + connclose(conn, "Timed out before name resolve started"); + return CURLE_OPERATION_TIMEDOUT; + } if(!timeout) timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */ /* Wait for the name resolve query to complete. */ - for(;;) { + while(!result) { struct timeval *tvp, tv, store; long timediff; int itimeout; @@ -385,28 +393,25 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, timeout_ms = 1000; waitperform(conn, timeout_ms); - Curl_resolver_is_resolved(conn, &temp_entry); + result = Curl_resolver_is_resolved(conn, &temp_entry); - if(conn->async.done) + if(result || conn->async.done) break; - if(Curl_pgrsUpdate(conn)) { + if(Curl_pgrsUpdate(conn)) result = CURLE_ABORTED_BY_CALLBACK; - timeout = -1; /* trigger the cancel below */ - } else { struct timeval now2 = Curl_tvnow(); timediff = Curl_tvdiff(now2, now); /* spent time */ timeout -= timediff?timediff:1; /* always deduct at least 1 */ now = now2; /* for next loop */ } - - if(timeout < 0) { - /* our timeout, so we cancel the ares operation */ - ares_cancel((ares_channel)data->state.resolver); - break; - } + if(timeout < 0) + result = CURLE_OPERATION_TIMEDOUT; } + if(result) + /* failure, so we cancel the ares operation */ + ares_cancel((ares_channel)data->state.resolver); /* Operation complete, if the lookup was successful we now have the entry in the cache. */