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/grpc.h>
20 #include <grpc/grpc_posix.h>
21 #include <grpcpp/channel.h>
22 #include <grpcpp/create_channel.h>
23 #include <grpcpp/impl/grpc_library.h>
25 #include "src/cpp/client/create_channel_internal.h"
29 #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
31 std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd(
32 const grpc::string& target, int fd) {
33 grpc::internal::GrpcLibrary init_lib;
35 return grpc::CreateChannelInternal(
36 "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr),
37 std::vector<std::unique_ptr<
38 grpc::experimental::ClientInterceptorFactoryInterface>>());
41 std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelFromFd(
42 const grpc::string& target, int fd, const grpc::ChannelArguments& args) {
43 grpc::internal::GrpcLibrary init_lib;
45 grpc_channel_args channel_args;
46 args.SetChannelArgs(&channel_args);
47 return grpc::CreateChannelInternal(
49 grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
50 std::vector<std::unique_ptr<
51 grpc::experimental::ClientInterceptorFactoryInterface>>());
54 namespace experimental {
56 std::shared_ptr<grpc::Channel>
57 CreateCustomInsecureChannelWithInterceptorsFromFd(
58 const grpc::string& target, int fd, const grpc::ChannelArguments& args,
60 std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
61 interceptor_creators) {
62 grpc::internal::GrpcLibrary init_lib;
64 grpc_channel_args channel_args;
65 args.SetChannelArgs(&channel_args);
66 return grpc::CreateChannelInternal(
68 grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
69 std::move(interceptor_creators));
72 } // namespace experimental
74 #endif // GPR_SUPPORT_CHANNELS_FROM_FD
76 } // namespace grpc_impl