3 /* Copyright (C) 2005 - 2006, 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.
17 #include <sys/types.h>
19 #ifdef HAVE_SYS_TIME_H
24 #include "ares_private.h"
26 int ares_getsock(ares_channel channel,
28 int numsocks) /* size of the 'socks' array */
30 struct server_state *server;
34 unsigned int setbits = 0xffffffff;
36 ares_socket_t *socks = (ares_socket_t *)s;
38 /* No queries, no file descriptors. */
39 if (!channel->queries)
43 (i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
46 server = &channel->servers[i];
47 if (server->udp_socket != ARES_SOCKET_BAD)
49 if(sockindex >= numsocks)
51 socks[sockindex] = server->udp_socket;
52 bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
55 if (server->tcp_socket != ARES_SOCKET_BAD)
57 if(sockindex >= numsocks)
59 socks[sockindex] = server->tcp_socket;
60 bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
63 /* then the tcp socket is also writable! */
64 bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);