00001 /* Copyright 1998 by the Massachusetts Institute of Technology. 00002 * 00003 * Permission to use, copy, modify, and distribute this 00004 * software and its documentation for any purpose and without 00005 * fee is hereby granted, provided that the above copyright 00006 * notice appear in all copies and that both that copyright 00007 * notice and this permission notice appear in supporting 00008 * documentation, and that the name of M.I.T. not be used in 00009 * advertising or publicity pertaining to distribution of the 00010 * software without specific, written prior permission. 00011 * M.I.T. makes no representations about the suitability of 00012 * this software for any purpose. It is provided "as is" 00013 * without express or implied warranty. 00014 * 00015 * CHANGELOG: this file has been modified by Sergio Perez Alcañiz <serpeal@disca.upv.es> 00016 * Departamento de Informática de Sistemas y Computadores 00017 * Universidad Politécnica de Valencia 00018 * Valencia (Spain) 00019 * Date: April 2003 00020 * 00021 */ 00022 00023 #include "ares_private.h" 00024 00025 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds) 00026 { 00027 struct server_state *server; 00028 int i, nfds; 00029 00030 /* No queries, no file descriptors. */ 00031 if (!channel->queries) 00032 return 0; 00033 00034 nfds = 0; 00035 for (i = 0; i < channel->nservers; i++) 00036 { 00037 server = &channel->servers[i]; 00038 if (server->udp_socket != -1) 00039 { 00040 FD_SET(server->udp_socket, read_fds); 00041 if (server->udp_socket >= nfds) 00042 nfds = server->udp_socket + 1; 00043 } 00044 if (server->tcp_socket != -1) 00045 { 00046 FD_SET(server->tcp_socket, read_fds); 00047 if (server->qhead) 00048 FD_SET(server->tcp_socket, write_fds); 00049 if (server->tcp_socket >= nfds) 00050 nfds = server->tcp_socket + 1; 00051 } 00052 } 00053 return nfds; 00054 }