/[resiprocate]/main/contrib/ares/ares_timeout.c
ViewVC logotype

Contents of /main/contrib/ares/ares_timeout.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5295 - (show annotations) (download)
Mon Aug 22 00:30:05 2005 UTC (14 years, 3 months ago) by jason
File MIME type: text/plain
File size: 1807 byte(s)
merged 5270:HEAD from b-directory-reorg
1 /* Copyright 1998 by the Massachusetts Institute of Technology.
2 *
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.
14 */
15
16 #include <sys/types.h>
17 #include <time.h>
18 #include "ares.h"
19 #include "ares_private.h"
20 #ifndef WIN32
21 #include <sys/time.h>
22 #endif
23
24 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
25 struct timeval *tvbuf)
26 {
27 struct query *query;
28 time_t now;
29 int offset, min_offset;
30
31 /* No queries, no timeout (and no fetch of the current time). */
32 if (!channel->queries)
33 return maxtv;
34
35 /* Find the minimum timeout for the current set of queries. */
36 time(&now);
37 min_offset = -1;
38 for (query = channel->queries; query; query = query->next)
39 {
40 if (query->timeout == 0)
41 continue;
42 offset = query->timeout - now;
43 if (offset < 0)
44 offset = 0;
45 if (min_offset == -1 || offset < min_offset)
46 min_offset = offset;
47 }
48
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
51 * maxtv.
52 */
53 if (min_offset != -1 && (!maxtv || min_offset <= maxtv->tv_sec))
54 {
55 tvbuf->tv_sec = min_offset;
56 tvbuf->tv_usec = 0;
57 return tvbuf;
58 }
59 else
60 return maxtv;
61 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27