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_fds.c,v 1.2 1998/09/04 21:09:30 ghudson Exp $";
18 #include <sys/types.h>
21 #include "ares_private.h"
23 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
25 struct server_state *server;
28 /* No queries, no file descriptors. */
29 if (!channel->queries)
33 for (i = 0; i < channel->nservers; i++)
35 server = &channel->servers[i];
36 if (server->udp_socket != -1)
38 FD_SET(server->udp_socket, read_fds);
39 if (server->udp_socket >= nfds)
40 nfds = server->udp_socket + 1;
42 if (server->tcp_socket != -1)
44 FD_SET(server->tcp_socket, read_fds);
46 FD_SET(server->tcp_socket, write_fds);
47 if (server->tcp_socket >= nfds)
48 nfds = server->tcp_socket + 1;