create_channel_posix.cc 2.4 KB

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