3 * Copyright 2018 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H
20 #define GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H
22 #include <grpc/support/port_platform.h>
24 #include "src/core/lib/iomgr/endpoint.h"
25 #include "src/core/lib/iomgr/sockaddr.h"
27 // Same number as the micro of SO_REUSEPORT in kernel
28 #define GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT (0x00000200u)
30 typedef struct grpc_tcp_listener grpc_tcp_listener;
31 typedef struct grpc_custom_tcp_connect grpc_custom_tcp_connect;
33 typedef struct grpc_custom_socket {
34 // Implementation defined
36 grpc_endpoint* endpoint;
37 grpc_tcp_listener* listener;
38 grpc_custom_tcp_connect* connector;
42 typedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket,
43 grpc_error_handle error);
44 typedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket,
45 grpc_error_handle error);
46 typedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket,
48 grpc_error_handle error);
49 typedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket,
50 grpc_custom_socket* client,
51 grpc_error_handle error);
52 typedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket);
54 typedef struct grpc_socket_vtable {
55 grpc_error_handle (*init)(grpc_custom_socket* socket, int domain);
56 void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr,
57 size_t len, grpc_custom_connect_callback cb);
58 void (*destroy)(grpc_custom_socket* socket);
59 void (*shutdown)(grpc_custom_socket* socket);
60 void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb);
61 void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices,
62 grpc_custom_write_callback cb);
63 void (*read)(grpc_custom_socket* socket, char* buffer, size_t length,
64 grpc_custom_read_callback cb);
65 grpc_error_handle (*getpeername)(grpc_custom_socket* socket,
66 const grpc_sockaddr* addr, int* len);
67 grpc_error_handle (*getsockname)(grpc_custom_socket* socket,
68 const grpc_sockaddr* addr, int* len);
69 grpc_error_handle (*bind)(grpc_custom_socket* socket,
70 const grpc_sockaddr* addr, size_t len, int flags);
71 grpc_error_handle (*listen)(grpc_custom_socket* socket);
72 void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client,
73 grpc_custom_accept_callback cb);
77 void grpc_custom_endpoint_init(grpc_socket_vtable* impl);
79 void grpc_custom_close_server_callback(grpc_tcp_listener* listener);
81 grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket,
82 grpc_resource_quota* resource_quota,
83 const char* peer_string);
85 #endif /* GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H */