ares_fds.c
Go to the documentation of this file.
1 
2 /* Copyright 1998 by the Massachusetts Institute of Technology.
3  *
4  * Permission to use, copy, modify, and distribute this
5  * software and its documentation for any purpose and without
6  * fee is hereby granted, provided that the above copyright
7  * notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting
9  * documentation, and that the name of M.I.T. not be used in
10  * advertising or publicity pertaining to distribution of the
11  * software without specific, written prior permission.
12  * M.I.T. makes no representations about the suitability of
13  * this software for any purpose. It is provided "as is"
14  * without express or implied warranty.
15  */
16 
17 #include "ares_setup.h"
18 
19 #include "ares.h"
20 #include "ares_nowarn.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  ares_socket_t nfds;
27  int i;
28 
29  /* Are there any active queries? */
30  int active_queries = !ares__is_list_empty(&(channel->all_queries));
31 
32  nfds = 0;
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  FD_SET(server->udp_socket, read_fds);
42  if (server->udp_socket >= nfds)
43  nfds = server->udp_socket + 1;
44  }
45  /* We always register for TCP events, because we want to know
46  * when the other side closes the connection, so we don't waste
47  * time trying to use a broken connection.
48  */
49  if (server->tcp_socket != ARES_SOCKET_BAD)
50  {
51  FD_SET(server->tcp_socket, read_fds);
52  if (server->qhead)
53  FD_SET(server->tcp_socket, write_fds);
54  if (server->tcp_socket >= nfds)
55  nfds = server->tcp_socket + 1;
56  }
57  }
58  return (int)nfds;
59 }
server_state
Definition: ares_private.h:161
ares_fds
int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
Definition: ares_fds.c:23
ares.h
ares__is_list_empty
int ares__is_list_empty(struct list_node *head)
Definition: ares_llist.c:41
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_private.h
ares_nowarn.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