GRPC C++  1.26.0
tcp_server_utils_posix.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H
20 #define GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H
21 
23 
28 
29 /* one listening port */
30 typedef struct grpc_tcp_listener {
31  int fd;
35  int port;
36  unsigned port_index;
37  unsigned fd_index;
41  /* sibling is a linked list of all listeners for a given port. add_port and
42  clone_port place all new listeners in the same sibling list. A member of
43  the 'sibling' list is also a member of the 'next' list. The head of each
44  sibling list has is_sibling==0, and subsequent members of sibling lists
45  have is_sibling==1. is_sibling allows separate sibling lists to be
46  identified while iterating through 'next'. */
50 
51 /* the overall server */
54  /* Called whenever accept() succeeds on a server port. */
57 
59 
60  /* active port count: how many ports are actually still listening */
61  size_t active_ports;
62  /* destroyed port count: how many ports are completely destroyed */
64 
65  /* is this server shutting down? */
66  bool shutdown;
67  /* have listeners been shutdown? */
69  /* use SO_REUSEPORT */
71  /* expand wildcard addresses to a list of all local addresses */
73 
74  /* linked list of server ports */
77  unsigned nports;
78 
79  /* List of closures passed to shutdown_starting_add(). */
81 
82  /* shutdown callback */
84 
85  /* all pollsets interested in new connections */
87  /* number of pollsets in the pollsets array */
88  size_t pollset_count;
89 
90  /* next pollset to assign a channel to */
92 
93  /* channel args for this server */
95 
96  /* a handler for external connections, owned */
98 };
99 
100 /* If successful, add a listener to \a s for \a addr, set \a dsmode for the
101  socket, and return the \a listener. */
103  const grpc_resolved_address* addr,
104  unsigned port_index, unsigned fd_index,
105  grpc_dualstack_mode* dsmode,
106  grpc_tcp_listener** listener);
107 
108 /* Get all addresses assigned to network interfaces on the machine and create a
109  listener for each. requested_port is the port to use for every listener, or 0
110  to select one random port that will be used for every listener. Set *out_port
111  to the port selected. Return GRPC_ERROR_NONE only if all listeners were
112  added. */
114  unsigned port_index,
115  int requested_port,
116  int* out_port);
117 
118 /* Prepare a recently-created socket for listening. */
120  const grpc_resolved_address* addr,
121  bool so_reuseport, int* port);
122 /* Ruturn true if the platform supports ifaddrs */
124 
125 #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H */
struct grpc_tcp_listener * sibling
Definition: tcp_server_utils_posix.h:47
void(* grpc_tcp_server_cb)(void *arg, grpc_endpoint *ep, grpc_pollset *accepting_pollset, grpc_tcp_server_acceptor *acceptor)
Definition: tcp_server.h:49
int port
Definition: tcp_server_utils_posix.h:35
bool shutdown_listeners
Definition: tcp_server_utils_posix.h:68
Definition: sync_generic.h:36
grpc_tcp_server_cb on_accept_cb
Definition: tcp_server_utils_posix.h:55
An array of arguments that can be passed around.
Definition: grpc_types.h:132
grpc_error * grpc_tcp_server_prepare_socket(grpc_tcp_server *, int fd, const grpc_resolved_address *addr, bool so_reuseport, int *port)
bool expand_wildcard_addrs
Definition: tcp_server_utils_posix.h:72
Definition: resolve_address.h:44
grpc_tcp_listener * tail
Definition: tcp_server_utils_posix.h:76
grpc_dualstack_mode
Definition: socket_utils_posix.h:103
struct grpc_tcp_listener * next
Definition: tcp_server_utils_posix.h:40
Definition: error_internal.h:39
int fd
Definition: tcp_server_utils_posix.h:31
unsigned port_index
Definition: tcp_server_utils_posix.h:36
grpc_fd * emfd
Definition: tcp_server_utils_posix.h:32
grpc_closure read_closure
Definition: tcp_server_utils_posix.h:38
unsigned nports
Definition: tcp_server_utils_posix.h:77
Definition: closure.h:41
Definition: tcp_server_utils_posix.h:52
grpc_pollset ** pollsets
Definition: tcp_server_utils_posix.h:86
grpc_error * grpc_tcp_server_add_all_local_addrs(grpc_tcp_server *s, unsigned port_index, int requested_port, int *out_port)
size_t active_ports
Definition: tcp_server_utils_posix.h:61
grpc_core::TcpServerFdHandler * fd_handler
Definition: tcp_server_utils_posix.h:97
grpc_resolved_address addr
Definition: tcp_server_utils_posix.h:34
Definition: sync_windows.h:26
struct grpc_fd grpc_fd
Definition: ev_posix.h:44
grpc_tcp_listener * head
Definition: tcp_server_utils_posix.h:75
grpc_tcp_server * server
Definition: tcp_server_utils_posix.h:33
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
unsigned fd_index
Definition: tcp_server_utils_posix.h:37
struct grpc_pollset grpc_pollset
Definition: pollset.h:38
gpr_refcount refs
Definition: tcp_server_utils_posix.h:53
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
grpc_channel_args * channel_args
Definition: tcp_server_utils_posix.h:94
grpc_closure_list shutdown_starting
Definition: tcp_server_utils_posix.h:80
grpc_closure destroyed_closure
Definition: tcp_server_utils_posix.h:39
void * on_accept_cb_arg
Definition: tcp_server_utils_posix.h:56
bool so_reuseport
Definition: tcp_server_utils_posix.h:70
Definition: tcp_server_utils_posix.h:30
grpc_closure * shutdown_complete
Definition: tcp_server_utils_posix.h:83
gpr_mu mu
Definition: tcp_server_utils_posix.h:58
int is_sibling
Definition: tcp_server_utils_posix.h:48
bool grpc_tcp_server_have_ifaddrs(void)
gpr_atm next_pollset_to_assign
Definition: tcp_server_utils_posix.h:91
bool shutdown
Definition: tcp_server_utils_posix.h:66
struct grpc_tcp_listener grpc_tcp_listener
grpc_error * grpc_tcp_server_add_addr(grpc_tcp_server *s, const grpc_resolved_address *addr, unsigned port_index, unsigned fd_index, grpc_dualstack_mode *dsmode, grpc_tcp_listener **listener)
Definition: tcp_server.h:55
size_t destroyed_ports
Definition: tcp_server_utils_posix.h:63
size_t pollset_count
Definition: tcp_server_utils_posix.h:88