ares_getsock.c
Go to the documentation of this file.
1 
2 /* Copyright (C) 2005 - 2010, Daniel Stenberg
3  *
4  * Permission to use, copy, modify, and distribute this software and its
5  * documentation for any purpose and without fee is hereby granted, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission. M.I.T. makes no representations about the
11  * suitability of this software for any purpose. It is provided "as is"
12  * without express or implied warranty.
13  */
14 
15 #include "ares_setup.h"
16 
17 #include "ares.h"
18 #include "ares_private.h"
19 
21  ares_socket_t *socks,
22  int numsocks) /* size of the 'socks' array */
23 {
24  struct server_state *server;
25  int i;
26  int sockindex=0;
27  int bitmap = 0;
28  unsigned int setbits = 0xffffffff;
29 
30  /* Are there any active queries? */
31  int active_queries = !ares__is_list_empty(&(channel->all_queries));
32 
33  for (i = 0; i < channel->nservers; i++)
34  {
35  server = &channel->servers[i];
36  /* We only need to register interest in UDP sockets if we have
37  * outstanding queries.
38  */
39  if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
40  {
41  if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
42  break;
43  socks[sockindex] = server->udp_socket;
44  bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
45  sockindex++;
46  }
47  /* We always register for TCP events, because we want to know
48  * when the other side closes the connection, so we don't waste
49  * time trying to use a broken connection.
50  */
51  if (server->tcp_socket != ARES_SOCKET_BAD)
52  {
53  if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
54  break;
55  socks[sockindex] = server->tcp_socket;
56  bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
57 
58  if (server->qhead && active_queries)
59  /* then the tcp socket is also writable! */
60  bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);
61 
62  sockindex++;
63  }
64  }
65  return bitmap;
66 }
server_state
Definition: ares_private.h:161
ares.h
ARES_GETSOCK_MAXNUM
#define ARES_GETSOCK_MAXNUM
Definition: ares.h:209
ARES_GETSOCK_READABLE
#define ARES_GETSOCK_READABLE(bits, num)
Definition: ares.h:210
ares__is_list_empty
int ares__is_list_empty(struct list_node *head)
Definition: ares_llist.c:41
ares_getsock
int ares_getsock(ares_channel channel, ares_socket_t *socks, int numsocks)
Definition: ares_getsock.c:20
server
std::unique_ptr< Server > server
Definition: channelz_service_test.cc:330
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
ares_setup.h
ARES_SOCKET_BAD
#define ARES_SOCKET_BAD
Definition: ares.h:230
ares_channeldata
Definition: ares_private.h:266
server
Definition: examples/python/async_streaming/server.py:1
ares_socket_t
int ares_socket_t
Definition: ares.h:229
ARES_GETSOCK_WRITABLE
#define ARES_GETSOCK_WRITABLE(bits, num)
Definition: ares.h:211
ares_private.h
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43