• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/grpc.h>
20 #include <grpc/grpc_posix.h>
21 #include <grpcpp/channel.h>
22 #include <grpcpp/impl/grpc_library.h>
23 #include <grpcpp/support/channel_arguments.h>
24 
25 #include "src/cpp/client/create_channel_internal.h"
26 
27 namespace grpc_impl {
28 
29 class ChannelArguments;
30 }  // namespace grpc_impl
31 
32 namespace grpc {
33 
34 #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
35 
CreateInsecureChannelFromFd(const std::string & target,int fd)36 std::shared_ptr<Channel> CreateInsecureChannelFromFd(const std::string& target,
37                                                      int fd) {
38   grpc::internal::GrpcLibrary init_lib;
39   init_lib.init();
40   return CreateChannelInternal(
41       "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr),
42       std::vector<
43           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
44 }
45 
CreateCustomInsecureChannelFromFd(const std::string & target,int fd,const grpc::ChannelArguments & args)46 std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
47     const std::string& target, int fd, const grpc::ChannelArguments& args) {
48   internal::GrpcLibrary init_lib;
49   init_lib.init();
50   grpc_channel_args channel_args;
51   args.SetChannelArgs(&channel_args);
52   return CreateChannelInternal(
53       "",
54       grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
55       std::vector<
56           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
57 }
58 
59 namespace experimental {
60 
CreateCustomInsecureChannelWithInterceptorsFromFd(const std::string & target,int fd,const ChannelArguments & args,std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators)61 std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
62     const std::string& target, int fd, const ChannelArguments& args,
63     std::vector<
64         std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
65         interceptor_creators) {
66   grpc::internal::GrpcLibrary init_lib;
67   init_lib.init();
68   grpc_channel_args channel_args;
69   args.SetChannelArgs(&channel_args);
70   return CreateChannelInternal(
71       "",
72       grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
73       std::move(interceptor_creators));
74 }
75 
76 }  // namespace experimental
77 
78 #endif  // GPR_SUPPORT_CHANNELS_FROM_FD
79 
80 }  // namespace grpc
81