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 typedef struct grpc_tcp_listener grpc_tcp_listener;
28 typedef struct grpc_custom_tcp_connect grpc_custom_tcp_connect;
30 typedef struct grpc_custom_socket {
31 // Implementation defined
33 grpc_endpoint* endpoint;
34 grpc_tcp_listener* listener;
35 grpc_custom_tcp_connect* connector;
39 typedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket,
41 typedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket,
43 typedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket,
44 size_t nread, grpc_error* error);
45 typedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket,
46 grpc_custom_socket* client,
48 typedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket);
50 typedef struct grpc_socket_vtable {
51 grpc_error* (*init)(grpc_custom_socket* socket, int domain);
52 void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr,
53 size_t len, grpc_custom_connect_callback cb);
54 void (*destroy)(grpc_custom_socket* socket);
55 void (*shutdown)(grpc_custom_socket* socket);
56 void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb);
57 void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices,
58 grpc_custom_write_callback cb);
59 void (*read)(grpc_custom_socket* socket, char* buffer, size_t length,
60 grpc_custom_read_callback cb);
61 grpc_error* (*getpeername)(grpc_custom_socket* socket,
62 const grpc_sockaddr* addr, int* len);
63 grpc_error* (*getsockname)(grpc_custom_socket* socket,
64 const grpc_sockaddr* addr, int* len);
65 grpc_error* (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr,
66 size_t len, int flags);
67 grpc_error* (*listen)(grpc_custom_socket* socket);
68 void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client,
69 grpc_custom_accept_callback cb);
73 void grpc_custom_endpoint_init(grpc_socket_vtable* impl);
75 void grpc_custom_close_server_callback(grpc_tcp_listener* listener);
77 grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket,
78 grpc_resource_quota* resource_quota,
81 #endif /* GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H */