create_channel_posix.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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++/channel.h>
  19. #include <grpc++/create_channel.h>
  20. #include <grpc++/impl/grpc_library.h>
  21. #include <grpc/grpc.h>
  22. #include <grpc/grpc_posix.h>
  23. #include "src/cpp/client/create_channel_internal.h"
  24. namespace grpc {
  25. #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
  26. std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
  27. int fd) {
  28. internal::GrpcLibrary init_lib;
  29. init_lib.init();
  30. return CreateChannelInternal(
  31. "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr));
  32. }
  33. std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
  34. const grpc::string& target, int fd, const ChannelArguments& args) {
  35. internal::GrpcLibrary init_lib;
  36. init_lib.init();
  37. grpc_channel_args channel_args;
  38. args.SetChannelArgs(&channel_args);
  39. return CreateChannelInternal("", grpc_insecure_channel_create_from_fd(
  40. target.c_str(), fd, &channel_args));
  41. }
  42. #endif // GPR_SUPPORT_CHANNELS_FROM_FD
  43. } // namespace grpc