From dbdc6e4ae619225a555849569f04af5575a5f99f Mon Sep 17 00:00:00 2001
From: Adam Czachorowski <adamcz@google.com>
Date: Fri, 9 Sep 2016 11:32:09 +0200
Subject: [PATCH] Add method for creating insecure channel from FD with custom
 arguments using C++ API.

This was already supported in C API.
---
 include/grpc++/create_channel_posix.h  | 10 ++++++++++
 src/cpp/client/create_channel_posix.cc | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/grpc++/create_channel_posix.h b/include/grpc++/create_channel_posix.h
index 0d96159942..2af12e6c36 100644
--- a/include/grpc++/create_channel_posix.h
+++ b/include/grpc++/create_channel_posix.h
@@ -37,6 +37,7 @@
 #include <memory>
 
 #include <grpc++/channel.h>
+#include <grpc++/support/channel_arguments.h>
 #include <grpc/support/port_platform.h>
 
 namespace grpc {
@@ -50,6 +51,15 @@ namespace grpc {
 std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
                                                      int fd);
 
+/// Create a new \a Channel communicating over given file descriptor with custom
+/// channel arguments
+///
+/// \param target The name of the target.
+/// \param fd The file descriptor representing a socket.
+/// \param args Options for channel creation.
+std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
+    const grpc::string& target, int fd, const ChannelArguments& args);
+
 #endif  // GPR_SUPPORT_CHANNELS_FROM_FD
 
 }  // namespace grpc
diff --git a/src/cpp/client/create_channel_posix.cc b/src/cpp/client/create_channel_posix.cc
index 60cfed3d62..eb323ac50b 100644
--- a/src/cpp/client/create_channel_posix.cc
+++ b/src/cpp/client/create_channel_posix.cc
@@ -51,6 +51,16 @@ std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
       "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr));
 }
 
+std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
+    const grpc::string& target, int fd, const ChannelArguments& args) {
+  internal::GrpcLibrary init_lib;
+  init_lib.init();
+  grpc_channel_args channel_args;
+  args.SetChannelArgs(&channel_args);
+  return CreateChannelInternal("", grpc_insecure_channel_create_from_fd(
+                                       target.c_str(), fd, &channel_args));
+}
+
 #endif  // GPR_SUPPORT_CHANNELS_FROM_FD
 
 }  // namespace grpc
-- 
GitLab