gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
tcp_server.h
1 /*
2  *
3  * Copyright 2015, 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/endpoint.h"
38 
39 /* Forward decl of grpc_tcp_server */
40 typedef struct grpc_tcp_server grpc_tcp_server;
41 
42 /* New server callback: tcp is the newly connected tcp connection */
43 typedef void (*grpc_tcp_server_cb)(void *arg, grpc_endpoint *ep);
44 
45 /* Create a server, initially not bound to any ports */
46 grpc_tcp_server *grpc_tcp_server_create(void);
47 
48 /* Start listening to bound ports */
49 void grpc_tcp_server_start(grpc_tcp_server *server, grpc_pollset **pollsets,
50  size_t pollset_count, grpc_tcp_server_cb cb,
51  void *cb_arg);
52 
53 /* Add a port to the server, returning port number on success, or negative
54  on failure.
55 
56  The :: and 0.0.0.0 wildcard addresses are treated identically, accepting
57  both IPv4 and IPv6 connections, but :: is the preferred style. This usually
58  creates one socket, but possibly two on systems which support IPv6,
59  but not dualstack sockets.
60 
61  For raw access to the underlying sockets, see grpc_tcp_server_get_fd(). */
62 /* TODO(ctiller): deprecate this, and make grpc_tcp_server_add_ports to handle
63  all of the multiple socket port matching logic in one place */
64 int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
65  int addr_len);
66 
67 /* Returns the file descriptor of the Nth listening socket on this server,
68  or -1 if the index is out of bounds.
69 
70  The file descriptor remains owned by the server, and will be cleaned
71  up when grpc_tcp_server_destroy is called. */
72 int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index);
73 
74 void grpc_tcp_server_destroy(grpc_tcp_server *server,
75  void (*shutdown_done)(void *shutdown_done_arg),
76  void *shutdown_done_arg);
77 
78 #endif /* GRPC_INTERNAL_CORE_IOMGR_TCP_SERVER_H */
Definition: cmdline.c:46
Definition: pollset_posix.h:48
Definition: endpoint.h:102