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 | static const char rcsid[] = "$Id: ares_fds.c,v 1.2 1998-09-04 21:09:30 ghudson Exp $"; |
---|
17 | |
---|
18 | #include <sys/types.h> |
---|
19 | #include <sys/time.h> |
---|
20 | #include "ares.h" |
---|
21 | #include "ares_private.h" |
---|
22 | |
---|
23 | int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds) |
---|
24 | { |
---|
25 | struct server_state *server; |
---|
26 | int i, nfds; |
---|
27 | |
---|
28 | /* No queries, no file descriptors. */ |
---|
29 | if (!channel->queries) |
---|
30 | return 0; |
---|
31 | |
---|
32 | nfds = 0; |
---|
33 | for (i = 0; i < channel->nservers; i++) |
---|
34 | { |
---|
35 | server = &channel->servers[i]; |
---|
36 | if (server->udp_socket != -1) |
---|
37 | { |
---|
38 | FD_SET(server->udp_socket, read_fds); |
---|
39 | if (server->udp_socket >= nfds) |
---|
40 | nfds = server->udp_socket + 1; |
---|
41 | } |
---|
42 | if (server->tcp_socket != -1) |
---|
43 | { |
---|
44 | FD_SET(server->tcp_socket, read_fds); |
---|
45 | if (server->qhead) |
---|
46 | FD_SET(server->tcp_socket, write_fds); |
---|
47 | if (server->tcp_socket >= nfds) |
---|
48 | nfds = server->tcp_socket + 1; |
---|
49 | } |
---|
50 | } |
---|
51 | return nfds; |
---|
52 | } |
---|