Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: third_party/grpc/src/core/iomgr/tcp_server.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_INTERNAL_CORE_IOMGR_TCP_SERVER_H
35 #define GRPC_INTERNAL_CORE_IOMGR_TCP_SERVER_H
36
37 #include "src/core/iomgr/closure.h"
38 #include "src/core/iomgr/endpoint.h"
39
40 /* Forward decl of grpc_tcp_server */
41 typedef struct grpc_tcp_server grpc_tcp_server;
42
43 typedef struct grpc_tcp_server_acceptor {
44 /* grpc_tcp_server_cb functions share a ref on from_server that is valid
45 until the function returns. */
46 grpc_tcp_server *from_server;
47 /* Indices that may be passed to grpc_tcp_server_port_fd(). */
48 unsigned port_index;
49 unsigned fd_index;
50 } grpc_tcp_server_acceptor;
51
52 /* Called for newly connected TCP connections. */
53 typedef void (*grpc_tcp_server_cb)(grpc_exec_ctx *exec_ctx, void *arg,
54 grpc_endpoint *ep,
55 grpc_tcp_server_acceptor *acceptor);
56
57 /* Create a server, initially not bound to any ports. The caller owns one ref.
58 If shutdown_complete is not NULL, it will be used by
59 grpc_tcp_server_unref() when the ref count reaches zero. */
60 grpc_tcp_server *grpc_tcp_server_create(grpc_closure *shutdown_complete);
61
62 /* Start listening to bound ports */
63 void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *server,
64 grpc_pollset **pollsets, size_t pollset_count,
65 grpc_tcp_server_cb on_accept_cb, void *cb_arg);
66
67 /* Add a port to the server, returning the newly allocated port on success, or
68 -1 on failure.
69
70 The :: and 0.0.0.0 wildcard addresses are treated identically, accepting
71 both IPv4 and IPv6 connections, but :: is the preferred style. This usually
72 creates one socket, but possibly two on systems which support IPv6,
73 but not dualstack sockets. */
74 /* TODO(ctiller): deprecate this, and make grpc_tcp_server_add_ports to handle
75 all of the multiple socket port matching logic in one place */
76 int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
77 size_t addr_len);
78
79 /* Number of fds at the given port_index, or 0 if port_index is out of
80 bounds. */
81 unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, unsigned port_index);
82
83 /* Returns the file descriptor of the Mth (fd_index) listening socket of the Nth
84 (port_index) call to add_port() on this server, or -1 if the indices are out
85 of bounds. The file descriptor remains owned by the server, and will be
86 cleaned up when the ref count reaches zero. */
87 int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index,
88 unsigned fd_index);
89
90 /* Ref s and return s. */
91 grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s);
92
93 /* shutdown_starting is called when ref count has reached zero and the server is
94 about to be destroyed. The server will be deleted after it returns. Calling
95 grpc_tcp_server_ref() from it has no effect. */
96 void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s,
97 grpc_closure *shutdown_starting);
98
99 /* If the refcount drops to zero, delete s, and call (exec_ctx==NULL) or enqueue
100 a call (exec_ctx!=NULL) to shutdown_complete. */
101 void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s);
102
103 #endif /* GRPC_INTERNAL_CORE_IOMGR_TCP_SERVER_H */
OLDNEW
« no previous file with comments | « third_party/grpc/src/core/iomgr/tcp_posix.c ('k') | third_party/grpc/src/core/iomgr/tcp_server_posix.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698