blob: ac70124727479e82ff86cc1bd38c3290a5276977 [file] [log] [blame]
Robbie Shadea4e21a12015-07-10 14:16:31 -04001/*
2 *
Robbie Shade3d14fd62016-01-28 11:30:42 -05003 * Copyright 2015-2016, Google Inc.
Robbie Shadea4e21a12015-07-10 14:16:31 -04004 * 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 Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_IOMGR_UDP_SERVER_H
35#define GRPC_CORE_LIB_IOMGR_UDP_SERVER_H
Robbie Shadea4e21a12015-07-10 14:16:31 -040036
37#include "src/core/iomgr/endpoint.h"
Craig Tiller69b093b2016-02-25 19:04:07 -080038#include "src/core/iomgr/fd_posix.h"
Robbie Shadea4e21a12015-07-10 14:16:31 -040039
vjpaiaea32072016-03-18 12:22:59 -070040/* Forward decl of struct grpc_server */
41/* This is not typedef'ed to avoid a typedef-redefinition error */
42struct grpc_server;
Robbie Shade147fe702015-09-25 15:04:40 -040043
Robbie Shadea4e21a12015-07-10 14:16:31 -040044/* Forward decl of grpc_udp_server */
45typedef struct grpc_udp_server grpc_udp_server;
46
Robbie Shadea4e21a12015-07-10 14:16:31 -040047/* Called when data is available to read from the socket. */
Robbie Shadec6787b22015-10-07 10:13:53 -040048typedef void (*grpc_udp_server_read_cb)(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
vjpaiaea32072016-03-18 12:22:59 -070049 struct grpc_server *server);
Robbie Shadea4e21a12015-07-10 14:16:31 -040050
51/* Create a server, initially not bound to any ports */
Craig Tillera82950e2015-09-22 12:33:20 -070052grpc_udp_server *grpc_udp_server_create(void);
Robbie Shadea4e21a12015-07-10 14:16:31 -040053
54/* Start listening to bound ports */
Robbie Shade109a8dc2015-09-25 15:18:49 -040055void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *udp_server,
Robbie Shade147fe702015-09-25 15:04:40 -040056 grpc_pollset **pollsets, size_t pollset_count,
vjpaiaea32072016-03-18 12:22:59 -070057 struct grpc_server *server);
Robbie Shadea4e21a12015-07-10 14:16:31 -040058
Craig Tillera82950e2015-09-22 12:33:20 -070059int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index);
Robbie Shade3d4fc4a2015-08-04 19:20:00 -040060
Robbie Shadea4e21a12015-07-10 14:16:31 -040061/* Add a port to the server, returning port number on success, or negative
62 on failure.
63
64 The :: and 0.0.0.0 wildcard addresses are treated identically, accepting
65 both IPv4 and IPv6 connections, but :: is the preferred style. This usually
66 creates one socket, but possibly two on systems which support IPv6,
67 but not dualstack sockets. */
68
69/* TODO(ctiller): deprecate this, and make grpc_udp_server_add_ports to handle
70 all of the multiple socket port matching logic in one place */
Craig Tillera82950e2015-09-22 12:33:20 -070071int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
72 size_t addr_len, grpc_udp_server_read_cb read_cb);
Robbie Shadea4e21a12015-07-10 14:16:31 -040073
Craig Tillera82950e2015-09-22 12:33:20 -070074void grpc_udp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_udp_server *server,
75 grpc_closure *on_done);
Robbie Shadea4e21a12015-07-10 14:16:31 -040076
Craig Tiller9a4dddd2016-03-25 17:08:13 -070077#endif /* GRPC_CORE_LIB_IOMGR_UDP_SERVER_H */