• 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 {
28 
29 class ChannelArguments;
30 
31 #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
32 
CreateInsecureChannelFromFd(const std::string & target,int fd)33 std::shared_ptr<Channel> CreateInsecureChannelFromFd(const std::string& target,
34                                                      int fd) {
35   grpc::internal::GrpcLibrary init_lib;
36   init_lib.init();
37   return CreateChannelInternal(
38       "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr),
39       std::vector<
40           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
41 }
42 
CreateCustomInsecureChannelFromFd(const std::string & target,int fd,const grpc::ChannelArguments & args)43 std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
44     const std::string& target, int fd, const grpc::ChannelArguments& args) {
45   internal::GrpcLibrary init_lib;
46   init_lib.init();
47   grpc_channel_args channel_args;
48   args.SetChannelArgs(&channel_args);
49   return CreateChannelInternal(
50       "",
51       grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
52       std::vector<
53           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
54 }
55 
56 namespace experimental {
57 
CreateCustomInsecureChannelWithInterceptorsFromFd(const std::string & target,int fd,const ChannelArguments & args,std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators)58 std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
59     const std::string& target, int fd, const ChannelArguments& args,
60     std::vector<
61         std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
62         interceptor_creators) {
63   grpc::internal::GrpcLibrary init_lib;
64   init_lib.init();
65   grpc_channel_args channel_args;
66   args.SetChannelArgs(&channel_args);
67   return CreateChannelInternal(
68       "",
69       grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
70       std::move(interceptor_creators));
71 }
72 
73 }  // namespace experimental
74 
75 #endif  // GPR_SUPPORT_CHANNELS_FROM_FD
76 
77 }  // namespace grpc
78