summaryrefslogtreecommitdiff
path: root/ares_timeout.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2008-05-13 20:48:48 +0000
committerDaniel Stenberg <daniel@haxx.se>2008-05-13 20:48:48 +0000
commit46dbd9461af66b9aa11a7f9e776979df6be028ac (patch)
tree3bfc49e25d58aec0342727b02ba904c7ea6c7e0e /ares_timeout.c
parent76d91c21ad6248518e37eb6dd6b52fb7ab8a7fbd (diff)
downloadc-ares-46dbd9461af66b9aa11a7f9e776979df6be028ac.tar.gz
c-ares-46dbd9461af66b9aa11a7f9e776979df6be028ac.tar.bz2
c-ares-46dbd9461af66b9aa11a7f9e776979df6be028ac.zip
- Introducing millisecond resolution support for the timeout option. See
ares_init_options()'s ARES_OPT_TIMEOUTMS.
Diffstat (limited to 'ares_timeout.c')
-rw-r--r--ares_timeout.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/ares_timeout.c b/ares_timeout.c
index 12b93b0..ce98491 100644
--- a/ares_timeout.c
+++ b/ares_timeout.c
@@ -37,16 +37,16 @@ struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
struct query *query;
struct list_node* list_head;
struct list_node* list_node;
- time_t now;
- time_t offset, min_offset; /* these use time_t since some 32 bit systems
- still use 64 bit time_t! (like VS2005) */
+ struct timeval now;
+ struct timeval nextstop;
+ long offset, min_offset;
/* No queries, no timeout (and no fetch of the current time). */
if (ares__is_list_empty(&(channel->all_queries)))
return maxtv;
/* Find the minimum timeout for the current set of queries. */
- time(&now);
+ now = ares__tvnow();
min_offset = -1;
list_head = &(channel->all_queries);
@@ -54,23 +54,26 @@ struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
list_node = list_node->next)
{
query = list_node->data;
- if (query->timeout == 0)
+ if (query->timeout.tv_sec == 0)
continue;
- offset = query->timeout - now;
+ offset = ares__timeoffset(&now, &query->timeout);
if (offset < 0)
offset = 0;
if (min_offset == -1 || offset < min_offset)
min_offset = offset;
}
- /* If we found a minimum timeout and it's sooner than the one
- * specified in maxtv (if any), return it. Otherwise go with
- * maxtv.
+ if(min_offset != -1) {
+ nextstop = now;
+ ares__timeadd(&now, min_offset);
+ }
+
+ /* If we found a minimum timeout and it's sooner than the one specified in
+ * maxtv (if any), return it. Otherwise go with maxtv.
*/
- if (min_offset != -1 && (!maxtv || min_offset <= maxtv->tv_sec))
+ if (min_offset != -1 && (!maxtv || ares__timedout(maxtv, &nextstop)))
{
- tvbuf->tv_sec = (long)min_offset;
- tvbuf->tv_usec = 0;
+ *tvbuf = nextstop;
return tvbuf;
}
else