aboutsummaryrefslogtreecommitdiff
path: root/ares/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
commit76c251513e73d9fd940ed4df8a9b73ca587559f8 (patch)
treea2c4924599df991cb31af9f7edc7bb534850541d /ares/ares_timeout.c
parent80afddacc8ee850c7e591f8d73427042f4d9db12 (diff)
- Introducing millisecond resolution support for the timeout option. See
ares_init_options()'s ARES_OPT_TIMEOUTMS.
Diffstat (limited to 'ares/ares_timeout.c')
-rw-r--r--ares/ares_timeout.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/ares/ares_timeout.c b/ares/ares_timeout.c
index 12b93b044..ce9849153 100644
--- a/ares/ares_timeout.c
+++ b/ares/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