Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / deps / grpc / src / core / ext / transport / chttp2 / server / insecure / server_chttp2_posix.cc
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 #include <grpc/support/port_platform.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_posix.h>
23 #include <grpc/support/log.h>
24
25 #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
26
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/string_util.h>
29
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"
37
38 void grpc_server_add_insecure_channel_from_fd(grpc_server* server,
39                                               void* reserved, int fd) {
40   GPR_ASSERT(reserved == nullptr);
41
42   grpc_core::ExecCtx exec_ctx;
43   char* name;
44   gpr_asprintf(&name, "fd:%d", fd);
45
46   grpc_endpoint* server_endpoint =
47       grpc_tcp_create(grpc_fd_create(fd, name, true),
48                       grpc_server_get_channel_args(server), name);
49
50   gpr_free(name);
51
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 */);
55
56   grpc_pollset** pollsets;
57   size_t num_pollsets = 0;
58   grpc_server_get_pollsets(server, &pollsets, &num_pollsets);
59
60   for (size_t i = 0; i < num_pollsets; i++) {
61     grpc_endpoint_add_to_pollset(server_endpoint, pollsets[i]);
62   }
63
64   grpc_server_setup_transport(server, transport, nullptr, server_args, nullptr);
65   grpc_chttp2_transport_start_reading(transport, nullptr, nullptr);
66 }
67
68 #else  // !GPR_SUPPORT_CHANNELS_FROM_FD
69
70 void grpc_server_add_insecure_channel_from_fd(grpc_server* server,
71                                               void* reserved, int fd) {
72   GPR_ASSERT(0);
73 }
74
75 #endif  // GPR_SUPPORT_CHANNELS_FROM_FD