Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 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 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_IOMGR_UDP_SERVER_H |
| 35 | #define GRPC_CORE_LIB_IOMGR_UDP_SERVER_H |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 36 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 37 | #include "src/core/lib/iomgr/endpoint.h" |
Craig Tiller | 8a03448 | 2016-03-28 16:09:04 -0700 | [diff] [blame] | 38 | #include "src/core/lib/iomgr/ev_posix.h" |
murgatroid99 | aa9c578 | 2016-10-10 12:16:13 -0700 | [diff] [blame] | 39 | #include "src/core/lib/iomgr/resolve_address.h" |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 40 | |
vjpai | aea3207 | 2016-03-18 12:22:59 -0700 | [diff] [blame] | 41 | /* Forward decl of struct grpc_server */ |
| 42 | /* This is not typedef'ed to avoid a typedef-redefinition error */ |
| 43 | struct grpc_server; |
Robbie Shade | 147fe70 | 2015-09-25 15:04:40 -0400 | [diff] [blame] | 44 | |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 45 | /* Forward decl of grpc_udp_server */ |
| 46 | typedef struct grpc_udp_server grpc_udp_server; |
| 47 | |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 48 | /* Called when data is available to read from the socket. */ |
Robbie Shade | c6787b2 | 2015-10-07 10:13:53 -0400 | [diff] [blame] | 49 | typedef void (*grpc_udp_server_read_cb)(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, |
vjpai | aea3207 | 2016-03-18 12:22:59 -0700 | [diff] [blame] | 50 | struct grpc_server *server); |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 51 | |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 52 | /* Called when the grpc_fd is about to be orphaned (and the FD closed). */ |
| 53 | typedef void (*grpc_udp_server_orphan_cb)(grpc_fd *emfd); |
| 54 | |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 55 | /* Create a server, initially not bound to any ports */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 56 | grpc_udp_server *grpc_udp_server_create(void); |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 57 | |
| 58 | /* Start listening to bound ports */ |
Robbie Shade | 109a8dc | 2015-09-25 15:18:49 -0400 | [diff] [blame] | 59 | void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *udp_server, |
Robbie Shade | 147fe70 | 2015-09-25 15:04:40 -0400 | [diff] [blame] | 60 | grpc_pollset **pollsets, size_t pollset_count, |
vjpai | aea3207 | 2016-03-18 12:22:59 -0700 | [diff] [blame] | 61 | struct grpc_server *server); |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 62 | |
Robbie Shade | 956f1d3 | 2016-08-02 16:55:00 -0400 | [diff] [blame] | 63 | int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned port_index); |
Robbie Shade | 3d4fc4a | 2015-08-04 19:20:00 -0400 | [diff] [blame] | 64 | |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 65 | /* Add a port to the server, returning port number on success, or negative |
| 66 | on failure. |
| 67 | |
| 68 | The :: and 0.0.0.0 wildcard addresses are treated identically, accepting |
| 69 | both IPv4 and IPv6 connections, but :: is the preferred style. This usually |
| 70 | creates one socket, but possibly two on systems which support IPv6, |
| 71 | but not dualstack sockets. */ |
| 72 | |
| 73 | /* TODO(ctiller): deprecate this, and make grpc_udp_server_add_ports to handle |
| 74 | all of the multiple socket port matching logic in one place */ |
murgatroid99 | 22d50e9 | 2016-10-12 09:54:49 -0700 | [diff] [blame] | 75 | int grpc_udp_server_add_port(grpc_udp_server *s, |
| 76 | const grpc_resolved_address *addr, |
murgatroid99 | aa9c578 | 2016-10-10 12:16:13 -0700 | [diff] [blame] | 77 | grpc_udp_server_read_cb read_cb, |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 78 | grpc_udp_server_orphan_cb orphan_cb); |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 79 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 80 | void grpc_udp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_udp_server *server, |
| 81 | grpc_closure *on_done); |
Robbie Shade | a4e21a1 | 2015-07-10 14:16:31 -0400 | [diff] [blame] | 82 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 83 | #endif /* GRPC_CORE_LIB_IOMGR_UDP_SERVER_H */ |