3 /* Copyright (C) 2005 - 2007, Daniel Stenberg
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation for any purpose and without fee is hereby granted, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of M.I.T. not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. M.I.T. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
18 #ifdef HAVE_SYS_TIME_H
23 #include "ares_private.h"
25 int ares_getsock(ares_channel channel,
27 int numsocks) /* size of the 'socks' array */
29 struct server_state *server;
33 unsigned int setbits = 0xffffffff;
35 ares_socket_t *socks = (ares_socket_t *)s;
37 /* No queries, no file descriptors. */
38 if (!channel->queries)
42 (i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
45 server = &channel->servers[i];
46 if (server->udp_socket != ARES_SOCKET_BAD)
48 if(sockindex >= numsocks)
50 socks[sockindex] = server->udp_socket;
51 bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
54 if (server->tcp_socket != ARES_SOCKET_BAD)
56 if(sockindex >= numsocks)
58 socks[sockindex] = server->tcp_socket;
59 bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
62 /* then the tcp socket is also writable! */
63 bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);