removed tabs and trailing whitespace from source
[platform/upstream/c-ares.git] / ares_fds.c
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 "setup.h"
17 #include <sys/types.h>
18
19 #ifdef HAVE_SYS_TIME_H
20 #include <sys/time.h>
21 #endif
22
23 #include "ares.h"
24 #include "ares_private.h"
25
26 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
27 {
28   struct server_state *server;
29   int i, nfds;
30
31   /* No queries, no file descriptors. */
32   if (!channel->queries)
33     return 0;
34
35   nfds = 0;
36   for (i = 0; i < channel->nservers; i++)
37     {
38       server = &channel->servers[i];
39       if (server->udp_socket != ARES_SOCKET_BAD)
40         {
41           FD_SET(server->udp_socket, read_fds);
42           if (server->udp_socket >= nfds)
43             nfds = server->udp_socket + 1;
44         }
45       if (server->tcp_socket != ARES_SOCKET_BAD)
46         {
47           FD_SET(server->tcp_socket, read_fds);
48           if (server->qhead)
49             FD_SET(server->tcp_socket, write_fds);
50           if (server->tcp_socket >= nfds)
51             nfds = server->tcp_socket + 1;
52         }
53     }
54   return nfds;
55 }