3 * Copyright 2016 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 #include <grpc/support/port_platform.h>
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_posix.h>
23 #include <grpc/support/log.h>
25 #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/string_util.h>
30 #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
31 #include "src/core/lib/channel/channel_args.h"
32 #include "src/core/lib/iomgr/endpoint.h"
33 #include "src/core/lib/iomgr/exec_ctx.h"
34 #include "src/core/lib/iomgr/tcp_posix.h"
35 #include "src/core/lib/surface/completion_queue.h"
36 #include "src/core/lib/surface/server.h"
38 void grpc_server_add_insecure_channel_from_fd(grpc_server* server,
39 void* reserved, int fd) {
40 GPR_ASSERT(reserved == nullptr);
42 grpc_core::ExecCtx exec_ctx;
44 gpr_asprintf(&name, "fd:%d", fd);
46 grpc_endpoint* server_endpoint =
47 grpc_tcp_create(grpc_fd_create(fd, name, true),
48 grpc_server_get_channel_args(server), name);
52 const grpc_channel_args* server_args = grpc_server_get_channel_args(server);
53 grpc_transport* transport = grpc_create_chttp2_transport(
54 server_args, server_endpoint, false /* is_client */);
56 grpc_pollset** pollsets;
57 size_t num_pollsets = 0;
58 grpc_server_get_pollsets(server, &pollsets, &num_pollsets);
60 for (size_t i = 0; i < num_pollsets; i++) {
61 grpc_endpoint_add_to_pollset(server_endpoint, pollsets[i]);
64 grpc_server_setup_transport(server, transport, nullptr, server_args, nullptr);
65 grpc_chttp2_transport_start_reading(transport, nullptr, nullptr);
68 #else // !GPR_SUPPORT_CHANNELS_FROM_FD
70 void grpc_server_add_insecure_channel_from_fd(grpc_server* server,
71 void* reserved, int fd) {
75 #endif // GPR_SUPPORT_CHANNELS_FROM_FD