1 /* Copyright 1998 by the Massachusetts Institute of Technology.
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
16 static const char rcsid[] = "$Id: ares_timeout.c,v 1.1 1998/08/13 18:06:35 ghudson Exp $";
18 #include <sys/types.h>
22 #include "ares_private.h"
24 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
25 struct timeval *tvbuf)
29 int offset, min_offset;
31 /* No queries, no timeout (and no fetch of the current time). */
32 if (!channel->queries)
35 /* Find the minimum timeout for the current set of queries. */
38 for (query = channel->queries; query; query = query->next)
40 if (query->timeout == 0)
42 offset = query->timeout - now;
45 if (min_offset == -1 || offset < min_offset)
49 /* If we found a minimum timeout and it's sooner than the one
50 * specified in maxtv (if any), return it. Otherwise go with
53 if (min_offset != -1 && (!maxtv || min_offset <= maxtv->tv_sec))
55 tvbuf->tv_sec = min_offset;