Merge branch 'master' into grpc_namespace_channel_arguments

pull/18831/head
Karthik Ravi Shankar 6 years ago
commit f01997b377
  1. 88
      BUILD
  2. 14
      BUILD.gn
  3. 75
      CMakeLists.txt
  4. 85
      Makefile
  5. 40
      WORKSPACE
  6. 24
      bazel/grpc_build_system.bzl
  7. 16
      bazel/grpc_python_deps.bzl
  8. 35
      build.yaml
  9. 4
      doc/PROTOCOL-HTTP2.md
  10. 3
      doc/g_stands_for.md
  11. 119
      examples/BUILD
  12. 4
      examples/cpp/helloworld/greeter_async_client.cc
  13. 4
      examples/cpp/helloworld/greeter_async_client2.cc
  14. 4
      examples/cpp/helloworld/greeter_async_server.cc
  15. 31
      examples/cpp/route_guide/helper.cc
  16. 4
      examples/cpp/route_guide/route_guide_client.cc
  17. 13
      examples/cpp/route_guide/route_guide_server.cc
  18. 56
      examples/python/errors/BUILD.bazel
  19. 107
      examples/python/errors/README.md
  20. 56
      examples/python/errors/client.py
  21. 90
      examples/python/errors/server.py
  22. 54
      examples/python/errors/test/_error_handling_example_test.py
  23. 18
      gRPC-C++.podspec
  24. 37
      gRPC-Core.podspec
  25. 8
      gRPC-ProtoRPC.podspec
  26. 2
      gRPC-RxLibrary.podspec
  27. 9
      gRPC.podspec
  28. 4
      grpc.gemspec
  29. 2
      include/grpc/impl/codegen/port_platform.h
  30. 58
      include/grpcpp/create_channel.h
  31. 79
      include/grpcpp/create_channel_impl.h
  32. 46
      include/grpcpp/create_channel_posix.h
  33. 70
      include/grpcpp/create_channel_posix_impl.h
  34. 13
      include/grpcpp/ext/channelz_service_plugin.h
  35. 41
      include/grpcpp/ext/channelz_service_plugin_impl.h
  36. 31
      include/grpcpp/ext/proto_server_reflection_plugin.h
  37. 55
      include/grpcpp/ext/proto_server_reflection_plugin_impl.h
  38. 30
      include/grpcpp/ext/server_load_reporting.h
  39. 54
      include/grpcpp/ext/server_load_reporting_impl.h
  40. 78
      include/grpcpp/generic/generic_stub.h
  41. 108
      include/grpcpp/generic/generic_stub_impl.h
  42. 39
      include/grpcpp/health_check_service_interface.h
  43. 55
      include/grpcpp/health_check_service_interface_impl.h
  44. 16
      include/grpcpp/impl/codegen/server_callback.h
  45. 7
      include/grpcpp/impl/codegen/server_interface.h
  46. 19
      include/grpcpp/impl/server_builder_option.h
  47. 43
      include/grpcpp/impl/server_builder_option_impl.h
  48. 9
      include/grpcpp/impl/server_builder_plugin.h
  49. 31
      include/grpcpp/impl/server_initializer.h
  50. 57
      include/grpcpp/impl/server_initializer_impl.h
  51. 31
      include/grpcpp/opencensus.h
  52. 51
      include/grpcpp/opencensus_impl.h
  53. 45
      include/grpcpp/resource_quota.h
  54. 68
      include/grpcpp/resource_quota_impl.h
  55. 37
      include/grpcpp/security/auth_metadata_processor.h
  56. 61
      include/grpcpp/security/auth_metadata_processor_impl.h
  57. 36
      include/grpcpp/security/credentials.h
  58. 66
      include/grpcpp/security/server_credentials.h
  59. 85
      include/grpcpp/security/server_credentials_impl.h
  60. 13
      include/grpcpp/server.h
  61. 22
      include/grpcpp/server_builder.h
  62. 14
      include/grpcpp/server_posix.h
  63. 42
      include/grpcpp/server_posix_impl.h
  64. 5
      include/grpcpp/support/channel_arguments.h
  65. 22
      include/grpcpp/support/error_details.h
  66. 48
      include/grpcpp/support/error_details_impl.h
  67. 6
      package.xml
  68. 16
      src/compiler/objective_c_generator.cc
  69. 541
      src/core/ext/filters/client_channel/client_channel.cc
  70. 28
      src/core/ext/filters/client_channel/health/health_check_client.cc
  71. 12
      src/core/ext/filters/client_channel/health/health_check_client.h
  72. 7
      src/core/ext/filters/client_channel/lb_policy.cc
  73. 15
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  74. 8
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc
  75. 20
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h
  76. 4
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc
  77. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h
  78. 27
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  79. 535
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  80. 24
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  81. 6
      src/core/ext/transport/chttp2/transport/internal.h
  82. 13
      src/core/lib/gpr/time_posix.cc
  83. 2
      src/core/lib/gprpp/fork.cc
  84. 419
      src/core/lib/gprpp/map.h
  85. 38
      src/core/lib/gprpp/pair.h
  86. 7
      src/core/lib/iomgr/cfstream_handle.cc
  87. 1
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  88. 5
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  89. 17
      src/core/lib/security/security_connector/ssl/ssl_security_connector.cc
  90. 2
      src/core/lib/surface/init.cc
  91. 2
      src/core/lib/surface/version.cc
  92. 16
      src/core/lib/transport/transport.cc
  93. 26
      src/core/lib/transport/transport.h
  94. 7
      src/cpp/client/channel_cc.cc
  95. 40
      src/cpp/client/create_channel.cc
  96. 39
      src/cpp/client/create_channel_posix.cc
  97. 82
      src/cpp/client/generic_stub.cc
  98. 2
      src/cpp/common/channel_arguments.cc
  99. 4
      src/cpp/common/resource_quota_cc.cc
  100. 2
      src/cpp/common/version_cc.cc
  101. Some files were not shown because too many files have changed in this diff Show More

88
BUILD

@ -74,11 +74,11 @@ config_setting(
)
# This should be updated along with build.yaml
g_stands_for = "godric"
g_stands_for = "gandalf"
core_version = "7.0.0"
version = "1.20.0-dev"
version = "1.21.0-dev"
GPR_PUBLIC_HDRS = [
"include/grpc/support/alloc.h",
@ -192,8 +192,8 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpc++/impl/service_type.h",
"include/grpc++/impl/sync_cxx11.h",
"include/grpc++/impl/sync_no_cxx11.h",
"include/grpc++/resource_quota.h",
"include/grpc++/security/auth_context.h",
"include/grpc++/resource_quota.h",
"include/grpc++/security/auth_metadata_processor.h",
"include/grpc++/security/credentials.h",
"include/grpc++/security/server_credentials.h",
@ -219,12 +219,16 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/client_context.h",
"include/grpcpp/completion_queue.h",
"include/grpcpp/create_channel.h",
"include/grpcpp/create_channel_impl.h",
"include/grpcpp/create_channel_posix.h",
"include/grpcpp/create_channel_posix_impl.h",
"include/grpcpp/ext/health_check_service_server_builder_option.h",
"include/grpcpp/generic/async_generic_service.h",
"include/grpcpp/generic/generic_stub.h",
"include/grpcpp/generic/generic_stub_impl.h",
"include/grpcpp/grpcpp.h",
"include/grpcpp/health_check_service_interface.h",
"include/grpcpp/health_check_service_interface_impl.h",
"include/grpcpp/impl/call.h",
"include/grpcpp/impl/channel_argument_option.h",
"include/grpcpp/impl/client_unary_call.h",
@ -235,20 +239,26 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/impl/rpc_service_method.h",
"include/grpcpp/impl/serialization_traits.h",
"include/grpcpp/impl/server_builder_option.h",
"include/grpcpp/impl/server_builder_option_impl.h",
"include/grpcpp/impl/server_builder_plugin.h",
"include/grpcpp/impl/server_initializer.h",
"include/grpcpp/impl/server_initializer_impl.h",
"include/grpcpp/impl/service_type.h",
"include/grpcpp/impl/sync_cxx11.h",
"include/grpcpp/impl/sync_no_cxx11.h",
"include/grpcpp/resource_quota.h",
"include/grpcpp/resource_quota_impl.h",
"include/grpcpp/security/auth_context.h",
"include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",
"include/grpcpp/server_posix.h",
"include/grpcpp/server_posix_impl.h",
"include/grpcpp/support/async_stream.h",
"include/grpcpp/support/async_unary_call.h",
"include/grpcpp/support/byte_buffer.h",
@ -308,7 +318,6 @@ grpc_cc_library(
public_hdrs = GRPC_PUBLIC_HDRS + GRPC_SECURE_PUBLIC_HDRS,
standalone = True,
deps = [
"grpc_cfstream",
"grpc_common",
"grpc_lb_policy_grpclb_secure",
"grpc_lb_policy_xds_secure",
@ -362,7 +371,6 @@ grpc_cc_library(
"gpr",
"grpc",
"grpc++_base",
"grpc_cfstream",
"grpc++_codegen_base",
"grpc++_codegen_base_src",
"grpc++_codegen_proto",
@ -396,6 +404,7 @@ grpc_cc_library(
hdrs = [
"include/grpc++/support/error_details.h",
"include/grpcpp/support/error_details.h",
"include/grpcpp/support/error_details_impl.h",
],
language = "c++",
standalone = True,
@ -579,8 +588,10 @@ grpc_cc_library(
"src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mutex_lock.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/profiling/timers.h",
],
@ -726,12 +737,15 @@ grpc_cc_library(
"src/core/lib/http/parser.cc",
"src/core/lib/iomgr/buffer_list.cc",
"src/core/lib/iomgr/call_combiner.cc",
"src/core/lib/iomgr/cfstream_handle.cc",
"src/core/lib/iomgr/combiner.cc",
"src/core/lib/iomgr/endpoint.cc",
"src/core/lib/iomgr/endpoint_cfstream.cc",
"src/core/lib/iomgr/endpoint_pair_posix.cc",
"src/core/lib/iomgr/endpoint_pair_uv.cc",
"src/core/lib/iomgr/endpoint_pair_windows.cc",
"src/core/lib/iomgr/error.cc",
"src/core/lib/iomgr/error_cfstream.cc",
"src/core/lib/iomgr/ev_epoll1_linux.cc",
"src/core/lib/iomgr/ev_epollex_linux.cc",
"src/core/lib/iomgr/ev_poll_posix.cc",
@ -752,6 +766,7 @@ grpc_cc_library(
"src/core/lib/iomgr/iomgr_custom.cc",
"src/core/lib/iomgr/iomgr_internal.cc",
"src/core/lib/iomgr/iomgr_posix.cc",
"src/core/lib/iomgr/iomgr_posix_cfstream.cc",
"src/core/lib/iomgr/iomgr_windows.cc",
"src/core/lib/iomgr/is_epollexclusive_available.cc",
"src/core/lib/iomgr/load_file.cc",
@ -778,6 +793,7 @@ grpc_cc_library(
"src/core/lib/iomgr/socket_utils_windows.cc",
"src/core/lib/iomgr/socket_windows.cc",
"src/core/lib/iomgr/tcp_client.cc",
"src/core/lib/iomgr/tcp_client_cfstream.cc",
"src/core/lib/iomgr/tcp_client_custom.cc",
"src/core/lib/iomgr/tcp_client_posix.cc",
"src/core/lib/iomgr/tcp_client_windows.cc",
@ -877,12 +893,15 @@ grpc_cc_library(
"src/core/lib/iomgr/block_annotate.h",
"src/core/lib/iomgr/buffer_list.h",
"src/core/lib/iomgr/call_combiner.h",
"src/core/lib/iomgr/cfstream_handle.h",
"src/core/lib/iomgr/closure.h",
"src/core/lib/iomgr/combiner.h",
"src/core/lib/iomgr/dynamic_annotations.h",
"src/core/lib/iomgr/endpoint.h",
"src/core/lib/iomgr/endpoint_cfstream.h",
"src/core/lib/iomgr/endpoint_pair.h",
"src/core/lib/iomgr/error.h",
"src/core/lib/iomgr/error_cfstream.h",
"src/core/lib/iomgr/error_internal.h",
"src/core/lib/iomgr/ev_epoll1_linux.h",
"src/core/lib/iomgr/ev_epollex_linux.h",
@ -1037,27 +1056,6 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "grpc_cfstream",
srcs = [
"src/core/lib/iomgr/cfstream_handle.cc",
"src/core/lib/iomgr/endpoint_cfstream.cc",
"src/core/lib/iomgr/error_cfstream.cc",
"src/core/lib/iomgr/iomgr_posix_cfstream.cc",
"src/core/lib/iomgr/tcp_client_cfstream.cc",
],
hdrs = [
"src/core/lib/iomgr/cfstream_handle.h",
"src/core/lib/iomgr/endpoint_cfstream.h",
"src/core/lib/iomgr/error_cfstream.h",
],
use_cfstream = True,
deps = [
":gpr_base",
":grpc_base",
],
)
grpc_cc_library(
name = "grpc_client_channel",
srcs = [
@ -1477,6 +1475,7 @@ grpc_cc_library(
language = "c++",
public_hdrs = [
"include/grpcpp/ext/server_load_reporting.h",
"include/grpcpp/ext/server_load_reporting_impl.h",
],
deps = [
"lb_server_load_reporting_filter",
@ -2201,6 +2200,7 @@ grpc_cc_library(
public_hdrs = [
"include/grpc++/ext/proto_server_reflection_plugin.h",
"include/grpcpp/ext/proto_server_reflection_plugin.h",
"include/grpcpp/ext/proto_server_reflection_plugin_impl.h",
],
deps = [
":grpc++",
@ -2221,6 +2221,7 @@ grpc_cc_library(
language = "c++",
public_hdrs = [
"include/grpcpp/ext/channelz_service_plugin.h",
"include/grpcpp/ext/channelz_service_plugin_impl.h",
],
deps = [
":grpc++",
@ -2285,6 +2286,7 @@ grpc_cc_library(
],
hdrs = [
"include/grpcpp/opencensus.h",
"include/grpcpp/opencensus_impl.h",
"src/cpp/ext/filters/census/channel_filter.h",
"src/cpp/ext/filters/census/client_filter.h",
"src/cpp/ext/filters/census/context.h",
@ -2318,34 +2320,34 @@ grpc_cc_library(
name = "envoy_ads_upb",
srcs = [
"src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/cds.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/cds.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/eds.upb.c",
"src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c",
"src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c",
],
hdrs = [
"src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/cds.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/cds.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/eds.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h",
"src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
language = "c++",
deps = [
":envoy_core_upb",
":envoy_type_upb",
":google_api_upb",
":proto_gen_validate_upb",
]
],
)
grpc_cc_library(
@ -2366,15 +2368,16 @@ grpc_cc_library(
"src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h",
"src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
language = "c++",
tags = ["no_windows"],
deps = [
":envoy_type_upb",
":google_api_upb",
":proto_gen_validate_upb"
]
":proto_gen_validate_upb",
],
)
grpc_cc_library(
@ -2387,14 +2390,15 @@ grpc_cc_library(
"src/core/ext/upb-generated/envoy/type/percent.upb.h",
"src/core/ext/upb-generated/envoy/type/range.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
language = "c++",
tags = ["no_windows"],
deps = [
":google_api_upb",
":proto_gen_validate_upb"
]
":proto_gen_validate_upb",
],
)
grpc_cc_library(
@ -2407,13 +2411,14 @@ grpc_cc_library(
"src/core/ext/upb-generated/gogoproto/gogo.upb.h",
"src/core/ext/upb-generated/validate/validate.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
language = "c++",
tags = ["no_windows"],
deps = [
":google_api_upb",
]
],
)
grpc_cc_library(
@ -2442,10 +2447,11 @@ grpc_cc_library(
"src/core/ext/upb-generated/google/protobuf/wrappers.upb.h",
"src/core/ext/upb-generated/google/rpc/status.upb.h",
],
language = "c++",
external_deps = [
"upb_lib",
],
language = "c++",
tags = ["no_windows"],
)
grpc_generate_one_off_targets()

@ -184,8 +184,10 @@ config("grpc_config") {
"src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mutex_lock.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
@ -1004,12 +1006,16 @@ config("grpc_config") {
"include/grpcpp/client_context.h",
"include/grpcpp/completion_queue.h",
"include/grpcpp/create_channel.h",
"include/grpcpp/create_channel_impl.h",
"include/grpcpp/create_channel_posix.h",
"include/grpcpp/create_channel_posix_impl.h",
"include/grpcpp/ext/health_check_service_server_builder_option.h",
"include/grpcpp/generic/async_generic_service.h",
"include/grpcpp/generic/generic_stub.h",
"include/grpcpp/generic/generic_stub_impl.h",
"include/grpcpp/grpcpp.h",
"include/grpcpp/health_check_service_interface.h",
"include/grpcpp/health_check_service_interface_impl.h",
"include/grpcpp/impl/call.h",
"include/grpcpp/impl/channel_argument_option.h",
"include/grpcpp/impl/client_unary_call.h",
@ -1066,18 +1072,24 @@ config("grpc_config") {
"include/grpcpp/impl/rpc_service_method.h",
"include/grpcpp/impl/serialization_traits.h",
"include/grpcpp/impl/server_builder_option.h",
"include/grpcpp/impl/server_builder_option_impl.h",
"include/grpcpp/impl/server_builder_plugin.h",
"include/grpcpp/impl/server_initializer.h",
"include/grpcpp/impl/server_initializer_impl.h",
"include/grpcpp/impl/service_type.h",
"include/grpcpp/resource_quota.h",
"include/grpcpp/resource_quota_impl.h",
"include/grpcpp/security/auth_context.h",
"include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",
"include/grpcpp/server_posix.h",
"include/grpcpp/server_posix_impl.h",
"include/grpcpp/support/async_stream.h",
"include/grpcpp/support/async_unary_call.h",
"include/grpcpp/support/byte_buffer.h",
@ -1143,10 +1155,12 @@ config("grpc_config") {
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/inlined_vector.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mutex_lock.h",
"src/core/lib/gprpp/optional.h",
"src/core/lib/gprpp/orphanable.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/ref_counted.h",
"src/core/lib/gprpp/ref_counted_ptr.h",
"src/core/lib/gprpp/thd.h",

@ -24,7 +24,7 @@
cmake_minimum_required(VERSION 2.8)
set(PACKAGE_NAME "grpc")
set(PACKAGE_VERSION "1.20.0-dev")
set(PACKAGE_VERSION "1.21.0-dev")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
@ -631,6 +631,7 @@ add_dependencies(buildtests_cxx generic_end2end_test)
add_dependencies(buildtests_cxx golden_file_test)
add_dependencies(buildtests_cxx grpc_alts_credentials_options_test)
add_dependencies(buildtests_cxx grpc_cli)
add_dependencies(buildtests_cxx grpc_core_map_test)
add_dependencies(buildtests_cxx grpc_linux_system_roots_test)
add_dependencies(buildtests_cxx grpc_tool_test)
add_dependencies(buildtests_cxx grpclb_api_test)
@ -2999,12 +3000,16 @@ foreach(_hdr
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
include/grpcpp/create_channel_impl.h
include/grpcpp/create_channel_posix.h
include/grpcpp/create_channel_posix_impl.h
include/grpcpp/ext/health_check_service_server_builder_option.h
include/grpcpp/generic/async_generic_service.h
include/grpcpp/generic/generic_stub.h
include/grpcpp/generic/generic_stub_impl.h
include/grpcpp/grpcpp.h
include/grpcpp/health_check_service_interface.h
include/grpcpp/health_check_service_interface_impl.h
include/grpcpp/impl/call.h
include/grpcpp/impl/channel_argument_option.h
include/grpcpp/impl/client_unary_call.h
@ -3015,18 +3020,24 @@ foreach(_hdr
include/grpcpp/impl/rpc_service_method.h
include/grpcpp/impl/serialization_traits.h
include/grpcpp/impl/server_builder_option.h
include/grpcpp/impl/server_builder_option_impl.h
include/grpcpp/impl/server_builder_plugin.h
include/grpcpp/impl/server_initializer.h
include/grpcpp/impl/server_initializer_impl.h
include/grpcpp/impl/service_type.h
include/grpcpp/resource_quota.h
include/grpcpp/resource_quota_impl.h
include/grpcpp/security/auth_context.h
include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h
include/grpcpp/server_posix.h
include/grpcpp/server_posix_impl.h
include/grpcpp/support/async_stream.h
include/grpcpp/support/async_unary_call.h
include/grpcpp/support/byte_buffer.h
@ -3590,12 +3601,16 @@ foreach(_hdr
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
include/grpcpp/create_channel_impl.h
include/grpcpp/create_channel_posix.h
include/grpcpp/create_channel_posix_impl.h
include/grpcpp/ext/health_check_service_server_builder_option.h
include/grpcpp/generic/async_generic_service.h
include/grpcpp/generic/generic_stub.h
include/grpcpp/generic/generic_stub_impl.h
include/grpcpp/grpcpp.h
include/grpcpp/health_check_service_interface.h
include/grpcpp/health_check_service_interface_impl.h
include/grpcpp/impl/call.h
include/grpcpp/impl/channel_argument_option.h
include/grpcpp/impl/client_unary_call.h
@ -3606,18 +3621,24 @@ foreach(_hdr
include/grpcpp/impl/rpc_service_method.h
include/grpcpp/impl/serialization_traits.h
include/grpcpp/impl/server_builder_option.h
include/grpcpp/impl/server_builder_option_impl.h
include/grpcpp/impl/server_builder_plugin.h
include/grpcpp/impl/server_initializer.h
include/grpcpp/impl/server_initializer_impl.h
include/grpcpp/impl/service_type.h
include/grpcpp/resource_quota.h
include/grpcpp/resource_quota_impl.h
include/grpcpp/security/auth_context.h
include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h
include/grpcpp/server_posix.h
include/grpcpp/server_posix_impl.h
include/grpcpp/support/async_stream.h
include/grpcpp/support/async_unary_call.h
include/grpcpp/support/byte_buffer.h
@ -3825,6 +3846,7 @@ target_link_libraries(grpc++_error_details
foreach(_hdr
include/grpc++/support/error_details.h
include/grpcpp/support/error_details.h
include/grpcpp/support/error_details_impl.h
)
string(REPLACE "include/" "" _path ${_hdr})
get_filename_component(_path ${_path} PATH)
@ -3958,6 +3980,7 @@ target_link_libraries(grpc++_reflection
foreach(_hdr
include/grpc++/ext/proto_server_reflection_plugin.h
include/grpcpp/ext/proto_server_reflection_plugin.h
include/grpcpp/ext/proto_server_reflection_plugin_impl.h
)
string(REPLACE "include/" "" _path ${_hdr})
get_filename_component(_path ${_path} PATH)
@ -4553,12 +4576,16 @@ foreach(_hdr
include/grpcpp/client_context.h
include/grpcpp/completion_queue.h
include/grpcpp/create_channel.h
include/grpcpp/create_channel_impl.h
include/grpcpp/create_channel_posix.h
include/grpcpp/create_channel_posix_impl.h
include/grpcpp/ext/health_check_service_server_builder_option.h
include/grpcpp/generic/async_generic_service.h
include/grpcpp/generic/generic_stub.h
include/grpcpp/generic/generic_stub_impl.h
include/grpcpp/grpcpp.h
include/grpcpp/health_check_service_interface.h
include/grpcpp/health_check_service_interface_impl.h
include/grpcpp/impl/call.h
include/grpcpp/impl/channel_argument_option.h
include/grpcpp/impl/client_unary_call.h
@ -4569,18 +4596,24 @@ foreach(_hdr
include/grpcpp/impl/rpc_service_method.h
include/grpcpp/impl/serialization_traits.h
include/grpcpp/impl/server_builder_option.h
include/grpcpp/impl/server_builder_option_impl.h
include/grpcpp/impl/server_builder_plugin.h
include/grpcpp/impl/server_initializer.h
include/grpcpp/impl/server_initializer_impl.h
include/grpcpp/impl/service_type.h
include/grpcpp/resource_quota.h
include/grpcpp/resource_quota_impl.h
include/grpcpp/security/auth_context.h
include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h
include/grpcpp/server_posix.h
include/grpcpp/server_posix_impl.h
include/grpcpp/support/async_stream.h
include/grpcpp/support/async_unary_call.h
include/grpcpp/support/byte_buffer.h
@ -4965,6 +4998,7 @@ target_link_libraries(grpcpp_channelz
foreach(_hdr
include/grpcpp/ext/channelz_service_plugin.h
include/grpcpp/ext/channelz_service_plugin_impl.h
)
string(REPLACE "include/" "" _path ${_hdr})
get_filename_component(_path ${_path} PATH)
@ -13455,6 +13489,45 @@ target_link_libraries(grpc_cli
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(grpc_core_map_test
test/core/gprpp/map_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(grpc_core_map_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(grpc_core_map_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc++
grpc
gpr
${_gRPC_GFLAGS_LIBRARIES}
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_CODEGEN)

@ -460,8 +460,8 @@ Q = @
endif
CORE_VERSION = 7.0.0
CPP_VERSION = 1.20.0-dev
CSHARP_VERSION = 1.20.0-dev
CPP_VERSION = 1.21.0-dev
CSHARP_VERSION = 1.21.0-dev
CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
@ -1209,6 +1209,7 @@ generic_end2end_test: $(BINDIR)/$(CONFIG)/generic_end2end_test
golden_file_test: $(BINDIR)/$(CONFIG)/golden_file_test
grpc_alts_credentials_options_test: $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test
grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli
grpc_core_map_test: $(BINDIR)/$(CONFIG)/grpc_core_map_test
grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin
grpc_csharp_plugin: $(BINDIR)/$(CONFIG)/grpc_csharp_plugin
grpc_linux_system_roots_test: $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test
@ -1680,6 +1681,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/golden_file_test \
$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \
$(BINDIR)/$(CONFIG)/grpc_cli \
$(BINDIR)/$(CONFIG)/grpc_core_map_test \
$(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \
$(BINDIR)/$(CONFIG)/grpc_tool_test \
$(BINDIR)/$(CONFIG)/grpclb_api_test \
@ -1821,6 +1823,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/golden_file_test \
$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \
$(BINDIR)/$(CONFIG)/grpc_cli \
$(BINDIR)/$(CONFIG)/grpc_core_map_test \
$(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \
$(BINDIR)/$(CONFIG)/grpc_tool_test \
$(BINDIR)/$(CONFIG)/grpclb_api_test \
@ -2311,6 +2314,8 @@ test_cxx: buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/golden_file_test || ( echo test golden_file_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_alts_credentials_options_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test || ( echo test grpc_alts_credentials_options_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_core_map_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_core_map_test || ( echo test grpc_core_map_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_linux_system_roots_test"
$(Q) $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test || ( echo test grpc_linux_system_roots_test failed ; exit 1 )
$(E) "[RUN] Testing grpc_tool_test"
@ -5326,12 +5331,16 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
include/grpcpp/create_channel_impl.h \
include/grpcpp/create_channel_posix.h \
include/grpcpp/create_channel_posix_impl.h \
include/grpcpp/ext/health_check_service_server_builder_option.h \
include/grpcpp/generic/async_generic_service.h \
include/grpcpp/generic/generic_stub.h \
include/grpcpp/generic/generic_stub_impl.h \
include/grpcpp/grpcpp.h \
include/grpcpp/health_check_service_interface.h \
include/grpcpp/health_check_service_interface_impl.h \
include/grpcpp/impl/call.h \
include/grpcpp/impl/channel_argument_option.h \
include/grpcpp/impl/client_unary_call.h \
@ -5342,18 +5351,24 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/rpc_service_method.h \
include/grpcpp/impl/serialization_traits.h \
include/grpcpp/impl/server_builder_option.h \
include/grpcpp/impl/server_builder_option_impl.h \
include/grpcpp/impl/server_builder_plugin.h \
include/grpcpp/impl/server_initializer.h \
include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \
include/grpcpp/server_posix.h \
include/grpcpp/server_posix_impl.h \
include/grpcpp/support/async_stream.h \
include/grpcpp/support/async_unary_call.h \
include/grpcpp/support/byte_buffer.h \
@ -5925,12 +5940,16 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
include/grpcpp/create_channel_impl.h \
include/grpcpp/create_channel_posix.h \
include/grpcpp/create_channel_posix_impl.h \
include/grpcpp/ext/health_check_service_server_builder_option.h \
include/grpcpp/generic/async_generic_service.h \
include/grpcpp/generic/generic_stub.h \
include/grpcpp/generic/generic_stub_impl.h \
include/grpcpp/grpcpp.h \
include/grpcpp/health_check_service_interface.h \
include/grpcpp/health_check_service_interface_impl.h \
include/grpcpp/impl/call.h \
include/grpcpp/impl/channel_argument_option.h \
include/grpcpp/impl/client_unary_call.h \
@ -5941,18 +5960,24 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/rpc_service_method.h \
include/grpcpp/impl/serialization_traits.h \
include/grpcpp/impl/server_builder_option.h \
include/grpcpp/impl/server_builder_option_impl.h \
include/grpcpp/impl/server_builder_plugin.h \
include/grpcpp/impl/server_initializer.h \
include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \
include/grpcpp/server_posix.h \
include/grpcpp/server_posix_impl.h \
include/grpcpp/support/async_stream.h \
include/grpcpp/support/async_unary_call.h \
include/grpcpp/support/byte_buffer.h \
@ -6166,6 +6191,7 @@ LIBGRPC++_ERROR_DETAILS_SRC = \
PUBLIC_HEADERS_CXX += \
include/grpc++/support/error_details.h \
include/grpcpp/support/error_details.h \
include/grpcpp/support/error_details_impl.h \
LIBGRPC++_ERROR_DETAILS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_ERROR_DETAILS_SRC))))
@ -6292,6 +6318,7 @@ LIBGRPC++_REFLECTION_SRC = \
PUBLIC_HEADERS_CXX += \
include/grpc++/ext/proto_server_reflection_plugin.h \
include/grpcpp/ext/proto_server_reflection_plugin.h \
include/grpcpp/ext/proto_server_reflection_plugin_impl.h \
LIBGRPC++_REFLECTION_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_REFLECTION_SRC))))
@ -6837,12 +6864,16 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/client_context.h \
include/grpcpp/completion_queue.h \
include/grpcpp/create_channel.h \
include/grpcpp/create_channel_impl.h \
include/grpcpp/create_channel_posix.h \
include/grpcpp/create_channel_posix_impl.h \
include/grpcpp/ext/health_check_service_server_builder_option.h \
include/grpcpp/generic/async_generic_service.h \
include/grpcpp/generic/generic_stub.h \
include/grpcpp/generic/generic_stub_impl.h \
include/grpcpp/grpcpp.h \
include/grpcpp/health_check_service_interface.h \
include/grpcpp/health_check_service_interface_impl.h \
include/grpcpp/impl/call.h \
include/grpcpp/impl/channel_argument_option.h \
include/grpcpp/impl/client_unary_call.h \
@ -6853,18 +6884,24 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/rpc_service_method.h \
include/grpcpp/impl/serialization_traits.h \
include/grpcpp/impl/server_builder_option.h \
include/grpcpp/impl/server_builder_option_impl.h \
include/grpcpp/impl/server_builder_plugin.h \
include/grpcpp/impl/server_initializer.h \
include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \
include/grpcpp/server_posix.h \
include/grpcpp/server_posix_impl.h \
include/grpcpp/support/async_stream.h \
include/grpcpp/support/async_unary_call.h \
include/grpcpp/support/byte_buffer.h \
@ -7218,6 +7255,7 @@ LIBGRPCPP_CHANNELZ_SRC = \
PUBLIC_HEADERS_CXX += \
include/grpcpp/ext/channelz_service_plugin.h \
include/grpcpp/ext/channelz_service_plugin_impl.h \
LIBGRPCPP_CHANNELZ_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPCPP_CHANNELZ_SRC))))
@ -16421,6 +16459,49 @@ endif
endif
GRPC_CORE_MAP_TEST_SRC = \
test/core/gprpp/map_test.cc \
GRPC_CORE_MAP_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CORE_MAP_TEST_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/grpc_core_map_test: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
$(BINDIR)/$(CONFIG)/grpc_core_map_test: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/grpc_core_map_test: $(PROTOBUF_DEP) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/grpc_core_map_test
endif
endif
$(OBJDIR)/$(CONFIG)/test/core/gprpp/map_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_grpc_core_map_test: $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep)
endif
endif
GRPC_CPP_PLUGIN_SRC = \
src/compiler/cpp_plugin.cc \

@ -17,20 +17,13 @@ register_toolchains(
"//third_party/toolchains:cc-toolchain-clang-x86_64-default",
)
http_archive(
name = "cython",
build_file = "//third_party:cython.BUILD",
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
urls = [
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
# TODO(https://github.com/grpc/grpc/issues/18331): Move off of this dependency.
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/ghostwriternr/rules_protobuf",
tag = "v0.8.2.1-alpha",
)
load("//third_party/py:python_configure.bzl", "python_configure")
python_configure(name = "local_config_python")
git_repository(
name = "io_bazel_rules_python",
commit = "8b5d0683a7d878b28fffe464779c8a53659fc645",
@ -39,24 +32,21 @@ git_repository(
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
pip_repositories()
pip_import(
name = "grpc_python_dependencies",
requirements = "//:requirements.bazel.txt",
)
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
pip_install()
# NOTE(https://github.com/pubref/rules_protobuf/pull/196): Switch to upstream repo after this gets merged.
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/ghostwriternr/rules_protobuf",
tag = "v0.8.2.1-alpha",
http_archive(
name = "cython",
build_file = "//third_party:cython.BUILD",
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
urls = [
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
)
load("@org_pubref_rules_protobuf//python:rules.bzl", "py_proto_repositories")
load("//bazel:grpc_python_deps.bzl", "grpc_python_deps")
py_proto_repositories()
grpc_python_deps()

@ -80,7 +80,8 @@ def grpc_cc_library(
visibility = None,
alwayslink = 0,
data = [],
use_cfstream = False):
use_cfstream = False,
tags = []):
copts = []
if use_cfstream:
copts = if_mac(["-DGRPC_CFSTREAM"])
@ -117,6 +118,7 @@ def grpc_cc_library(
],
alwayslink = alwayslink,
data = data,
tags = tags,
)
def grpc_proto_plugin(name, srcs = [], deps = []):
@ -149,7 +151,6 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
if language.upper() == "C":
copts = copts + if_not_windows(["-std=c99"])
args = {
"name": name,
"srcs": srcs,
"args": args,
"data": data,
@ -161,7 +162,17 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
"exec_compatible_with": exec_compatible_with,
}
if uses_polling:
native.cc_test(testonly = True, tags = ["manual"], **args)
# Only run targets with pollers for non-MSVC
# TODO(yfen): Enable MSVC for poller-enabled targets without pollers
native.cc_test(
name = name,
testonly = True,
tags = [
"manual",
"no_windows",
],
**args
)
for poller in POLLERS:
native.sh_test(
name = name + "@poller=" + poller,
@ -175,13 +186,13 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
poller,
"$(location %s)" % name,
] + args["args"],
tags = tags,
tags = (tags + ["no_windows"]),
exec_compatible_with = exec_compatible_with,
)
else:
native.cc_test(**args)
native.cc_test(tags = tags, **args)
def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = []):
def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = [], tags = []):
copts = []
if language.upper() == "C":
copts = ["-std=c99"]
@ -195,6 +206,7 @@ def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], da
deps = deps + _get_external_deps(external_deps),
copts = copts,
linkopts = if_not_windows(["-pthread"]) + linkopts,
tags = tags,
)
def grpc_generate_one_off_targets():

@ -0,0 +1,16 @@
load("//third_party/py:python_configure.bzl", "python_configure")
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
load("@org_pubref_rules_protobuf//python:rules.bzl", "py_proto_repositories")
def grpc_python_deps():
# TODO(https://github.com/grpc/grpc/issues/18256): Remove conditional.
if hasattr(native, "http_archive"):
python_configure(name = "local_config_python")
pip_repositories()
pip_install()
py_proto_repositories()
else:
print("Building Python gRPC with bazel 23.0+ is disabled pending " +
"resolution of https://github.com/grpc/grpc/issues/18256.")

@ -13,8 +13,8 @@ settings:
'#09': Per-language overrides are possible with (eg) ruby_version tag here
'#10': See the expand_version.py for all the quirks here
core_version: 7.0.0
g_stands_for: godric
version: 1.20.0-dev
g_stands_for: gandalf
version: 1.21.0-dev
filegroups:
- name: alts_proto
headers:
@ -194,8 +194,10 @@ filegroups:
- src/core/lib/gprpp/atomic.h
- src/core/lib/gprpp/fork.h
- src/core/lib/gprpp/manual_constructor.h
- src/core/lib/gprpp/map.h
- src/core/lib/gprpp/memory.h
- src/core/lib/gprpp/mutex_lock.h
- src/core/lib/gprpp/pair.h
- src/core/lib/gprpp/thd.h
- src/core/lib/profiling/timers.h
uses:
@ -1344,12 +1346,16 @@ filegroups:
- include/grpcpp/client_context.h
- include/grpcpp/completion_queue.h
- include/grpcpp/create_channel.h
- include/grpcpp/create_channel_impl.h
- include/grpcpp/create_channel_posix.h
- include/grpcpp/create_channel_posix_impl.h
- include/grpcpp/ext/health_check_service_server_builder_option.h
- include/grpcpp/generic/async_generic_service.h
- include/grpcpp/generic/generic_stub.h
- include/grpcpp/generic/generic_stub_impl.h
- include/grpcpp/grpcpp.h
- include/grpcpp/health_check_service_interface.h
- include/grpcpp/health_check_service_interface_impl.h
- include/grpcpp/impl/call.h
- include/grpcpp/impl/channel_argument_option.h
- include/grpcpp/impl/client_unary_call.h
@ -1360,18 +1366,24 @@ filegroups:
- include/grpcpp/impl/rpc_service_method.h
- include/grpcpp/impl/serialization_traits.h
- include/grpcpp/impl/server_builder_option.h
- include/grpcpp/impl/server_builder_option_impl.h
- include/grpcpp/impl/server_builder_plugin.h
- include/grpcpp/impl/server_initializer.h
- include/grpcpp/impl/server_initializer_impl.h
- include/grpcpp/impl/service_type.h
- include/grpcpp/resource_quota.h
- include/grpcpp/resource_quota_impl.h
- include/grpcpp/security/auth_context.h
- include/grpcpp/security/auth_metadata_processor.h
- include/grpcpp/security/auth_metadata_processor_impl.h
- include/grpcpp/security/credentials.h
- include/grpcpp/security/server_credentials.h
- include/grpcpp/security/server_credentials_impl.h
- include/grpcpp/server.h
- include/grpcpp/server_builder.h
- include/grpcpp/server_context.h
- include/grpcpp/server_posix.h
- include/grpcpp/server_posix_impl.h
- include/grpcpp/support/async_stream.h
- include/grpcpp/support/async_unary_call.h
- include/grpcpp/support/byte_buffer.h
@ -1714,6 +1726,7 @@ libs:
public_headers:
- include/grpc++/support/error_details.h
- include/grpcpp/support/error_details.h
- include/grpcpp/support/error_details_impl.h
src:
- src/proto/grpc/status/status.proto
- src/cpp/util/error_details.cc
@ -1739,6 +1752,7 @@ libs:
public_headers:
- include/grpc++/ext/proto_server_reflection_plugin.h
- include/grpcpp/ext/proto_server_reflection_plugin.h
- include/grpcpp/ext/proto_server_reflection_plugin_impl.h
headers:
- src/cpp/ext/proto_server_reflection.h
src:
@ -1917,6 +1931,7 @@ libs:
language: c++
public_headers:
- include/grpcpp/ext/channelz_service_plugin.h
- include/grpcpp/ext/channelz_service_plugin_impl.h
headers:
- src/cpp/server/channelz/channelz_service.h
src:
@ -4735,6 +4750,22 @@ targets:
- grpc
- gpr
- grpc++_test_config
- name: grpc_core_map_test
gtest: true
build: test
language: c++
headers:
- test/core/gprpp/map_tester.h
src:
- test/core/gprpp/map_test.cc
deps:
- grpc_test_util
- grpc++
- grpc
- gpr
uses:
- grpc++_test
uses_polling: false
- name: grpc_cpp_plugin
build: protoc
language: c++

@ -61,6 +61,8 @@ the form shown above.
If **Timeout** is omitted a server should assume an infinite timeout. Client implementations are free to send a default minimum timeout based on their deployment requirements.
If **Content-Type** does not begin with "application/grpc", gRPC servers SHOULD respond with HTTP status of 415 (Unsupported Media Type). This will prevent other HTTP/2 clients from interpreting a gRPC error response, which uses status 200 (OK), as successful.
**Custom-Metadata** is an arbitrary set of key-value pairs defined by the application layer. Header names starting with "grpc-" but not listed here are reserved for future GRPC use and should not be used by applications as **Custom-Metadata**.
Note that HTTP2 does not allow arbitrary octet sequences for header values so binary header values must be encoded using Base64 as per https://tools.ietf.org/html/rfc4648#section-4. Implementations MUST accept padded and un-padded values and should emit un-padded values. Applications define binary headers by having their names end with "-bin". Runtime libraries use this suffix to detect binary headers and properly apply base64 encoding & decoding as headers are sent and received.
@ -255,5 +257,3 @@ to be used.
* **Service-Name** → ?( {_proto package name_} "." ) {_service name_}
* **Message-Type** → {_fully qualified proto message name_}
* **Content-Type** → "application/grpc+proto"

@ -19,4 +19,5 @@
- 1.17 'g' stands for ['gizmo'](https://github.com/grpc/grpc/tree/v1.17.x)
- 1.18 'g' stands for ['goose'](https://github.com/grpc/grpc/tree/v1.18.x)
- 1.19 'g' stands for ['gold'](https://github.com/grpc/grpc/tree/v1.19.x)
- 1.20 'g' stands for ['godric'](https://github.com/grpc/grpc/tree/master)
- 1.20 'g' stands for ['godric'](https://github.com/grpc/grpc/tree/v1.20.x)
- 1.21 'g' stands for ['gandalf'](https://github.com/grpc/grpc/tree/master)

@ -16,7 +16,9 @@ licenses(["notice"]) # 3-clause BSD
package(default_visibility = ["//visibility:public"])
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library")
load("@org_pubref_rules_protobuf//python:rules.bzl", "py_proto_library")
grpc_proto_library(
name = "auth_sample",
@ -43,60 +45,121 @@ grpc_proto_library(
srcs = ["protos/keyvaluestore.proto"],
)
py_proto_library(
name = "py_helloworld",
protos = ["protos/helloworld.proto"],
with_grpc = True,
deps = [requirement('protobuf'),],
)
cc_binary(
name = "greeter_client",
srcs = ["cpp/helloworld/greeter_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "greeter_async_client",
srcs = ["cpp/helloworld/greeter_async_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "greeter_async_client2",
srcs = ["cpp/helloworld/greeter_async_client2.cc"],
defines = ["BAZEL_BUILD"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "greeter_server",
srcs = ["cpp/helloworld/greeter_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "greeter_async_server",
srcs = ["cpp/helloworld/greeter_async_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "metadata_client",
srcs = ["cpp/metadata/greeter_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "metadata_server",
srcs = ["cpp/metadata/greeter_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "lb_client",
srcs = ["cpp/load_balancing/greeter_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "lb_server",
srcs = ["cpp/load_balancing/greeter_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "compression_client",
srcs = ["cpp/compression/greeter_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
name = "compression_server",
srcs = ["cpp/compression/greeter_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [":helloworld", "//:grpc++"],
deps = [
":helloworld",
"//:grpc++",
],
)
cc_binary(
@ -104,12 +167,48 @@ cc_binary(
srcs = ["cpp/keyvaluestore/caching_interceptor.h",
"cpp/keyvaluestore/client.cc"],
defines = ["BAZEL_BUILD"],
deps = [":keyvaluestore", "//:grpc++"],
deps = [
":keyvaluestore",
"//:grpc++",
],
)
cc_binary(
name = "keyvaluestore_server",
srcs = ["cpp/keyvaluestore/server.cc"],
defines = ["BAZEL_BUILD"],
deps = [":keyvaluestore", "//:grpc++"],
deps = [
":keyvaluestore",
"//:grpc++",
],
)
cc_binary(
name = "route_guide_client",
srcs = [
"cpp/route_guide/helper.cc",
"cpp/route_guide/helper.h",
"cpp/route_guide/route_guide_client.cc",
],
data = ["cpp/route_guide/route_guide_db.json"],
defines = ["BAZEL_BUILD"],
deps = [
":route_guide",
"//:grpc++",
],
)
cc_binary(
name = "route_guide_server",
srcs = [
"cpp/route_guide/helper.cc",
"cpp/route_guide/helper.h",
"cpp/route_guide/route_guide_server.cc",
],
data = ["cpp/route_guide/route_guide_db.json"],
defines = ["BAZEL_BUILD"],
deps = [
":route_guide",
"//:grpc++",
],
)

@ -23,7 +23,11 @@
#include <grpcpp/grpcpp.h>
#include <grpc/support/log.h>
#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif
using grpc::Channel;
using grpc::ClientAsyncResponseReader;

@ -24,7 +24,11 @@
#include <grpc/support/log.h>
#include <thread>
#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif
using grpc::Channel;
using grpc::ClientAsyncResponseReader;

@ -24,7 +24,11 @@
#include <grpcpp/grpcpp.h>
#include <grpc/support/log.h>
#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif
using grpc::Server;
using grpc::ServerAsyncResponseWriter;

@ -23,7 +23,11 @@
#include <sstream>
#include <string>
#include <vector>
#ifdef BAZEL_BUILD
#include "examples/protos/route_guide.grpc.pb.h"
#else
#include "route_guide.grpc.pb.h"
#endif
namespace routeguide {
@ -35,13 +39,16 @@ std::string GetDbFileContent(int argc, char** argv) {
size_t start_position = argv_1.find(arg_str);
if (start_position != std::string::npos) {
start_position += arg_str.size();
if (argv_1[start_position] == ' ' ||
argv_1[start_position] == '=') {
if (argv_1[start_position] == ' ' || argv_1[start_position] == '=') {
db_path = argv_1.substr(start_position + 1);
}
}
} else {
#ifdef BAZEL_BUILD
db_path = "cpp/route_guide/route_guide_db.json";
#else
db_path = "route_guide_db.json";
#endif
}
std::ifstream db_file(db_path);
if (!db_file.is_open()) {
@ -60,17 +67,13 @@ class Parser {
public:
explicit Parser(const std::string& db) : db_(db) {
// Remove all spaces.
db_.erase(
std::remove_if(db_.begin(), db_.end(), isspace),
db_.end());
db_.erase(std::remove_if(db_.begin(), db_.end(), isspace), db_.end());
if (!Match("[")) {
SetFailedAndReturnFalse();
}
}
bool Finished() {
return current_ >= db_.size();
}
bool Finished() { return current_ >= db_.size(); }
bool TryParseOne(Feature* feature) {
if (failed_ || Finished() || !Match("{")) {
@ -96,7 +99,7 @@ class Parser {
if (current_ == db_.size()) {
return SetFailedAndReturnFalse();
}
feature->set_name(db_.substr(name_start, current_-name_start-1));
feature->set_name(db_.substr(name_start, current_ - name_start - 1));
if (!Match("},")) {
if (db_[current_ - 1] == ']' && current_ == db_.size()) {
return true;
@ -107,7 +110,6 @@ class Parser {
}
private:
bool SetFailedAndReturnFalse() {
failed_ = true;
return false;
@ -121,7 +123,8 @@ class Parser {
void ReadLong(long* l) {
size_t start = current_;
while (current_ != db_.size() && db_[current_] != ',' && db_[current_] != '}') {
while (current_ != db_.size() && db_[current_] != ',' &&
db_[current_] != '}') {
current_++;
}
// It will throw an exception if fails.
@ -154,10 +157,8 @@ void ParseDb(const std::string& db, std::vector<Feature>* feature_list) {
break;
}
}
std::cout << "DB parsed, loaded " << feature_list->size()
<< " features." << std::endl;
std::cout << "DB parsed, loaded " << feature_list->size() << " features."
<< std::endl;
}
} // namespace routeguide

@ -29,7 +29,11 @@
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
#include "helper.h"
#ifdef BAZEL_BUILD
#include "examples/protos/route_guide.grpc.pb.h"
#else
#include "route_guide.grpc.pb.h"
#endif
using grpc::Channel;
using grpc::ClientContext;

@ -29,7 +29,11 @@
#include <grpcpp/server_context.h>
#include <grpcpp/security/server_credentials.h>
#include "helper.h"
#ifdef BAZEL_BUILD
#include "examples/protos/route_guide.grpc.pb.h"
#else
#include "route_guide.grpc.pb.h"
#endif
using grpc::Server;
using grpc::ServerBuilder;
@ -147,24 +151,25 @@ class RouteGuideImpl final : public RouteGuide::Service {
Status RouteChat(ServerContext* context,
ServerReaderWriter<RouteNote, RouteNote>* stream) override {
std::vector<RouteNote> received_notes;
RouteNote note;
while (stream->Read(&note)) {
for (const RouteNote& n : received_notes) {
std::unique_lock<std::mutex> lock(mu_);
for (const RouteNote& n : received_notes_) {
if (n.location().latitude() == note.location().latitude() &&
n.location().longitude() == note.location().longitude()) {
stream->Write(n);
}
}
received_notes.push_back(note);
received_notes_.push_back(note);
}
return Status::OK;
}
private:
std::vector<Feature> feature_list_;
std::mutex mu_;
std::vector<RouteNote> received_notes_;
};
void RunServer(const std::string& db_path) {

@ -0,0 +1,56 @@
# Copyright 2019 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
py_library(
name = "client",
testonly = 1,
srcs = ["client.py"],
deps = [
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_status/grpc_status:grpc_status",
"//examples:py_helloworld",
requirement('googleapis-common-protos'),
],
)
py_library(
name = "server",
testonly = 1,
srcs = ["server.py"],
deps = [
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_status/grpc_status:grpc_status",
"//examples:py_helloworld",
] + select({
"//conditions:default": [requirement("futures")],
"//:python3": [],
}),
)
py_test(
name = "test/_error_handling_example_test",
srcs = ["test/_error_handling_example_test.py"],
deps = [
":client",
":server",
"//src/python/grpcio_tests/tests:bazel_namespace_package_hack",
],
size = "small",
imports = [
"../../../src/python/grpcio_status",
"../../../src/python/grpcio_tests",
],
)

@ -0,0 +1,107 @@
# gRPC Python Error Handling Example
The goal of this example is sending error status from server that is more complicated than a code and detail string.
The definition for an RPC method in proto files contains request message and response message. There are many error states that can be shared across RPC methods (e.g. stack trace, insufficient quota). Using a different path to handle error will make the code more maintainable.
Ideally, the final status of an RPC should be described in the trailing headers of HTTP2, and gRPC Python provides helper functions in `grpcio-status` package to assist the packing and unpacking of error status.
### Requirement
```
grpcio>=1.18.0
grpcio-status>=1.18.0
googleapis-common-protos>=1.5.5
```
### Error Detail Proto
You may provide any custom proto message as error detail in your implementation. Here are protos are defined by Google Cloud Library Team:
* [code.proto]([https://github.com/googleapis/api-common-protos/blob/master/google/rpc/code.proto](https://github.com/googleapis/api-common-protos/blob/87185dfffad4afa5a33a8c153f0e1ea53b4f85dc/google/rpc/code.proto)) contains definition of RPC error codes.
* [error_details.proto]([https://github.com/googleapis/api-common-protos/blob/master/google/rpc/error_details.proto](https://github.com/googleapis/api-common-protos/blob/87185dfffad4afa5a33a8c153f0e1ea53b4f85dc/google/rpc/error_details.proto)) contains definitions of common error details.
### Definition of Status Proto
Here is the definition of Status proto. For full text, please see [status.proto](https://github.com/googleapis/api-common-protos/blob/87185dfffad4afa5a33a8c153f0e1ea53b4f85dc/google/rpc/status.proto).
```proto
// The `Status` type defines a logical error model that is suitable for different
// programming environments, including REST APIs and RPC APIs. It is used by
// [gRPC](https://github.com/grpc). The error model is designed to be:
//
// - Simple to use and understand for most users
// - Flexible enough to meet unexpected needs
//
// # Overview
//
// The `Status` message contains three pieces of data: error code, error message,
// and error details. The error code should be an enum value of
// [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The
// error message should be a developer-facing English message that helps
// developers *understand* and *resolve* the error. If a localized user-facing
// error message is needed, put the localized message in the error details or
// localize it in the client. The optional error details may contain arbitrary
// information about the error. There is a predefined set of error detail types
// in the package `google.rpc` that can be used for common error conditions.
//
// # Language mapping
//
// The `Status` message is the logical representation of the error model, but it
// is not necessarily the actual wire format. When the `Status` message is
// exposed in different client libraries and different wire protocols, it can be
// mapped differently. For example, it will likely be mapped to some exceptions
// in Java, but more likely mapped to some error codes in C.
//
// # Other uses
//
// The error model and the `Status` message can be used in a variety of
// environments, either with or without APIs, to provide a
// consistent developer experience across different environments.
//
// Example uses of this error model include:
//
// - Partial errors. If a service needs to return partial errors to the client,
// it may embed the `Status` in the normal response to indicate the partial
// errors.
//
// - Workflow errors. A typical workflow has multiple steps. Each step may
// have a `Status` message for error reporting.
//
// - Batch operations. If a client uses batch request and batch response, the
// `Status` message should be used directly inside batch response, one for
// each error sub-response.
//
// - Asynchronous operations. If an API call embeds asynchronous operation
// results in its response, the status of those operations should be
// represented directly using the `Status` message.
//
// - Logging. If some API errors are stored in logs, the message `Status` could
// be used directly after any stripping needed for security/privacy reasons.
message Status {
// The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
int32 code = 1;
// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
string message = 2;
// A list of messages that carry the error details. There is a common set of
// message types for APIs to use.
repeated google.protobuf.Any details = 3;
}
```
### Usage of Well-Known-Proto `Any`
Please check [ProtoBuf Document: Any](https://developers.google.com/protocol-buffers/docs/reference/python-generated#any)
```Python
any_message.Pack(message)
any_message.Unpack(message)
assert any_message.Is(message.DESCRIPTOR)
```

@ -0,0 +1,56 @@
# Copyright 2019 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example handles rich error status in client-side."""
from __future__ import print_function
import logging
import grpc
from grpc_status import rpc_status
from google.rpc import error_details_pb2
from examples.protos import helloworld_pb2
from examples.protos import helloworld_pb2_grpc
_LOGGER = logging.getLogger(__name__)
def process(stub):
try:
response = stub.SayHello(helloworld_pb2.HelloRequest(name='Alice'))
_LOGGER.info('Call success: %s', response.message)
except grpc.RpcError as rpc_error:
_LOGGER.error('Call failure: %s', rpc_error)
status = rpc_status.from_call(rpc_error)
for detail in status.details:
if detail.Is(error_details_pb2.QuotaFailure.DESCRIPTOR):
info = error_details_pb2.QuotaFailure()
detail.Unpack(info)
_LOGGER.error('Quota failure: %s', info)
else:
raise RuntimeError('Unexpected failure: %s' % detail)
def main():
# NOTE(gRPC Python Team): .close() is possible on a channel and should be
# used in circumstances in which the with statement does not fit the needs
# of the code.
with grpc.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
process(stub)
if __name__ == '__main__':
logging.basicConfig()
main()

@ -0,0 +1,90 @@
# Copyright 2019 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example sends out rich error status from server-side."""
from concurrent import futures
import time
import logging
import threading
import grpc
from grpc_status import rpc_status
from google.protobuf import any_pb2
from google.rpc import code_pb2, status_pb2, error_details_pb2
from examples.protos import helloworld_pb2
from examples.protos import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def create_greet_limit_exceed_error_status(name):
detail = any_pb2.Any()
detail.Pack(
error_details_pb2.QuotaFailure(
violations=[
error_details_pb2.QuotaFailure.Violation(
subject="name: %s" % name,
description="Limit one greeting per person",
)
],))
return status_pb2.Status(
code=code_pb2.RESOURCE_EXHAUSTED,
message='Request limit exceeded.',
details=[detail],
)
class LimitedGreeter(helloworld_pb2_grpc.GreeterServicer):
def __init__(self):
self._lock = threading.RLock()
self._greeted = set()
def SayHello(self, request, context):
with self._lock:
if request.name in self._greeted:
rich_status = create_greet_limit_exceed_error_status(
request.name)
context.abort_with_status(rpc_status.to_status(rich_status))
else:
self._greeted.add(request.name)
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
def create_server(server_address):
server = grpc.server(futures.ThreadPoolExecutor())
helloworld_pb2_grpc.add_GreeterServicer_to_server(LimitedGreeter(), server)
port = server.add_insecure_port(server_address)
return server, port
def serve(server):
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(None)
def main():
server, unused_port = create_server('[::]:50051')
serve(server)
if __name__ == '__main__':
logging.basicConfig()
main()

@ -0,0 +1,54 @@
# Copyright 2019 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests of the error handling example."""
# NOTE(lidiz) This module only exists in Bazel BUILD file, for more details
# please refer to comments in the "bazel_namespace_package_hack" module.
try:
from tests import bazel_namespace_package_hack
bazel_namespace_package_hack.sys_path_to_site_dir_hack()
except ImportError:
pass
import unittest
import logging
import grpc
from examples.protos import helloworld_pb2_grpc
from examples.python.errors import client as error_handling_client
from examples.python.errors import server as error_handling_server
class ErrorHandlingExampleTest(unittest.TestCase):
def setUp(self):
self._server, port = error_handling_server.create_server('[::]:0')
self._server.start()
self._channel = grpc.insecure_channel('localhost:%d' % port)
def tearDown(self):
self._channel.close()
self._server.stop(None)
def test_error_handling_example(self):
stub = helloworld_pb2_grpc.GreeterStub(self._channel)
error_handling_client.process(stub)
error_handling_client.process(stub)
# No unhandled exception raised, test passed!
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -23,7 +23,7 @@
Pod::Spec.new do |s|
s.name = 'gRPC-C++'
# TODO (mxyan): use version that match gRPC version when pod is stabilized
# version = '1.20.0-dev'
# version = '1.21.0-dev'
version = '0.0.8-dev'
s.version = version
s.summary = 'gRPC C++ library'
@ -31,7 +31,7 @@ Pod::Spec.new do |s|
s.license = 'Apache License, Version 2.0'
s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' }
grpc_version = '1.20.0-dev'
grpc_version = '1.21.0-dev'
s.source = {
:git => 'https://github.com/grpc/grpc.git',
@ -85,12 +85,16 @@ Pod::Spec.new do |s|
'include/grpcpp/client_context.h',
'include/grpcpp/completion_queue.h',
'include/grpcpp/create_channel.h',
'include/grpcpp/create_channel_impl.h',
'include/grpcpp/create_channel_posix.h',
'include/grpcpp/create_channel_posix_impl.h',
'include/grpcpp/ext/health_check_service_server_builder_option.h',
'include/grpcpp/generic/async_generic_service.h',
'include/grpcpp/generic/generic_stub.h',
'include/grpcpp/generic/generic_stub_impl.h',
'include/grpcpp/grpcpp.h',
'include/grpcpp/health_check_service_interface.h',
'include/grpcpp/health_check_service_interface_impl.h',
'include/grpcpp/impl/call.h',
'include/grpcpp/impl/channel_argument_option.h',
'include/grpcpp/impl/client_unary_call.h',
@ -101,18 +105,24 @@ Pod::Spec.new do |s|
'include/grpcpp/impl/rpc_service_method.h',
'include/grpcpp/impl/serialization_traits.h',
'include/grpcpp/impl/server_builder_option.h',
'include/grpcpp/impl/server_builder_option_impl.h',
'include/grpcpp/impl/server_builder_plugin.h',
'include/grpcpp/impl/server_initializer.h',
'include/grpcpp/impl/server_initializer_impl.h',
'include/grpcpp/impl/service_type.h',
'include/grpcpp/resource_quota.h',
'include/grpcpp/resource_quota_impl.h',
'include/grpcpp/security/auth_context.h',
'include/grpcpp/security/auth_metadata_processor.h',
'include/grpcpp/security/auth_metadata_processor_impl.h',
'include/grpcpp/security/credentials.h',
'include/grpcpp/security/server_credentials.h',
'include/grpcpp/security/server_credentials_impl.h',
'include/grpcpp/server.h',
'include/grpcpp/server_builder.h',
'include/grpcpp/server_context.h',
'include/grpcpp/server_posix.h',
'include/grpcpp/server_posix_impl.h',
'include/grpcpp/support/async_stream.h',
'include/grpcpp/support/async_unary_call.h',
'include/grpcpp/support/byte_buffer.h',
@ -253,8 +263,10 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mutex_lock.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/ext/transport/chttp2/transport/bin_decoder.h',
@ -568,8 +580,10 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mutex_lock.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/lib/avl/avl.h',

@ -22,7 +22,7 @@
Pod::Spec.new do |s|
s.name = 'gRPC-Core'
version = '1.20.0-dev'
version = '1.21.0-dev'
s.version = version
s.summary = 'Core cross-platform gRPC library, written in C'
s.homepage = 'https://grpc.io'
@ -208,8 +208,10 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mutex_lock.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/lib/gpr/alloc.cc',
@ -855,7 +857,15 @@ Pod::Spec.new do |s|
'src/core/ext/filters/http/client_authority_filter.cc',
'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc',
'src/core/ext/filters/workarounds/workaround_utils.cc',
'src/core/plugin_registry/grpc_plugin_registry.cc'
'src/core/plugin_registry/grpc_plugin_registry.cc',
'src/core/lib/iomgr/cfstream_handle.cc',
'src/core/lib/iomgr/endpoint_cfstream.cc',
'src/core/lib/iomgr/error_cfstream.cc',
'src/core/lib/iomgr/iomgr_posix_cfstream.cc',
'src/core/lib/iomgr/tcp_client_cfstream.cc',
'src/core/lib/iomgr/cfstream_handle.h',
'src/core/lib/iomgr/endpoint_cfstream.h',
'src/core/lib/iomgr/error_cfstream.h'
ss.private_header_files = 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
@ -877,8 +887,10 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mutex_lock.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/ext/transport/chttp2/transport/bin_decoder.h',
@ -1160,26 +1172,15 @@ Pod::Spec.new do |s|
'src/core/ext/filters/message_size/message_size_filter.h',
'src/core/ext/filters/http/client_authority_filter.h',
'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h',
'src/core/ext/filters/workarounds/workaround_utils.h'
'src/core/ext/filters/workarounds/workaround_utils.h',
'src/core/lib/iomgr/cfstream_handle.h',
'src/core/lib/iomgr/endpoint_cfstream.h',
'src/core/lib/iomgr/error_cfstream.h'
end
# CFStream is now default. Leaving this subspec only for compatibility purpose.
s.subspec 'CFStream-Implementation' do |ss|
ss.header_mappings_dir = '.'
ss.dependency "#{s.name}/Implementation", version
ss.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => 'GRPC_CFSTREAM=1'
}
ss.source_files = 'src/core/lib/iomgr/cfstream_handle.cc',
'src/core/lib/iomgr/endpoint_cfstream.cc',
'src/core/lib/iomgr/error_cfstream.cc',
'src/core/lib/iomgr/iomgr_posix_cfstream.cc',
'src/core/lib/iomgr/tcp_client_cfstream.cc',
'src/core/lib/iomgr/cfstream_handle.h',
'src/core/lib/iomgr/endpoint_cfstream.h',
'src/core/lib/iomgr/error_cfstream.h'
ss.private_header_files = 'src/core/lib/iomgr/cfstream_handle.h',
'src/core/lib/iomgr/endpoint_cfstream.h',
'src/core/lib/iomgr/error_cfstream.h'
end
s.subspec 'Cronet-Interface' do |ss|

@ -21,7 +21,7 @@
Pod::Spec.new do |s|
s.name = 'gRPC-ProtoRPC'
version = '1.20.0-dev'
version = '1.21.0-dev'
s.version = version
s.summary = 'RPC library for Protocol Buffers, based on gRPC'
s.homepage = 'https://grpc.io'
@ -53,12 +53,10 @@ Pod::Spec.new do |s|
ss.source_files = "#{src_dir}/*.{h,m}"
end
# CFStream is now default. Leaving this subspec only for compatibility purpose.
s.subspec 'CFStream' do |ss|
ss.dependency 'gRPC/CFStream', version
ss.dependency "#{s.name}/Main", version
ss.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => 'GRPC_CFSTREAM=1'
}
end
s.pod_target_xcconfig = {

@ -21,7 +21,7 @@
Pod::Spec.new do |s|
s.name = 'gRPC-RxLibrary'
version = '1.20.0-dev'
version = '1.21.0-dev'
s.version = version
s.summary = 'Reactive Extensions library for iOS/OSX.'
s.homepage = 'https://grpc.io'

@ -20,7 +20,7 @@
Pod::Spec.new do |s|
s.name = 'gRPC'
version = '1.20.0-dev'
version = '1.21.0-dev'
s.version = version
s.summary = 'gRPC client library for iOS/OSX'
s.homepage = 'https://grpc.io'
@ -64,14 +64,9 @@ Pod::Spec.new do |s|
ss.dependency 'gRPC-Core', version
end
# This subspec is mutually exclusive with the `Main` subspec
# CFStream is now default. Leaving this subspec only for compatibility purpose.
s.subspec 'CFStream' do |ss|
ss.dependency 'gRPC-Core/CFStream-Implementation', version
ss.dependency "#{s.name}/Main", version
ss.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => 'GRPC_CFSTREAM=1'
}
end
s.subspec 'GID' do |ss|

@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.add_dependency 'google-protobuf', '~> 3.7'
s.add_dependency 'googleapis-common-protos-types', '~> 1.0.0'
s.add_dependency 'googleapis-common-protos-types', '~> 1.0'
s.add_development_dependency 'bundler', '~> 1.9'
s.add_development_dependency 'facter', '~> 2.4'
@ -102,8 +102,10 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/atomic.h )
s.files += %w( src/core/lib/gprpp/fork.h )
s.files += %w( src/core/lib/gprpp/manual_constructor.h )
s.files += %w( src/core/lib/gprpp/map.h )
s.files += %w( src/core/lib/gprpp/memory.h )
s.files += %w( src/core/lib/gprpp/mutex_lock.h )
s.files += %w( src/core/lib/gprpp/pair.h )
s.files += %w( src/core/lib/gprpp/thd.h )
s.files += %w( src/core/lib/profiling/timers.h )
s.files += %w( src/core/lib/gpr/alloc.cc )

@ -193,6 +193,7 @@
#define GPR_PLATFORM_STRING "ios"
#define GPR_CPU_IPHONE 1
#define GPR_PTHREAD_TLS 1
#define GRPC_CFSTREAM 1
/* the c-ares resolver isnt safe to enable on iOS */
#define GRPC_ARES 0
#else /* TARGET_OS_IPHONE */
@ -235,7 +236,6 @@
#define GPR_POSIX_SYNC 1
#define GPR_POSIX_TIME 1
#define GPR_GETPID_IN_UNISTD_H 1
/* TODO(mxyan): Remove when CFStream becomes default */
#ifndef GRPC_CFSTREAM
#define GPR_SUPPORT_CHANNELS_FROM_FD 1
#endif

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,60 +19,36 @@
#ifndef GRPCPP_CREATE_CHANNEL_H
#define GRPCPP_CREATE_CHANNEL_H
#include <memory>
#include <grpcpp/channel.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/config.h>
#include <grpcpp/create_channel_impl.h>
namespace grpc {
/// Create a new \a Channel pointing to \a target.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
std::shared_ptr<Channel> CreateChannel(
static inline std::shared_ptr<Channel> CreateChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds);
const std::shared_ptr<ChannelCredentials>& creds) {
return ::grpc_impl::CreateChannel(target, creds);
}
/// Create a new \em custom \a Channel pointing to \a target.
///
/// \warning For advanced use and testing ONLY. Override default channel
/// arguments only if necessary.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<Channel> CreateCustomChannel(
static inline std::shared_ptr<Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args);
const ChannelArguments& args) {
return ::grpc_impl::CreateCustomChannel(target, creds, args);
}
namespace experimental {
/// Create a new \em custom \a Channel pointing to \a target with \a
/// interceptors being invoked per call.
///
/// \warning For advanced use and testing ONLY. Override default channel
/// arguments only if necessary.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
static inline std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
interceptor_creators) {
return ::grpc_impl::experimental::CreateCustomChannelWithInterceptors(
target, creds, args, std::move(interceptor_creators));
}
} // namespace experimental
} // namespace grpc

@ -0,0 +1,79 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_CREATE_CHANNEL_IMPL_H
#define GRPCPP_CREATE_CHANNEL_IMPL_H
#include <memory>
#include <grpcpp/channel.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/config.h>
namespace grpc_impl {
/// Create a new \a Channel pointing to \a target.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
std::shared_ptr<grpc::Channel> CreateChannel(
const grpc::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds);
/// Create a new \em custom \a Channel pointing to \a target.
///
/// \warning For advanced use and testing ONLY. Override default channel
/// arguments only if necessary.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args);
namespace experimental {
/// Create a new \em custom \a Channel pointing to \a target with \a
/// interceptors being invoked per call.
///
/// \warning For advanced use and testing ONLY. Override default channel
/// arguments only if necessary.
///
/// \param target The URI of the endpoint to connect to.
/// \param creds Credentials to use for the created channel. If it does not
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args,
std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
} // namespace experimental
} // namespace grpc_impl
#endif // GRPCPP_CREATE_CHANNEL_IMPL_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2016 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,46 +19,34 @@
#ifndef GRPCPP_CREATE_CHANNEL_POSIX_H
#define GRPCPP_CREATE_CHANNEL_POSIX_H
#include <memory>
#include <grpc/support/port_platform.h>
#include <grpcpp/channel.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/create_channel_posix_impl.h>
namespace grpc {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
/// Create a new \a Channel communicating over the given file descriptor.
///
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
int fd);
static inline std::shared_ptr<Channel> CreateInsecureChannelFromFd(
const grpc::string& target, int fd) {
return ::grpc_impl::CreateInsecureChannelFromFd(target, 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);
static inline std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const ChannelArguments& args) {
return ::grpc_impl::CreateCustomInsecureChannelFromFd(target, fd, args);
}
namespace experimental {
/// 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.
/// \param interceptor_creators Vector of interceptor factory objects.
std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
static inline std::shared_ptr<Channel>
CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const ChannelArguments& args,
std::unique_ptr<std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
interceptor_creators);
interceptor_creators) {
return ::grpc_impl::experimental::
CreateCustomInsecureChannelWithInterceptorsFromFd(
target, fd, args, std::move(interceptor_creators));
}
} // namespace experimental

@ -0,0 +1,70 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H
#define GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H
#include <memory>
#include <grpc/support/port_platform.h>
#include <grpcpp/channel.h>
#include <grpcpp/support/channel_arguments.h>
namespace grpc_impl {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
/// Create a new \a Channel communicating over the given file descriptor.
///
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
std::shared_ptr<grpc::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<grpc::Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args);
namespace experimental {
/// 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.
/// \param interceptor_creators Vector of interceptor factory objects.
std::shared_ptr<grpc::Channel>
CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args,
std::unique_ptr<std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>>
interceptor_creators);
} // namespace experimental
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
} // namespace grpc_impl
#endif // GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H

@ -19,20 +19,15 @@
#ifndef GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H
#define GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H
#include <grpc/support/port_platform.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/impl/server_initializer.h>
#include <grpcpp/support/config.h>
#include <grpcpp/ext/channelz_service_plugin_impl.h>
namespace grpc {
namespace channelz {
namespace experimental {
/// Add channelz server plugin to \a ServerBuilder. This function should
/// be called at static initialization time. This service is experimental
/// for now. Track progress in https://github.com/grpc/grpc/issues/15988.
void InitChannelzService();
static inline void InitChannelzService() {
::grpc_impl::channelz::experimental::InitChannelzService();
}
} // namespace experimental
} // namespace channelz

@ -0,0 +1,41 @@
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_IMPL_H
#define GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_IMPL_H
#include <grpc/support/port_platform.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/impl/server_initializer.h>
#include <grpcpp/support/config.h>
namespace grpc_impl {
namespace channelz {
namespace experimental {
/// Add channelz server plugin to \a ServerBuilder. This function should
/// be called at static initialization time. This service is experimental
/// for now. Track progress in https://github.com/grpc/grpc/issues/15988.
void InitChannelzService();
} // namespace experimental
} // namespace channelz
} // namespace grpc_impl
#endif // GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_IMPL_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,34 +19,17 @@
#ifndef GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
#define GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/support/config.h>
namespace grpc {
class ServerInitializer;
class ProtoServerReflection;
} // namespace grpc
#include <grpcpp/ext/proto_server_reflection_plugin_impl.h>
namespace grpc {
namespace reflection {
class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin {
public:
ProtoServerReflectionPlugin();
::grpc::string name() override;
void InitServer(::grpc::ServerInitializer* si) override;
void Finish(::grpc::ServerInitializer* si) override;
void ChangeArguments(const ::grpc::string& name, void* value) override;
bool has_async_methods() const override;
bool has_sync_methods() const override;
private:
std::shared_ptr<grpc::ProtoServerReflection> reflection_service_;
};
typedef ::grpc_impl::reflection::ProtoServerReflectionPlugin
ProtoServerReflectionPlugin;
/// Add proto reflection plugin to \a ServerBuilder.
/// This function should be called at the static initialization time.
void InitProtoReflectionServerBuilderPlugin();
static inline void InitProtoReflectionServerBuilderPlugin() {
::grpc_impl::reflection::InitProtoReflectionServerBuilderPlugin();
}
} // namespace reflection
} // namespace grpc

@ -0,0 +1,55 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_IMPL_H
#define GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_IMPL_H
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/support/config.h>
namespace grpc {
class ProtoServerReflection;
} // namespace grpc
namespace grpc_impl {
class ServerInitializer;
namespace reflection {
class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin {
public:
ProtoServerReflectionPlugin();
::grpc::string name() override;
void InitServer(::grpc_impl::ServerInitializer* si) override;
void Finish(::grpc_impl::ServerInitializer* si) override;
void ChangeArguments(const ::grpc::string& name, void* value) override;
bool has_async_methods() const override;
bool has_sync_methods() const override;
private:
std::shared_ptr<grpc::ProtoServerReflection> reflection_service_;
};
/// Add proto reflection plugin to \a ServerBuilder.
/// This function should be called at the static initialization time.
void InitProtoReflectionServerBuilderPlugin();
} // namespace reflection
} // namespace grpc_impl
#endif // GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_IMPL_H

@ -19,32 +19,22 @@
#ifndef GRPCPP_EXT_SERVER_LOAD_REPORTING_H
#define GRPCPP_EXT_SERVER_LOAD_REPORTING_H
#include <grpc/support/port_platform.h>
#include <grpc/load_reporting.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/server_context.h>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/ext/server_load_reporting_impl.h>
namespace grpc {
namespace load_reporter {
namespace experimental {
// The ServerBuilderOption to enable server-side load reporting feature. To
// enable the feature, please make sure the binary builds with the
// grpcpp_server_load_reporting library and set this option in the
// ServerBuilder.
class LoadReportingServiceServerBuilderOption : public ServerBuilderOption {
public:
void UpdateArguments(::grpc::ChannelArguments* args) override;
void UpdatePlugins(std::vector<std::unique_ptr<::grpc::ServerBuilderPlugin>>*
plugins) override;
};
typedef ::grpc_impl::load_reporter::experimental::
LoadReportingServiceServerBuilderOption
LoadReportingServiceServerBuilderOption;
// Adds the load reporting cost with \a cost_name and \a cost_value in the
// trailing metadata of the server context.
void AddLoadReportingCost(grpc::ServerContext* ctx,
const grpc::string& cost_name, double cost_value);
static inline void AddLoadReportingCost(grpc::ServerContext* ctx,
const grpc::string& cost_name,
double cost_value) {
::grpc_impl::load_reporter::experimental::AddLoadReportingCost(ctx, cost_name,
cost_value);
}
} // namespace experimental
} // namespace load_reporter

@ -0,0 +1,54 @@
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H
#define GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H
#include <grpc/support/port_platform.h>
#include <grpc/load_reporting.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/server_context.h>
#include <grpcpp/impl/server_builder_option.h>
namespace grpc_impl {
namespace load_reporter {
namespace experimental {
// The ServerBuilderOption to enable server-side load reporting feature. To
// enable the feature, please make sure the binary builds with the
// grpcpp_server_load_reporting library and set this option in the
// ServerBuilder.
class LoadReportingServiceServerBuilderOption
: public grpc::ServerBuilderOption {
public:
void UpdateArguments(::grpc::ChannelArguments* args) override;
void UpdatePlugins(std::vector<std::unique_ptr<::grpc::ServerBuilderPlugin>>*
plugins) override;
};
// Adds the load reporting cost with \a cost_name and \a cost_value in the
// trailing metadata of the server context.
void AddLoadReportingCost(grpc::ServerContext* ctx,
const grpc::string& cost_name, double cost_value);
} // namespace experimental
} // namespace load_reporter
} // namespace grpc_impl
#endif // GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H

@ -19,85 +19,11 @@
#ifndef GRPCPP_GENERIC_GENERIC_STUB_H
#define GRPCPP_GENERIC_GENERIC_STUB_H
#include <functional>
#include <grpcpp/support/async_stream.h>
#include <grpcpp/support/async_unary_call.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/client_callback.h>
#include <grpcpp/support/status.h>
#include <grpcpp/generic/generic_stub_impl.h>
namespace grpc {
class CompletionQueue;
typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer>
GenericClientAsyncReaderWriter;
typedef ClientAsyncResponseReader<ByteBuffer> GenericClientAsyncResponseReader;
/// Generic stubs provide a type-unsafe interface to call gRPC methods
/// by name.
class GenericStub final {
public:
explicit GenericStub(std::shared_ptr<ChannelInterface> channel)
: channel_(channel) {}
/// Setup a call to a named method \a method using \a context, but don't
/// start it. Let it be started explicitly with StartCall and a tag.
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<GenericClientAsyncReaderWriter> PrepareCall(
ClientContext* context, const grpc::string& method, CompletionQueue* cq);
/// Setup a unary call to a named method \a method using \a context, and don't
/// start it. Let it be started explicitly with StartCall.
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<GenericClientAsyncResponseReader> PrepareUnaryCall(
ClientContext* context, const grpc::string& method,
const ByteBuffer& request, CompletionQueue* cq);
/// DEPRECATED for multi-threaded use
/// Begin a call to a named method \a method using \a context.
/// A tag \a tag will be delivered to \a cq when the call has been started
/// (i.e, initial metadata has been sent).
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<GenericClientAsyncReaderWriter> Call(
ClientContext* context, const grpc::string& method, CompletionQueue* cq,
void* tag);
/// NOTE: class experimental_type is not part of the public API of this class
/// TODO(vjpai): Move these contents to the public API of GenericStub when
/// they are no longer experimental
class experimental_type {
public:
explicit experimental_type(GenericStub* stub) : stub_(stub) {}
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(ClientContext* context, const grpc::string& method,
const ByteBuffer* request, ByteBuffer* response,
std::function<void(Status)> on_completion);
/// Setup a call to a named method \a method using \a context and tied to
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
ClientContext* context, const grpc::string& method,
experimental::ClientBidiReactor<ByteBuffer, ByteBuffer>* reactor);
private:
GenericStub* stub_;
};
/// NOTE: The function experimental() is not stable public API. It is a view
/// to the experimental components of this class. It may be changed or removed
/// at any time.
experimental_type experimental() { return experimental_type(this); }
private:
std::shared_ptr<ChannelInterface> channel_;
};
typedef ::grpc_impl::GenericStub GenericStub;
} // namespace grpc

@ -0,0 +1,108 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_GENERIC_GENERIC_STUB_IMPL_H
#define GRPCPP_GENERIC_GENERIC_STUB_IMPL_H
#include <functional>
#include <grpcpp/support/async_stream.h>
#include <grpcpp/support/async_unary_call.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/client_callback.h>
#include <grpcpp/support/status.h>
namespace grpc {
class CompletionQueue;
typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer>
GenericClientAsyncReaderWriter;
typedef ClientAsyncResponseReader<ByteBuffer> GenericClientAsyncResponseReader;
} // namespace grpc
namespace grpc_impl {
/// Generic stubs provide a type-unsafe interface to call gRPC methods
/// by name.
class GenericStub final {
public:
explicit GenericStub(std::shared_ptr<grpc::ChannelInterface> channel)
: channel_(channel) {}
/// Setup a call to a named method \a method using \a context, but don't
/// start it. Let it be started explicitly with StartCall and a tag.
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> PrepareCall(
grpc::ClientContext* context, const grpc::string& method,
grpc::CompletionQueue* cq);
/// Setup a unary call to a named method \a method using \a context, and don't
/// start it. Let it be started explicitly with StartCall.
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncResponseReader> PrepareUnaryCall(
grpc::ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer& request, grpc::CompletionQueue* cq);
/// DEPRECATED for multi-threaded use
/// Begin a call to a named method \a method using \a context.
/// A tag \a tag will be delivered to \a cq when the call has been started
/// (i.e, initial metadata has been sent).
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> Call(
grpc::ClientContext* context, const grpc::string& method,
grpc::CompletionQueue* cq, void* tag);
/// NOTE: class experimental_type is not part of the public API of this class
/// TODO(vjpai): Move these contents to the public API of GenericStub when
/// they are no longer experimental
class experimental_type {
public:
explicit experimental_type(GenericStub* stub) : stub_(stub) {}
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(grpc::ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request, grpc::ByteBuffer* response,
std::function<void(grpc::Status)> on_completion);
/// Setup a call to a named method \a method using \a context and tied to
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
grpc::ClientContext* context, const grpc::string& method,
grpc::experimental::ClientBidiReactor<grpc::ByteBuffer,
grpc::ByteBuffer>* reactor);
private:
GenericStub* stub_;
};
/// NOTE: The function experimental() is not stable public API. It is a view
/// to the experimental components of this class. It may be changed or removed
/// at any time.
experimental_type experimental() { return experimental_type(this); }
private:
std::shared_ptr<grpc::ChannelInterface> channel_;
};
} // namespace grpc_impl
#endif // GRPCPP_GENERIC_GENERIC_STUB_IMPL_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2016 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,39 +19,22 @@
#ifndef GRPCPP_HEALTH_CHECK_SERVICE_INTERFACE_H
#define GRPCPP_HEALTH_CHECK_SERVICE_INTERFACE_H
#include <grpcpp/support/config.h>
#include <grpcpp/health_check_service_interface_impl.h>
namespace grpc {
const char kHealthCheckServiceInterfaceArg[] =
"grpc.health_check_service_interface";
/// The gRPC server uses this interface to expose the health checking service
/// without depending on protobuf.
class HealthCheckServiceInterface {
public:
virtual ~HealthCheckServiceInterface() {}
/// Set or change the serving status of the given \a service_name.
virtual void SetServingStatus(const grpc::string& service_name,
bool serving) = 0;
/// Apply to all registered service names.
virtual void SetServingStatus(bool serving) = 0;
/// Set all registered service names to not serving and prevent future
/// state changes.
virtual void Shutdown() {}
};
/// Enable/disable the default health checking service. This applies to all C++
/// servers created afterwards. For each server, user can override the default
/// with a HealthCheckServiceServerBuilderOption.
/// NOT thread safe.
void EnableDefaultHealthCheckService(bool enable);
/// Returns whether the default health checking service is enabled.
/// NOT thread safe.
bool DefaultHealthCheckServiceEnabled();
typedef ::grpc_impl::HealthCheckServiceInterface HealthCheckServiceInterface;
static inline void EnableDefaultHealthCheckService(bool enable) {
::grpc_impl::EnableDefaultHealthCheckService(enable);
}
static inline bool DefaultHealthCheckServiceEnabled() {
return ::grpc_impl::DefaultHealthCheckServiceEnabled();
}
} // namespace grpc

@ -0,0 +1,55 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_HEALTH_CHECK_SERVICE_INTERFACE_IMPL_H
#define GRPCPP_HEALTH_CHECK_SERVICE_INTERFACE_IMPL_H
#include <grpcpp/support/config.h>
namespace grpc_impl {
/// The gRPC server uses this interface to expose the health checking service
/// without depending on protobuf.
class HealthCheckServiceInterface {
public:
virtual ~HealthCheckServiceInterface() {}
/// Set or change the serving status of the given \a service_name.
virtual void SetServingStatus(const grpc::string& service_name,
bool serving) = 0;
/// Apply to all registered service names.
virtual void SetServingStatus(bool serving) = 0;
/// Set all registered service names to not serving and prevent future
/// state changes.
virtual void Shutdown() {}
};
/// Enable/disable the default health checking service. This applies to all C++
/// servers created afterwards. For each server, user can override the default
/// with a HealthCheckServiceServerBuilderOption.
/// NOT thread safe.
void EnableDefaultHealthCheckService(bool enable);
/// Returns whether the default health checking service is enabled.
/// NOT thread safe.
bool DefaultHealthCheckServiceEnabled();
} // namespace grpc_impl
#endif // GRPCPP_HEALTH_CHECK_SERVICE_INTERFACE_IMPL_H

@ -169,9 +169,13 @@ class ServerCallbackReaderWriter {
// The following classes are the reactor interfaces that are to be implemented
// by the user, returned as the result of the method handler for a callback
// method, and activated by the call to OnStarted. Note that none of the classes
// are pure; all reactions have a default empty reaction so that the user class
// only needs to override those classes that it cares about.
// method, and activated by the call to OnStarted. The library guarantees that
// OnStarted will be called for any reactor that has been created using a
// method handler registered on a service. No operation initiation method may be
// called until after the call to OnStarted.
// Note that none of the classes are pure; all reactions have a default empty
// reaction so that the user class only needs to override those classes that it
// cares about.
/// \a ServerBidiReactor is the interface for a bidirectional streaming RPC.
template <class Request, class Response>
@ -179,6 +183,9 @@ class ServerBidiReactor : public internal::ServerReactor {
public:
~ServerBidiReactor() = default;
/// Do NOT call any operation initiation method (names that start with Start)
/// until after the library has called OnStarted on this object.
/// Send any initial metadata stored in the RPC context. If not invoked,
/// any initial metadata will be passed along with the first Write or the
/// Finish (if there are no writes).
@ -245,7 +252,8 @@ class ServerBidiReactor : public internal::ServerReactor {
/// \param[in] s The status outcome of this RPC
void Finish(Status s) { stream_->Finish(std::move(s)); }
/// Notify the application that a streaming RPC has started
/// Notify the application that a streaming RPC has started and that it is now
/// ok to call any operation initation method.
///
/// \param[in] context The context object now associated with this RPC
virtual void OnStarted(ServerContext* context) {}

@ -28,6 +28,10 @@
#include <grpcpp/impl/codegen/rpc_service_method.h>
#include <grpcpp/impl/codegen/server_context.h>
namespace grpc_impl {
class ServerCredentials;
}
namespace grpc {
class AsyncGenericService;
@ -35,7 +39,6 @@ class Channel;
class GenericServerContext;
class ServerCompletionQueue;
class ServerContext;
class ServerCredentials;
class Service;
extern CoreCodegenInterface* g_core_codegen_interface;
@ -150,7 +153,7 @@ class ServerInterface : public internal::CallHook {
///
/// \warning It's an error to call this method on an already started server.
virtual int AddListeningPort(const grpc::string& addr,
ServerCredentials* creds) = 0;
grpc_impl::ServerCredentials* creds) = 0;
/// Start the server.
///

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,24 +19,11 @@
#ifndef GRPCPP_IMPL_SERVER_BUILDER_OPTION_H
#define GRPCPP_IMPL_SERVER_BUILDER_OPTION_H
#include <map>
#include <memory>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/impl/server_builder_option_impl.h>
namespace grpc {
/// Interface to pass an option to a \a ServerBuilder.
class ServerBuilderOption {
public:
virtual ~ServerBuilderOption() {}
/// Alter the \a ChannelArguments used to create the gRPC server.
virtual void UpdateArguments(ChannelArguments* args) = 0;
/// Alter the ServerBuilderPlugin map that will be added into ServerBuilder.
virtual void UpdatePlugins(
std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) = 0;
};
typedef ::grpc_impl::ServerBuilderOption ServerBuilderOption;
} // namespace grpc

@ -0,0 +1,43 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_IMPL_SERVER_BUILDER_OPTION_IMPL_H
#define GRPCPP_IMPL_SERVER_BUILDER_OPTION_IMPL_H
#include <map>
#include <memory>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/support/channel_arguments.h>
namespace grpc_impl {
/// Interface to pass an option to a \a ServerBuilder.
class ServerBuilderOption {
public:
virtual ~ServerBuilderOption() {}
/// Alter the \a ChannelArguments used to create the gRPC server.
virtual void UpdateArguments(grpc::ChannelArguments* args) = 0;
/// Alter the ServerBuilderPlugin map that will be added into ServerBuilder.
virtual void UpdatePlugins(
std::vector<std::unique_ptr<grpc::ServerBuilderPlugin>>* plugins) = 0;
};
} // namespace grpc_impl
#endif // GRPCPP_IMPL_SERVER_BUILDER_OPTION_IMPL_H

@ -26,11 +26,10 @@
namespace grpc_impl {
class ChannelArguments;
} // namespace grpc_impl
namespace grpc {
class ServerBuilder;
class ServerInitializer;
} // namespace grpc_impl
namespace grpc {
/// This interface is meant for internal usage only. Implementations of this
/// interface should add themselves to a \a ServerBuilder instance through the
@ -47,10 +46,10 @@ class ServerBuilderPlugin {
/// InitServer will be called in ServerBuilder::BuildAndStart(), after the
/// Server instance is created.
virtual void InitServer(ServerInitializer* si) = 0;
virtual void InitServer(grpc_impl::ServerInitializer* si) = 0;
/// Finish will be called at the end of ServerBuilder::BuildAndStart().
virtual void Finish(ServerInitializer* si) = 0;
virtual void Finish(grpc_impl::ServerInitializer* si) = 0;
/// ChangeArguments is an interface that can be used in
/// ServerBuilderOption::UpdatePlugins

@ -1,6 +1,6 @@
/*
*
* Copyright 2016 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,36 +19,11 @@
#ifndef GRPCPP_IMPL_SERVER_INITIALIZER_H
#define GRPCPP_IMPL_SERVER_INITIALIZER_H
#include <memory>
#include <vector>
#include <grpcpp/server.h>
#include <grpcpp/impl/server_initializer_impl.h>
namespace grpc {
class Server;
class Service;
class ServerInitializer {
public:
ServerInitializer(Server* server) : server_(server) {}
bool RegisterService(std::shared_ptr<Service> service) {
if (!server_->RegisterService(nullptr, service.get())) {
return false;
}
default_services_.push_back(service);
return true;
}
const std::vector<grpc::string>* GetServiceList() {
return &server_->services_;
}
private:
Server* server_;
std::vector<std::shared_ptr<Service> > default_services_;
};
typedef ::grpc_impl::ServerInitializer ServerInitializer;
} // namespace grpc

@ -0,0 +1,57 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_IMPL_SERVER_INITIALIZER_IMPL_H
#define GRPCPP_IMPL_SERVER_INITIALIZER_IMPL_H
#include <memory>
#include <vector>
#include <grpcpp/server.h>
namespace grpc {
class Server;
class Service;
} // namespace grpc
namespace grpc_impl {
class ServerInitializer {
public:
ServerInitializer(grpc::Server* server) : server_(server) {}
bool RegisterService(std::shared_ptr<grpc::Service> service) {
if (!server_->RegisterService(nullptr, service.get())) {
return false;
}
default_services_.push_back(service);
return true;
}
const std::vector<grpc::string>* GetServiceList() {
return &server_->services_;
}
private:
grpc::Server* server_;
std::vector<std::shared_ptr<grpc::Service> > default_services_;
};
} // namespace grpc_impl
#endif // GRPCPP_IMPL_SERVER_INITIALIZER_IMPL_H

@ -19,29 +19,20 @@
#ifndef GRPCPP_OPENCENSUS_H
#define GRPCPP_OPENCENSUS_H
#include "opencensus/trace/span.h"
#include "grpcpp/opencensus_impl.h"
namespace grpc {
// These symbols in this file will not be included in the binary unless
// grpc_opencensus_plugin build target was added as a dependency. At the moment
// it is only setup to be built with Bazel.
// Registers the OpenCensus plugin with gRPC, so that it will be used for future
// RPCs. This must be called before any views are created.
void RegisterOpenCensusPlugin();
// RPC stats definitions, defined by
// https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md
// Registers the cumulative gRPC views so that they will be exported by any
// registered stats exporter. For on-task stats, construct a View using the
// ViewDescriptors below.
void RegisterOpenCensusViewsForExport();
class ServerContext;
// Returns the tracing Span for the current RPC.
::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context);
static inline void RegisterOpenCensusPlugin() {
::grpc_impl::RegisterOpenCensusPlugin();
}
static inline void RegisterOpenCensusViewsForExport() {
::grpc_impl::RegisterOpenCensusViewsForExport();
}
static inline ::opencensus::trace::Span GetSpanFromServerContext(
ServerContext* context) {
return ::grpc_impl::GetSpanFromServerContext(context);
}
} // namespace grpc

@ -0,0 +1,51 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_OPENCENSUS_IMPL_H
#define GRPCPP_OPENCENSUS_IMPL_H
#include "opencensus/trace/span.h"
namespace grpc {
class ServerContext;
}
namespace grpc_impl {
// These symbols in this file will not be included in the binary unless
// grpc_opencensus_plugin build target was added as a dependency. At the moment
// it is only setup to be built with Bazel.
// Registers the OpenCensus plugin with gRPC, so that it will be used for future
// RPCs. This must be called before any views are created.
void RegisterOpenCensusPlugin();
// RPC stats definitions, defined by
// https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md
// Registers the cumulative gRPC views so that they will be exported by any
// registered stats exporter. For on-task stats, construct a View using the
// ViewDescriptors below.
void RegisterOpenCensusViewsForExport();
// Returns the tracing Span for the current RPC.
::opencensus::trace::Span GetSpanFromServerContext(
grpc::ServerContext* context);
} // namespace grpc_impl
#endif // GRPCPP_OPENCENSUS_IMPL_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2016 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,50 +19,11 @@
#ifndef GRPCPP_RESOURCE_QUOTA_H
#define GRPCPP_RESOURCE_QUOTA_H
struct grpc_resource_quota;
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/grpc_library.h>
#include <grpcpp/resource_quota_impl.h>
namespace grpc {
/// ResourceQuota represents a bound on memory and thread usage by the gRPC
/// library. A ResourceQuota can be attached to a server (via \a ServerBuilder),
/// or a client channel (via \a ChannelArguments).
/// gRPC will attempt to keep memory and threads used by all attached entities
/// below the ResourceQuota bound.
class ResourceQuota final : private GrpcLibraryCodegen {
public:
/// \param name - a unique name for this ResourceQuota.
explicit ResourceQuota(const grpc::string& name);
ResourceQuota();
~ResourceQuota();
/// Resize this \a ResourceQuota to a new size. If \a new_size is smaller
/// than the current size of the pool, memory usage will be monotonically
/// decreased until it falls under \a new_size.
/// No time bound is given for this to occur however.
ResourceQuota& Resize(size_t new_size);
/// Set the max number of threads that can be allocated from this
/// ResourceQuota object.
///
/// If the new_max_threads value is smaller than the current value, no new
/// threads are allocated until the number of active threads fall below
/// new_max_threads. There is no time bound on when this may happen i.e none
/// of the current threads are forcefully destroyed and all threads run their
/// normal course.
ResourceQuota& SetMaxThreads(int new_max_threads);
grpc_resource_quota* c_resource_quota() const { return impl_; }
private:
ResourceQuota(const ResourceQuota& rhs);
ResourceQuota& operator=(const ResourceQuota& rhs);
grpc_resource_quota* const impl_;
};
typedef ::grpc_impl::ResourceQuota ResourceQuota;
} // namespace grpc
#endif // GRPCPP_RESOURCE_QUOTA_H

@ -0,0 +1,68 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_RESOURCE_QUOTA_IMPL_H
#define GRPCPP_RESOURCE_QUOTA_IMPL_H
struct grpc_resource_quota;
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/grpc_library.h>
namespace grpc_impl {
/// ResourceQuota represents a bound on memory and thread usage by the gRPC
/// library. A ResourceQuota can be attached to a server (via \a ServerBuilder),
/// or a client channel (via \a ChannelArguments).
/// gRPC will attempt to keep memory and threads used by all attached entities
/// below the ResourceQuota bound.
class ResourceQuota final : private ::grpc::GrpcLibraryCodegen {
public:
/// \param name - a unique name for this ResourceQuota.
explicit ResourceQuota(const grpc::string& name);
ResourceQuota();
~ResourceQuota();
/// Resize this \a ResourceQuota to a new size. If \a new_size is smaller
/// than the current size of the pool, memory usage will be monotonically
/// decreased until it falls under \a new_size.
/// No time bound is given for this to occur however.
ResourceQuota& Resize(size_t new_size);
/// Set the max number of threads that can be allocated from this
/// ResourceQuota object.
///
/// If the new_max_threads value is smaller than the current value, no new
/// threads are allocated until the number of active threads fall below
/// new_max_threads. There is no time bound on when this may happen i.e none
/// of the current threads are forcefully destroyed and all threads run their
/// normal course.
ResourceQuota& SetMaxThreads(int new_max_threads);
grpc_resource_quota* c_resource_quota() const { return impl_; }
private:
ResourceQuota(const ResourceQuota& rhs);
ResourceQuota& operator=(const ResourceQuota& rhs);
grpc_resource_quota* const impl_;
};
} // namespace grpc_impl
#endif // GRPCPP_RESOURCE_QUOTA_IMPL_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,42 +19,11 @@
#ifndef GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
#define GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
#include <map>
#include <grpcpp/security/auth_context.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
#include <grpcpp/security/auth_metadata_processor_impl.h>
namespace grpc {
/// Interface allowing custom server-side authorization based on credentials
/// encoded in metadata. Objects of this type can be passed to
/// \a ServerCredentials::SetAuthMetadataProcessor().
class AuthMetadataProcessor {
public:
typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
typedef std::multimap<grpc::string, grpc::string> OutputMetadata;
virtual ~AuthMetadataProcessor() {}
/// If this method returns true, the \a Process function will be scheduled in
/// a different thread from the one processing the call.
virtual bool IsBlocking() const { return true; }
/// context is read/write: it contains the properties of the channel peer and
/// it is the job of the Process method to augment it with properties derived
/// from the passed-in auth_metadata.
/// consumed_auth_metadata needs to be filled with metadata that has been
/// consumed by the processor and will be removed from the call.
/// response_metadata is the metadata that will be sent as part of the
/// response.
/// If the return value is not Status::OK, the rpc call will be aborted with
/// the error code and error message sent back to the client.
virtual Status Process(const InputMetadata& auth_metadata,
AuthContext* context,
OutputMetadata* consumed_auth_metadata,
OutputMetadata* response_metadata) = 0;
};
typedef ::grpc_impl::AuthMetadataProcessor AuthMetadataProcessor;
} // namespace grpc

@ -0,0 +1,61 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H
#define GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H
#include <map>
#include <grpcpp/security/auth_context.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
namespace grpc_impl {
/// Interface allowing custom server-side authorization based on credentials
/// encoded in metadata. Objects of this type can be passed to
/// \a ServerCredentials::SetAuthMetadataProcessor().
class AuthMetadataProcessor {
public:
typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
typedef std::multimap<grpc::string, grpc::string> OutputMetadata;
virtual ~AuthMetadataProcessor() {}
/// If this method returns true, the \a Process function will be scheduled in
/// a different thread from the one processing the call.
virtual bool IsBlocking() const { return true; }
/// context is read/write: it contains the properties of the channel peer and
/// it is the job of the Process method to augment it with properties derived
/// from the passed-in auth_metadata.
/// consumed_auth_metadata needs to be filled with metadata that has been
/// consumed by the processor and will be removed from the call.
/// response_metadata is the metadata that will be sent as part of the
/// response.
/// If the return value is not Status::OK, the rpc call will be aborted with
/// the error code and error message sent back to the client.
virtual grpc::Status Process(const InputMetadata& auth_metadata,
grpc::AuthContext* context,
OutputMetadata* consumed_auth_metadata,
OutputMetadata* response_metadata) = 0;
};
} // namespace grpc_impl
#endif // GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H

@ -34,22 +34,30 @@
struct grpc_call;
namespace grpc {
class Channel;
class SecureChannelCredentials;
class CallCredentials;
class SecureCallCredentials;
class ChannelArguments;
class ChannelCredentials;
} // namespace grpc
namespace grpc_impl {
std::shared_ptr<grpc::Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args);
namespace experimental {
std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
} // namespace experimental
} // namespace grpc_impl
namespace grpc {
class Channel;
class SecureChannelCredentials;
class SecureCallCredentials;
/// A channel credentials object encapsulates all the state needed by a client
/// to authenticate with a server for a given channel.
@ -70,18 +78,18 @@ class ChannelCredentials : private GrpcLibraryCodegen {
virtual SecureChannelCredentials* AsSecureCredentials() = 0;
private:
friend std::shared_ptr<Channel> CreateCustomChannel(
friend std::shared_ptr<Channel> grpc_impl::CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args);
const grpc::ChannelArguments& args);
friend std::shared_ptr<Channel>
experimental::CreateCustomChannelWithInterceptors(
grpc_impl::experimental::CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
const grpc::ChannelArguments& args,
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
virtual std::shared_ptr<Channel> CreateChannel(

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,39 +19,11 @@
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/support/config.h>
struct grpc_server;
#include <grpcpp/security/server_credentials_impl.h>
namespace grpc {
class Server;
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on sucess, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const grpc::string& addr,
grpc_server* server) = 0;
};
typedef ::grpc_impl::ServerCredentials ServerCredentials;
/// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
@ -79,27 +51,29 @@ struct SslServerCredentialsOptions {
grpc_ssl_client_certificate_request_type client_certificate_request;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options);
static inline std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options) {
return ::grpc_impl::SslServerCredentials(options);
}
/// Builds insecure server credentials.
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
static inline std::shared_ptr<ServerCredentials> InsecureServerCredentials() {
return ::grpc_impl::InsecureServerCredentials();
}
namespace experimental {
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
typedef ::grpc_impl::experimental::AltsServerCredentialsOptions
AltsServerCredentialsOptions;
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
static inline std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options) {
return ::grpc_impl::experimental::AltsServerCredentials(options);
}
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);
static inline std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type) {
return ::grpc_impl::experimental::LocalServerCredentials(type);
}
} // namespace experimental
} // namespace grpc

@ -0,0 +1,85 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/support/config.h>
struct grpc_server;
namespace grpc {
class Server;
struct SslServerCredentialsOptions;
} // namespace grpc
namespace grpc_impl {
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on sucess, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const grpc::string& addr,
grpc_server* server) = 0;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const grpc::SslServerCredentialsOptions& options);
/// Builds insecure server credentials.
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
namespace experimental {
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);
} // namespace experimental
} // namespace grpc_impl
#endif // GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H

@ -28,6 +28,7 @@
#include <grpc/compression.h>
#include <grpc/support/atm.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/health_check_service_interface.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/impl/codegen/grpc_library.h>
@ -40,12 +41,14 @@
struct grpc_server;
namespace grpc_impl {
class ServerInitializer;
}
namespace grpc {
class AsyncGenericService;
class HealthCheckServiceInterface;
class ServerContext;
class ServerInitializer;
/// Represents a gRPC server.
///
@ -199,7 +202,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen {
friend class AsyncGenericService;
friend class ServerBuilder;
friend class ServerInitializer;
friend class grpc_impl::ServerInitializer;
class SyncRequest;
class CallbackRequestBase;
@ -257,7 +260,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen {
CompletionQueue* CallbackCQ() override;
ServerInitializer* initializer();
grpc_impl::ServerInitializer* initializer();
// A vector of interceptor factory objects.
// This should be destroyed after health_check_service_ and this requirement
@ -321,7 +324,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen {
// Pointer to the wrapped grpc_server.
grpc_server* server_;
std::unique_ptr<ServerInitializer> server_initializer_;
std::unique_ptr<grpc_impl::ServerInitializer> server_initializer_;
std::unique_ptr<HealthCheckServiceInterface> health_check_service_;
bool health_check_service_disabled_;

@ -35,14 +35,18 @@
struct grpc_resource_quota;
namespace grpc_impl {
class ServerCredentials;
class ResourceQuota;
} // namespace grpc_impl
namespace grpc {
class AsyncGenericService;
class ResourceQuota;
class CompletionQueue;
class Server;
class ServerCompletionQueue;
class ServerCredentials;
class Service;
namespace testing {
@ -93,9 +97,10 @@ class ServerBuilder {
/// number bound to the \a grpc::Server for the corresponding endpoint after
/// it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort
/// does not modify this pointer.
ServerBuilder& AddListeningPort(const grpc::string& addr_uri,
std::shared_ptr<ServerCredentials> creds,
int* selected_port = nullptr);
ServerBuilder& AddListeningPort(
const grpc::string& addr_uri,
std::shared_ptr<grpc_impl::ServerCredentials> creds,
int* selected_port = nullptr);
/// Add a completion queue for handling asynchronous services.
///
@ -186,7 +191,8 @@ class ServerBuilder {
grpc_compression_algorithm algorithm);
/// Set the attached buffer pool for this server
ServerBuilder& SetResourceQuota(const ResourceQuota& resource_quota);
ServerBuilder& SetResourceQuota(
const ::grpc_impl::ResourceQuota& resource_quota);
ServerBuilder& SetOption(std::unique_ptr<ServerBuilderOption> option);
@ -251,7 +257,7 @@ class ServerBuilder {
/// Experimental, to be deprecated
struct Port {
grpc::string addr;
std::shared_ptr<ServerCredentials> creds;
std::shared_ptr<grpc_impl::ServerCredentials> creds;
int* selected_port;
};
@ -319,7 +325,7 @@ class ServerBuilder {
/// List of completion queues added via \a AddCompletionQueue method.
std::vector<ServerCompletionQueue*> cqs_;
std::shared_ptr<ServerCredentials> creds_;
std::shared_ptr<grpc_impl::ServerCredentials> creds_;
std::vector<std::unique_ptr<ServerBuilderPlugin>> plugins_;
grpc_resource_quota* resource_quota_;
AsyncGenericService* generic_service_{nullptr};

@ -19,21 +19,15 @@
#ifndef GRPCPP_SERVER_POSIX_H
#define GRPCPP_SERVER_POSIX_H
#include <memory>
#include <grpc/support/port_platform.h>
#include <grpcpp/server.h>
#include <grpcpp/server_posix_impl.h>
namespace grpc {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
/// Add a new client to a \a Server communicating over the given
/// file descriptor.
///
/// \param server The server to add the client to.
/// \param fd The file descriptor representing a socket.
void AddInsecureChannelFromFd(Server* server, int fd);
static inline void AddInsecureChannelFromFd(Server* server, int fd) {
::grpc_impl::AddInsecureChannelFromFd(server, fd);
}
#endif // GPR_SUPPORT_CHANNELS_FROM_FD

@ -0,0 +1,42 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SERVER_POSIX_IMPL_H
#define GRPCPP_SERVER_POSIX_IMPL_H
#include <memory>
#include <grpc/support/port_platform.h>
#include <grpcpp/server.h>
namespace grpc_impl {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
/// Add a new client to a \a Server communicating over the given
/// file descriptor.
///
/// \param server The server to add the client to.
/// \param fd The file descriptor representing a socket.
void AddInsecureChannelFromFd(grpc::Server* server, int fd);
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
} // namespace grpc
#endif // GRPCPP_SERVER_POSIX_IMPL_H

@ -21,6 +21,11 @@
#include <grpcpp/support/channel_arguments_impl.h>
namespace grpc_impl {
class ResourceQuota;
}
namespace grpc {
typedef ::grpc_impl::ChannelArguments ChannelArguments;

@ -19,7 +19,7 @@
#ifndef GRPCPP_SUPPORT_ERROR_DETAILS_H
#define GRPCPP_SUPPORT_ERROR_DETAILS_H
#include <grpcpp/support/status.h>
#include <grpcpp/support/error_details_impl.h>
namespace google {
namespace rpc {
@ -29,17 +29,15 @@ class Status;
namespace grpc {
/// Map a \a grpc::Status to a \a google::rpc::Status.
/// The given \a to object will be cleared.
/// On success, returns status with OK.
/// Returns status with \a INVALID_ARGUMENT, if failed to deserialize.
/// Returns status with \a FAILED_PRECONDITION, if \a to is nullptr.
Status ExtractErrorDetails(const Status& from, ::google::rpc::Status* to);
/// Map \a google::rpc::Status to a \a grpc::Status.
/// Returns OK on success.
/// Returns status with \a FAILED_PRECONDITION if \a to is nullptr.
Status SetErrorDetails(const ::google::rpc::Status& from, Status* to);
static inline Status ExtractErrorDetails(const Status& from,
::google::rpc::Status* to) {
return ::grpc_impl::ExtractErrorDetails(from, to);
}
static inline Status SetErrorDetails(const ::google::rpc::Status& from,
Status* to) {
return ::grpc_impl::SetErrorDetails(from, to);
}
} // namespace grpc

@ -0,0 +1,48 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H
#define GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H
#include <grpcpp/support/status.h>
namespace google {
namespace rpc {
class Status;
} // namespace rpc
} // namespace google
namespace grpc_impl {
/// Map a \a grpc::Status to a \a google::rpc::Status.
/// The given \a to object will be cleared.
/// On success, returns status with OK.
/// Returns status with \a INVALID_ARGUMENT, if failed to deserialize.
/// Returns status with \a FAILED_PRECONDITION, if \a to is nullptr.
grpc::Status ExtractErrorDetails(const grpc::Status& from,
::google::rpc::Status* to);
/// Map \a google::rpc::Status to a \a grpc::Status.
/// Returns OK on success.
/// Returns status with \a FAILED_PRECONDITION if \a to is nullptr.
grpc::Status SetErrorDetails(const ::google::rpc::Status& from,
grpc::Status* to);
} // namespace grpc_impl
#endif // GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H

@ -13,8 +13,8 @@
<date>2018-01-19</date>
<time>16:06:07</time>
<version>
<release>1.20.0dev</release>
<api>1.20.0dev</api>
<release>1.21.0dev</release>
<api>1.21.0dev</api>
</version>
<stability>
<release>beta</release>
@ -107,8 +107,10 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/mutex_lock.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/pair.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/timers.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/alloc.cc" role="src" />

@ -70,6 +70,10 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer) {
}
printer->Print("\n");
}
printer->Print(" *\n");
printer->Print(
" * This method belongs to a set of APIs that have been deprecated. Using"
" the v2 API is recommended.\n");
printer->Print(" */\n");
}
@ -278,6 +282,13 @@ void PrintMethodImplementations(Printer* printer,
map< ::grpc::string, ::grpc::string> vars = {
{"service_class", ServiceClassName(service)}};
printer.Print(vars,
"/**\n"
" * The methods in this protocol belong to a set of old APIs "
"that have been deprecated. They do not\n"
" * recognize call options provided in the initializer. Using "
"the v2 protocol is recommended.\n"
" */\n");
printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n");
for (int i = 0; i < service->method_count(); i++) {
PrintMethodDeclarations(&printer, service->method(i));
@ -329,10 +340,13 @@ void PrintMethodImplementations(Printer* printer,
"callOptions:(GRPCCallOptions "
"*_Nullable)callOptions"
" NS_DESIGNATED_INITIALIZER;\n");
printer.Print("- (instancetype)initWithHost:(NSString *)host;\n");
printer.Print(
"+ (instancetype)serviceWithHost:(NSString *)host "
"callOptions:(GRPCCallOptions *_Nullable)callOptions;\n");
printer.Print(
"// The following methods belong to a set of old APIs that have been "
"deprecated.\n");
printer.Print("- (instancetype)initWithHost:(NSString *)host;\n");
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n");
printer.Print("@end\n");

@ -51,6 +51,7 @@
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/mutex_lock.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/polling_entity.h"
@ -91,7 +92,55 @@ grpc_core::TraceFlag grpc_client_channel_routing_trace(
* CHANNEL-WIDE FUNCTIONS
*/
struct external_connectivity_watcher;
// Forward declaration.
typedef struct client_channel_channel_data channel_data;
namespace grpc_core {
namespace {
class ExternalConnectivityWatcher {
public:
class WatcherList {
public:
WatcherList() { gpr_mu_init(&mu_); }
~WatcherList() { gpr_mu_destroy(&mu_); }
int size() const;
ExternalConnectivityWatcher* Lookup(grpc_closure* on_complete) const;
void Add(ExternalConnectivityWatcher* watcher);
void Remove(const ExternalConnectivityWatcher* watcher);
private:
// head_ is guarded by a mutex, since the size() method needs to
// iterate over the list, and it's called from the C-core API
// function grpc_channel_num_external_connectivity_watchers(), which
// is synchronous and therefore cannot run in the combiner.
mutable gpr_mu mu_;
ExternalConnectivityWatcher* head_ = nullptr;
};
ExternalConnectivityWatcher(channel_data* chand, grpc_polling_entity pollent,
grpc_connectivity_state* state,
grpc_closure* on_complete,
grpc_closure* watcher_timer_init);
~ExternalConnectivityWatcher();
private:
static void OnWatchCompleteLocked(void* arg, grpc_error* error);
static void WatchConnectivityStateLocked(void* arg, grpc_error* ignored);
channel_data* chand_;
grpc_polling_entity pollent_;
grpc_connectivity_state* state_;
grpc_closure* on_complete_;
grpc_closure* watcher_timer_init_;
grpc_closure my_closure_;
ExternalConnectivityWatcher* next_ = nullptr;
};
} // namespace
} // namespace grpc_core
struct QueuedPick {
LoadBalancingPolicy::PickArgs pick;
@ -99,51 +148,53 @@ struct QueuedPick {
QueuedPick* next = nullptr;
};
typedef struct client_channel_channel_data {
struct client_channel_channel_data {
//
// Fields set at construction and never modified.
//
bool deadline_checking_enabled;
bool enable_retries;
size_t per_rpc_retry_buffer_size;
/** combiner protecting all variables below in this data structure */
grpc_combiner* combiner;
/** owning stack */
grpc_channel_stack* owning_stack;
/** interested parties (owned) */
grpc_pollset_set* interested_parties;
// Client channel factory.
grpc_core::ClientChannelFactory* client_channel_factory;
// Subchannel pool.
grpc_core::RefCountedPtr<grpc_core::SubchannelPoolInterface> subchannel_pool;
grpc_core::channelz::ClientChannelNode* channelz_node;
// Resolving LB policy.
grpc_core::OrphanablePtr<LoadBalancingPolicy> resolving_lb_policy;
// Subchannel picker from LB policy.
//
// Fields used in the data plane. Protected by data_plane_combiner.
//
grpc_combiner* data_plane_combiner;
grpc_core::UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker;
// Linked list of queued picks.
QueuedPick* queued_picks;
bool have_service_config;
/** retry throttle data from service config */
QueuedPick* queued_picks; // Linked list of queued picks.
// Data from service config.
bool received_service_config_data;
grpc_core::RefCountedPtr<ServerRetryThrottleData> retry_throttle_data;
/** per-method service config data */
grpc_core::RefCountedPtr<ClientChannelMethodParamsTable> method_params_table;
/* the following properties are guarded by a mutex since APIs require them
to be instantaneously available */
//
// Fields used in the control plane. Protected by combiner.
//
grpc_combiner* combiner;
grpc_pollset_set* interested_parties;
grpc_core::RefCountedPtr<grpc_core::SubchannelPoolInterface> subchannel_pool;
grpc_core::OrphanablePtr<LoadBalancingPolicy> resolving_lb_policy;
grpc_connectivity_state_tracker state_tracker;
//
// Fields accessed from both data plane and control plane combiners.
//
grpc_core::Atomic<grpc_error*> disconnect_error;
// The following properties are guarded by a mutex since APIs require them
// to be instantaneously available.
gpr_mu info_mu;
grpc_core::UniquePtr<char> info_lb_policy_name;
grpc_core::UniquePtr<char> info_service_config_json;
grpc_connectivity_state_tracker state_tracker;
grpc_error* disconnect_error;
/* external_connectivity_watcher_list head is guarded by its own mutex, since
* counts need to be grabbed immediately without polling on a cq */
gpr_mu external_connectivity_watcher_list_mu;
struct external_connectivity_watcher* external_connectivity_watcher_list_head;
} channel_data;
grpc_core::ManualConstructor<
grpc_core::ExternalConnectivityWatcher::WatcherList>
external_connectivity_watcher_list;
};
// Forward declarations.
static void start_pick_locked(void* arg, grpc_error* ignored);
@ -166,30 +217,215 @@ static const char* get_channel_connectivity_state_change_string(
GPR_UNREACHABLE_CODE(return "UNKNOWN");
}
static void set_connectivity_state_and_picker_locked(
channel_data* chand, grpc_connectivity_state state, grpc_error* state_error,
const char* reason,
grpc_core::UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker) {
// Update connectivity state.
grpc_connectivity_state_set(&chand->state_tracker, state, state_error,
reason);
if (chand->channelz_node != nullptr) {
chand->channelz_node->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string(
get_channel_connectivity_state_change_string(state)));
namespace grpc_core {
namespace {
// A fire-and-forget class that sets the channel's connectivity state
// and then hops into the data plane combiner to update the picker.
// Must be instantiated while holding the control plane combiner.
// Deletes itself when done.
class ConnectivityStateAndPickerSetter {
public:
ConnectivityStateAndPickerSetter(
channel_data* chand, grpc_connectivity_state state,
grpc_error* state_error, const char* reason,
UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker)
: chand_(chand), picker_(std::move(picker)) {
// Update connectivity state here, while holding control plane combiner.
grpc_connectivity_state_set(&chand->state_tracker, state, state_error,
reason);
if (chand->channelz_node != nullptr) {
chand->channelz_node->AddTraceEvent(
channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string(
get_channel_connectivity_state_change_string(state)));
}
// Bounce into the data plane combiner to reset the picker.
GRPC_CHANNEL_STACK_REF(chand->owning_stack,
"ConnectivityStateAndPickerSetter");
GRPC_CLOSURE_INIT(&closure_, SetPicker, this,
grpc_combiner_scheduler(chand->data_plane_combiner));
GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE);
}
private:
static void SetPicker(void* arg, grpc_error* ignored) {
auto* self = static_cast<ConnectivityStateAndPickerSetter*>(arg);
// Update picker.
self->chand_->picker = std::move(self->picker_);
// Re-process queued picks.
for (QueuedPick* pick = self->chand_->queued_picks; pick != nullptr;
pick = pick->next) {
start_pick_locked(pick->elem, GRPC_ERROR_NONE);
}
// Clean up.
GRPC_CHANNEL_STACK_UNREF(self->chand_->owning_stack,
"ConnectivityStateAndPickerSetter");
Delete(self);
}
channel_data* chand_;
UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker_;
grpc_closure closure_;
};
// A fire-and-forget class that sets the channel's service config data
// in the data plane combiner. Deletes itself when done.
class ServiceConfigSetter {
public:
ServiceConfigSetter(
channel_data* chand,
RefCountedPtr<ServerRetryThrottleData> retry_throttle_data,
RefCountedPtr<ClientChannelMethodParamsTable> method_params_table)
: chand_(chand),
retry_throttle_data_(std::move(retry_throttle_data)),
method_params_table_(std::move(method_params_table)) {
GRPC_CHANNEL_STACK_REF(chand->owning_stack, "ServiceConfigSetter");
GRPC_CLOSURE_INIT(&closure_, SetServiceConfigData, this,
grpc_combiner_scheduler(chand->data_plane_combiner));
GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE);
}
// Update picker.
chand->picker = std::move(picker);
// Re-process queued picks.
for (QueuedPick* pick = chand->queued_picks; pick != nullptr;
pick = pick->next) {
start_pick_locked(pick->elem, GRPC_ERROR_NONE);
private:
static void SetServiceConfigData(void* arg, grpc_error* ignored) {
ServiceConfigSetter* self = static_cast<ServiceConfigSetter*>(arg);
channel_data* chand = self->chand_;
// Update channel state.
chand->received_service_config_data = true;
chand->retry_throttle_data = std::move(self->retry_throttle_data_);
chand->method_params_table = std::move(self->method_params_table_);
// Apply service config to queued picks.
for (QueuedPick* pick = chand->queued_picks; pick != nullptr;
pick = pick->next) {
maybe_apply_service_config_to_call_locked(pick->elem);
}
// Clean up.
GRPC_CHANNEL_STACK_UNREF(self->chand_->owning_stack, "ServiceConfigSetter");
Delete(self);
}
channel_data* chand_;
RefCountedPtr<ServerRetryThrottleData> retry_throttle_data_;
RefCountedPtr<ClientChannelMethodParamsTable> method_params_table_;
grpc_closure closure_;
};
//
// ExternalConnectivityWatcher::WatcherList
//
int ExternalConnectivityWatcher::WatcherList::size() const {
MutexLock lock(&mu_);
int count = 0;
for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) {
++count;
}
return count;
}
namespace grpc_core {
namespace {
ExternalConnectivityWatcher* ExternalConnectivityWatcher::WatcherList::Lookup(
grpc_closure* on_complete) const {
MutexLock lock(&mu_);
ExternalConnectivityWatcher* w = head_;
while (w != nullptr && w->on_complete_ != on_complete) {
w = w->next_;
}
return w;
}
void ExternalConnectivityWatcher::WatcherList::Add(
ExternalConnectivityWatcher* watcher) {
GPR_ASSERT(Lookup(watcher->on_complete_) == nullptr);
MutexLock lock(&mu_);
GPR_ASSERT(watcher->next_ == nullptr);
watcher->next_ = head_;
head_ = watcher;
}
void ExternalConnectivityWatcher::WatcherList::Remove(
const ExternalConnectivityWatcher* watcher) {
MutexLock lock(&mu_);
if (watcher == head_) {
head_ = watcher->next_;
return;
}
for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) {
if (w->next_ == watcher) {
w->next_ = w->next_->next_;
return;
}
}
GPR_UNREACHABLE_CODE(return );
}
//
// ExternalConnectivityWatcher
//
ExternalConnectivityWatcher::ExternalConnectivityWatcher(
channel_data* chand, grpc_polling_entity pollent,
grpc_connectivity_state* state, grpc_closure* on_complete,
grpc_closure* watcher_timer_init)
: chand_(chand),
pollent_(pollent),
state_(state),
on_complete_(on_complete),
watcher_timer_init_(watcher_timer_init) {
grpc_polling_entity_add_to_pollset_set(&pollent_, chand_->interested_parties);
GRPC_CHANNEL_STACK_REF(chand_->owning_stack, "ExternalConnectivityWatcher");
GRPC_CLOSURE_SCHED(
GRPC_CLOSURE_INIT(&my_closure_, WatchConnectivityStateLocked, this,
grpc_combiner_scheduler(chand_->combiner)),
GRPC_ERROR_NONE);
}
ExternalConnectivityWatcher::~ExternalConnectivityWatcher() {
grpc_polling_entity_del_from_pollset_set(&pollent_,
chand_->interested_parties);
GRPC_CHANNEL_STACK_UNREF(chand_->owning_stack, "ExternalConnectivityWatcher");
}
void ExternalConnectivityWatcher::OnWatchCompleteLocked(void* arg,
grpc_error* error) {
ExternalConnectivityWatcher* self =
static_cast<ExternalConnectivityWatcher*>(arg);
grpc_closure* on_complete = self->on_complete_;
self->chand_->external_connectivity_watcher_list->Remove(self);
Delete(self);
GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_REF(error));
}
void ExternalConnectivityWatcher::WatchConnectivityStateLocked(
void* arg, grpc_error* ignored) {
ExternalConnectivityWatcher* self =
static_cast<ExternalConnectivityWatcher*>(arg);
if (self->state_ == nullptr) {
// Handle cancellation.
GPR_ASSERT(self->watcher_timer_init_ == nullptr);
ExternalConnectivityWatcher* found =
self->chand_->external_connectivity_watcher_list->Lookup(
self->on_complete_);
if (found != nullptr) {
grpc_connectivity_state_notify_on_state_change(
&found->chand_->state_tracker, nullptr, &found->my_closure_);
}
Delete(self);
return;
}
// New watcher.
self->chand_->external_connectivity_watcher_list->Add(self);
// This assumes that the closure is scheduled on the ExecCtx scheduler
// and that GRPC_CLOSURE_RUN would run the closure immediately.
GRPC_CLOSURE_RUN(self->watcher_timer_init_, GRPC_ERROR_NONE);
GRPC_CLOSURE_INIT(&self->my_closure_, OnWatchCompleteLocked, self,
grpc_combiner_scheduler(self->chand_->combiner));
grpc_connectivity_state_notify_on_state_change(
&self->chand_->state_tracker, self->state_, &self->my_closure_);
}
//
// ClientChannelControlHelper
//
class ClientChannelControlHelper
: public LoadBalancingPolicy::ChannelControlHelper {
@ -222,8 +458,10 @@ class ClientChannelControlHelper
void UpdateState(
grpc_connectivity_state state, grpc_error* state_error,
UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker) override {
grpc_error* disconnect_error =
chand_->disconnect_error.Load(grpc_core::MemoryOrder::ACQUIRE);
if (grpc_client_channel_routing_trace.enabled()) {
const char* extra = chand_->disconnect_error == GRPC_ERROR_NONE
const char* extra = disconnect_error == GRPC_ERROR_NONE
? ""
: " (ignoring -- channel shutting down)";
gpr_log(GPR_INFO, "chand=%p: update: state=%s error=%s picker=%p%s",
@ -231,9 +469,10 @@ class ClientChannelControlHelper
grpc_error_string(state_error), picker.get(), extra);
}
// Do update only if not shutting down.
if (chand_->disconnect_error == GRPC_ERROR_NONE) {
set_connectivity_state_and_picker_locked(chand_, state, state_error,
"helper", std::move(picker));
if (disconnect_error == GRPC_ERROR_NONE) {
// Will delete itself.
New<ConnectivityStateAndPickerSetter>(chand_, state, state_error,
"helper", std::move(picker));
} else {
GRPC_ERROR_UNREF(state_error);
}
@ -255,7 +494,6 @@ static bool process_resolver_result_locked(
void* arg, grpc_core::Resolver::Result* result, const char** lb_policy_name,
grpc_core::RefCountedPtr<LoadBalancingPolicy::Config>* lb_policy_config) {
channel_data* chand = static_cast<channel_data*>(arg);
chand->have_service_config = true;
ProcessedResolverResult resolver_result(result, chand->enable_retries);
grpc_core::UniquePtr<char> service_config_json =
resolver_result.service_config_json();
@ -263,9 +501,11 @@ static bool process_resolver_result_locked(
gpr_log(GPR_INFO, "chand=%p: resolver returned service config: \"%s\"",
chand, service_config_json.get());
}
// Update channel state.
chand->retry_throttle_data = resolver_result.retry_throttle_data();
chand->method_params_table = resolver_result.method_params_table();
// Create service config setter to update channel state in the data
// plane combiner. Destroys itself when done.
grpc_core::New<grpc_core::ServiceConfigSetter>(
chand, resolver_result.retry_throttle_data(),
resolver_result.method_params_table());
// Swap out the data used by cc_get_channel_info().
gpr_mu_lock(&chand->info_mu);
chand->info_lb_policy_name = resolver_result.lb_policy_name();
@ -280,11 +520,6 @@ static bool process_resolver_result_locked(
// Return results.
*lb_policy_name = chand->info_lb_policy_name.get();
*lb_policy_config = resolver_result.lb_policy_config();
// Apply service config to queued picks.
for (QueuedPick* pick = chand->queued_picks; pick != nullptr;
pick = pick->next) {
maybe_apply_service_config_to_call_locked(pick->elem);
}
return service_config_changed;
}
@ -342,12 +577,16 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) {
}
if (op->disconnect_with_error != GRPC_ERROR_NONE) {
chand->disconnect_error = op->disconnect_with_error;
grpc_error* error = GRPC_ERROR_NONE;
GPR_ASSERT(chand->disconnect_error.CompareExchangeStrong(
&error, op->disconnect_with_error, grpc_core::MemoryOrder::ACQ_REL,
grpc_core::MemoryOrder::ACQUIRE));
grpc_pollset_set_del_pollset_set(
chand->resolving_lb_policy->interested_parties(),
chand->interested_parties);
chand->resolving_lb_policy.reset();
set_connectivity_state_and_picker_locked(
// Will delete itself.
grpc_core::New<grpc_core::ConnectivityStateAndPickerSetter>(
chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(op->disconnect_with_error),
"shutdown from API",
grpc_core::UniquePtr<LoadBalancingPolicy::SubchannelPicker>(
@ -397,17 +636,14 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem,
GPR_ASSERT(args->is_last);
GPR_ASSERT(elem->filter == &grpc_client_channel_filter);
// Initialize data members.
chand->data_plane_combiner = grpc_combiner_create();
chand->combiner = grpc_combiner_create();
grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE,
"client_channel");
chand->disconnect_error = GRPC_ERROR_NONE;
chand->disconnect_error.Store(GRPC_ERROR_NONE,
grpc_core::MemoryOrder::RELAXED);
gpr_mu_init(&chand->info_mu);
gpr_mu_init(&chand->external_connectivity_watcher_list_mu);
gpr_mu_lock(&chand->external_connectivity_watcher_list_mu);
chand->external_connectivity_watcher_list_head = nullptr;
gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu);
chand->external_connectivity_watcher_list.Init();
chand->owning_stack = args->channel_stack;
chand->deadline_checking_enabled =
grpc_deadline_checking_enabled(args->channel_args);
@ -511,11 +747,13 @@ static void cc_destroy_channel_elem(grpc_channel_element* elem) {
chand->method_params_table.reset();
grpc_client_channel_stop_backup_polling(chand->interested_parties);
grpc_pollset_set_destroy(chand->interested_parties);
GRPC_COMBINER_UNREF(chand->data_plane_combiner, "client_channel");
GRPC_COMBINER_UNREF(chand->combiner, "client_channel");
GRPC_ERROR_UNREF(chand->disconnect_error);
GRPC_ERROR_UNREF(
chand->disconnect_error.Load(grpc_core::MemoryOrder::RELAXED));
grpc_connectivity_state_destroy(&chand->state_tracker);
gpr_mu_destroy(&chand->info_mu);
gpr_mu_destroy(&chand->external_connectivity_watcher_list_mu);
chand->external_connectivity_watcher_list.Destroy();
}
/*************************************************************************
@ -1261,7 +1499,7 @@ static void do_retry(grpc_call_element* elem,
}
// Schedule retry after computed delay.
GRPC_CLOSURE_INIT(&calld->pick_closure, start_pick_locked, elem,
grpc_combiner_scheduler(chand->combiner));
grpc_combiner_scheduler(chand->data_plane_combiner));
grpc_timer_init(&calld->retry_timer, next_attempt_time, &calld->pick_closure);
// Update bookkeeping.
if (retry_state != nullptr) retry_state->retry_dispatched = true;
@ -2488,7 +2726,7 @@ class QueuedPickCanceller {
auto* chand = static_cast<channel_data*>(elem->channel_data);
GRPC_CALL_STACK_REF(calld->owning_call, "QueuedPickCanceller");
GRPC_CLOSURE_INIT(&closure_, &CancelLocked, this,
grpc_combiner_scheduler(chand->combiner));
grpc_combiner_scheduler(chand->data_plane_combiner));
grpc_call_combiner_set_notify_on_cancel(calld->call_combiner, &closure_);
}
@ -2628,7 +2866,7 @@ static void maybe_apply_service_config_to_call_locked(grpc_call_element* elem) {
call_data* calld = static_cast<call_data*>(elem->call_data);
// Apply service config data to the call only once, and only if the
// channel has the data available.
if (GPR_LIKELY(chand->have_service_config &&
if (GPR_LIKELY(chand->received_service_config_data &&
!calld->service_config_applied)) {
calld->service_config_applied = true;
apply_service_config_to_call_locked(elem);
@ -2676,7 +2914,7 @@ static void start_pick_locked(void* arg, grpc_error* error) {
.send_initial_metadata_flags;
// Apply service config to call if needed.
maybe_apply_service_config_to_call_locked(elem);
// When done, we schedule this closure to leave the channel combiner.
// When done, we schedule this closure to leave the data plane combiner.
GRPC_CLOSURE_INIT(&calld->pick_closure, pick_done, elem,
grpc_schedule_on_exec_ctx);
// Attempt pick.
@ -2691,12 +2929,14 @@ static void start_pick_locked(void* arg, grpc_error* error) {
grpc_error_string(error));
}
switch (pick_result) {
case LoadBalancingPolicy::PICK_TRANSIENT_FAILURE:
case LoadBalancingPolicy::PICK_TRANSIENT_FAILURE: {
// If we're shutting down, fail all RPCs.
if (chand->disconnect_error != GRPC_ERROR_NONE) {
grpc_error* disconnect_error =
chand->disconnect_error.Load(grpc_core::MemoryOrder::ACQUIRE);
if (disconnect_error != GRPC_ERROR_NONE) {
GRPC_ERROR_UNREF(error);
GRPC_CLOSURE_SCHED(&calld->pick_closure,
GRPC_ERROR_REF(chand->disconnect_error));
GRPC_ERROR_REF(disconnect_error));
break;
}
// If wait_for_ready is false, then the error indicates the RPC
@ -2722,7 +2962,8 @@ static void start_pick_locked(void* arg, grpc_error* error) {
// If wait_for_ready is true, then queue to retry when we get a new
// picker.
GRPC_ERROR_UNREF(error);
// Fallthrough
}
// Fallthrough
case LoadBalancingPolicy::PICK_QUEUE:
if (!calld->pick_queued) add_call_to_queued_picks_locked(elem);
break;
@ -2816,7 +3057,8 @@ static void cc_start_transport_stream_op_batch(
}
GRPC_CLOSURE_SCHED(
GRPC_CLOSURE_INIT(&batch->handler_private.closure, start_pick_locked,
elem, grpc_combiner_scheduler(chand->combiner)),
elem,
grpc_combiner_scheduler(chand->data_plane_combiner)),
GRPC_ERROR_NONE);
} else {
// For all other batches, release the call combiner.
@ -2875,6 +3117,10 @@ const grpc_channel_filter grpc_client_channel_filter = {
"client-channel",
};
//
// functions exported to the rest of core
//
void grpc_client_channel_set_channelz_node(
grpc_channel_element* elem, grpc_core::channelz::ClientChannelNode* node) {
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
@ -2914,120 +3160,10 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state(
return out;
}
typedef struct external_connectivity_watcher {
channel_data* chand;
grpc_polling_entity pollent;
grpc_closure* on_complete;
grpc_closure* watcher_timer_init;
grpc_connectivity_state* state;
grpc_closure my_closure;
struct external_connectivity_watcher* next;
} external_connectivity_watcher;
static external_connectivity_watcher* lookup_external_connectivity_watcher(
channel_data* chand, grpc_closure* on_complete) {
gpr_mu_lock(&chand->external_connectivity_watcher_list_mu);
external_connectivity_watcher* w =
chand->external_connectivity_watcher_list_head;
while (w != nullptr && w->on_complete != on_complete) {
w = w->next;
}
gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu);
return w;
}
static void external_connectivity_watcher_list_append(
channel_data* chand, external_connectivity_watcher* w) {
GPR_ASSERT(!lookup_external_connectivity_watcher(chand, w->on_complete));
gpr_mu_lock(&w->chand->external_connectivity_watcher_list_mu);
GPR_ASSERT(!w->next);
w->next = chand->external_connectivity_watcher_list_head;
chand->external_connectivity_watcher_list_head = w;
gpr_mu_unlock(&w->chand->external_connectivity_watcher_list_mu);
}
static void external_connectivity_watcher_list_remove(
channel_data* chand, external_connectivity_watcher* to_remove) {
GPR_ASSERT(
lookup_external_connectivity_watcher(chand, to_remove->on_complete));
gpr_mu_lock(&chand->external_connectivity_watcher_list_mu);
if (to_remove == chand->external_connectivity_watcher_list_head) {
chand->external_connectivity_watcher_list_head = to_remove->next;
gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu);
return;
}
external_connectivity_watcher* w =
chand->external_connectivity_watcher_list_head;
while (w != nullptr) {
if (w->next == to_remove) {
w->next = w->next->next;
gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu);
return;
}
w = w->next;
}
GPR_UNREACHABLE_CODE(return );
}
int grpc_client_channel_num_external_connectivity_watchers(
grpc_channel_element* elem) {
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
int count = 0;
gpr_mu_lock(&chand->external_connectivity_watcher_list_mu);
external_connectivity_watcher* w =
chand->external_connectivity_watcher_list_head;
while (w != nullptr) {
count++;
w = w->next;
}
gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu);
return count;
}
static void on_external_watch_complete_locked(void* arg, grpc_error* error) {
external_connectivity_watcher* w =
static_cast<external_connectivity_watcher*>(arg);
grpc_closure* follow_up = w->on_complete;
grpc_polling_entity_del_from_pollset_set(&w->pollent,
w->chand->interested_parties);
GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack,
"external_connectivity_watcher");
external_connectivity_watcher_list_remove(w->chand, w);
gpr_free(w);
GRPC_CLOSURE_SCHED(follow_up, GRPC_ERROR_REF(error));
}
static void watch_connectivity_state_locked(void* arg,
grpc_error* error_ignored) {
external_connectivity_watcher* w =
static_cast<external_connectivity_watcher*>(arg);
external_connectivity_watcher* found = nullptr;
if (w->state != nullptr) {
external_connectivity_watcher_list_append(w->chand, w);
// An assumption is being made that the closure is scheduled on the exec ctx
// scheduler and that GRPC_CLOSURE_RUN would run the closure immediately.
GRPC_CLOSURE_RUN(w->watcher_timer_init, GRPC_ERROR_NONE);
GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete_locked, w,
grpc_combiner_scheduler(w->chand->combiner));
grpc_connectivity_state_notify_on_state_change(&w->chand->state_tracker,
w->state, &w->my_closure);
} else {
GPR_ASSERT(w->watcher_timer_init == nullptr);
found = lookup_external_connectivity_watcher(w->chand, w->on_complete);
if (found) {
GPR_ASSERT(found->on_complete == w->on_complete);
grpc_connectivity_state_notify_on_state_change(
&found->chand->state_tracker, nullptr, &found->my_closure);
}
grpc_polling_entity_del_from_pollset_set(&w->pollent,
w->chand->interested_parties);
GRPC_CHANNEL_STACK_UNREF(w->chand->owning_stack,
"external_connectivity_watcher");
gpr_free(w);
}
return chand->external_connectivity_watcher_list->size();
}
void grpc_client_channel_watch_connectivity_state(
@ -3035,21 +3171,8 @@ void grpc_client_channel_watch_connectivity_state(
grpc_connectivity_state* state, grpc_closure* closure,
grpc_closure* watcher_timer_init) {
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
external_connectivity_watcher* w =
static_cast<external_connectivity_watcher*>(gpr_zalloc(sizeof(*w)));
w->chand = chand;
w->pollent = pollent;
w->on_complete = closure;
w->state = state;
w->watcher_timer_init = watcher_timer_init;
grpc_polling_entity_add_to_pollset_set(&w->pollent,
chand->interested_parties);
GRPC_CHANNEL_STACK_REF(w->chand->owning_stack,
"external_connectivity_watcher");
GRPC_CLOSURE_SCHED(
GRPC_CLOSURE_INIT(&w->my_closure, watch_connectivity_state_locked, w,
grpc_combiner_scheduler(chand->combiner)),
GRPC_ERROR_NONE);
grpc_core::New<grpc_core::ExternalConnectivityWatcher>(
chand, pollent, state, closure, watcher_timer_init);
}
grpc_core::RefCountedPtr<grpc_core::SubchannelCall>

@ -287,7 +287,6 @@ HealthCheckClient::CallState::CallState(
->GetInitialCallSizeEstimate(0))),
payload_(context_) {
grpc_call_combiner_init(&call_combiner_);
gpr_atm_rel_store(&seen_response_, static_cast<gpr_atm>(0));
}
HealthCheckClient::CallState::~CallState() {
@ -295,9 +294,6 @@ HealthCheckClient::CallState::~CallState() {
gpr_log(GPR_INFO, "HealthCheckClient %p: destroying CallState %p",
health_check_client_.get(), this);
}
// The subchannel call is in the arena, so reset the pointer before we destroy
// the arena.
call_.reset();
for (size_t i = 0; i < GRPC_CONTEXT_COUNT; i++) {
if (context_[i].destroy != nullptr) {
context_[i].destroy(context_[i].value);
@ -349,7 +345,6 @@ void HealthCheckClient::CallState::StartCall() {
return;
}
// Initialize payload and batch.
memset(&batch_, 0, sizeof(batch_));
payload_.context = context_;
batch_.payload = &payload_;
// on_complete callback takes ref, handled manually.
@ -401,8 +396,6 @@ void HealthCheckClient::CallState::StartCall() {
// Start batch.
StartBatch(&batch_);
// Initialize recv_trailing_metadata batch.
memset(&recv_trailing_metadata_batch_, 0,
sizeof(recv_trailing_metadata_batch_));
recv_trailing_metadata_batch_.payload = &payload_;
// Add recv_trailing_metadata op.
grpc_metadata_batch_init(&recv_trailing_metadata_);
@ -439,12 +432,22 @@ void HealthCheckClient::CallState::StartBatch(
GRPC_ERROR_NONE, "start_subchannel_batch");
}
void HealthCheckClient::CallState::AfterCallStackDestruction(
void* arg, grpc_error* error) {
HealthCheckClient::CallState* self =
static_cast<HealthCheckClient::CallState*>(arg);
self->Unref(DEBUG_LOCATION, "cancel");
}
void HealthCheckClient::CallState::OnCancelComplete(void* arg,
grpc_error* error) {
HealthCheckClient::CallState* self =
static_cast<HealthCheckClient::CallState*>(arg);
GRPC_CALL_COMBINER_STOP(&self->call_combiner_, "health_cancel");
self->Unref(DEBUG_LOCATION, "cancel");
GRPC_CLOSURE_INIT(&self->after_call_stack_destruction_,
AfterCallStackDestruction, self, grpc_schedule_on_exec_ctx);
self->call_->SetAfterCallStackDestroy(&self->after_call_stack_destruction_);
self->call_.reset();
}
void HealthCheckClient::CallState::StartCancel(void* arg, grpc_error* error) {
@ -458,7 +461,9 @@ void HealthCheckClient::CallState::StartCancel(void* arg, grpc_error* error) {
}
void HealthCheckClient::CallState::Cancel() {
if (call_ != nullptr) {
bool expected = false;
if (cancelled_.CompareExchangeStrong(&expected, true, MemoryOrder::ACQ_REL,
MemoryOrder::ACQUIRE)) {
Ref(DEBUG_LOCATION, "cancel").release();
GRPC_CALL_COMBINER_START(
&call_combiner_,
@ -501,13 +506,12 @@ void HealthCheckClient::CallState::DoneReadingRecvMessage(grpc_error* error) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("backend unhealthy");
}
health_check_client_->SetHealthStatus(state, error);
gpr_atm_rel_store(&seen_response_, static_cast<gpr_atm>(1));
seen_response_.Store(true, MemoryOrder::RELEASE);
grpc_slice_buffer_destroy_internal(&recv_message_buffer_);
// Start another recv_message batch.
// This re-uses the ref we're holding.
// Note: Can't just reuse batch_ here, since we don't know that all
// callbacks from the original batch have completed yet.
memset(&recv_message_batch_, 0, sizeof(recv_message_batch_));
recv_message_batch_.payload = &payload_;
payload_.recv_message.recv_message = &recv_message_;
payload_.recv_message.recv_message_ready = GRPC_CLOSURE_INIT(
@ -635,7 +639,7 @@ void HealthCheckClient::CallState::CallEnded(bool retry) {
health_check_client_->call_state_.reset();
if (retry) {
GPR_ASSERT(!health_check_client_->shutting_down_);
if (static_cast<bool>(gpr_atm_acq_load(&seen_response_))) {
if (seen_response_.Load(MemoryOrder::ACQUIRE)) {
// If the call fails after we've gotten a successful response, reset
// the backoff and restart the call immediately.
health_check_client_->retry_backoff_.Reset();

@ -22,13 +22,13 @@
#include <grpc/support/port_platform.h>
#include <grpc/grpc.h>
#include <grpc/support/atm.h>
#include <grpc/support/sync.h>
#include "src/core/ext/filters/client_channel/client_channel_channelz.h"
#include "src/core/ext/filters/client_channel/subchannel.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/arena.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/call_combiner.h"
@ -91,6 +91,8 @@ class HealthCheckClient : public InternallyRefCounted<HealthCheckClient> {
grpc_error* PullSliceFromRecvMessage();
void DoneReadingRecvMessage(grpc_error* error);
static void AfterCallStackDestruction(void* arg, grpc_error* error);
RefCountedPtr<HealthCheckClient> health_check_client_;
grpc_polling_entity pollent_;
@ -126,12 +128,18 @@ class HealthCheckClient : public InternallyRefCounted<HealthCheckClient> {
OrphanablePtr<ByteStream> recv_message_;
grpc_closure recv_message_ready_;
grpc_slice_buffer recv_message_buffer_;
gpr_atm seen_response_;
Atomic<bool> seen_response_{false};
// recv_trailing_metadata
grpc_metadata_batch recv_trailing_metadata_;
grpc_transport_stream_stats collect_stats_;
grpc_closure recv_trailing_metadata_ready_;
// True if the cancel_stream batch has been started.
Atomic<bool> cancelled_{false};
// Closure for call stack destruction.
grpc_closure after_call_stack_destruction_;
};
void StartCall();

@ -140,10 +140,9 @@ LoadBalancingPolicy::PickResult LoadBalancingPolicy::QueuePicker::Pick(
// the time this function returns, the pick will already have
// been processed, and we'll be trying to re-process the same
// pick again, leading to a crash.
// 2. In a subsequent PR, we will split the data plane and control
// plane synchronization into separate combiners, at which
// point this will need to hop from the data plane combiner into
// the control plane combiner.
// 2. We are currently running in the data plane combiner, but we
// need to bounce into the control plane combiner to call
// ExitIdleLocked().
if (!exit_idle_called_) {
exit_idle_called_ = true;
parent_->Ref().release(); // ref held by closure.

@ -234,12 +234,19 @@ class GrpcLb : public LoadBalancingPolicy {
// Returns the LB token to use for a drop, or null if the call
// should not be dropped.
// Intended to be called from picker, so calls will be externally
// synchronized.
//
// Note: This is called from the picker, so it will be invoked in
// the channel's data plane combiner, NOT the control plane
// combiner. It should not be accessed by any other part of the LB
// policy.
const char* ShouldDrop();
private:
grpc_grpclb_serverlist* serverlist_;
// Guarded by the channel's data plane combiner, NOT the control
// plane combiner. It should not be accessed by anything but the
// picker via the ShouldDrop() method.
size_t drop_index_ = 0;
};
@ -551,7 +558,7 @@ GrpcLb::PickResult GrpcLb::Picker::Pick(PickArgs* pick, grpc_error** error) {
// subchannel call (and therefore no client_load_reporting filter)
// for dropped calls.
if (client_stats_ != nullptr) {
client_stats_->AddCallDroppedLocked(drop_token);
client_stats_->AddCallDropped(drop_token);
}
return PICK_COMPLETE;
}
@ -910,7 +917,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
// Construct message payload.
GPR_ASSERT(send_message_payload_ == nullptr);
grpc_grpclb_request* request =
grpc_grpclb_load_report_request_create_locked(client_stats_.get());
grpc_grpclb_load_report_request_create(client_stats_.get());
// Skip client load report if the counters were all zero in the last
// report and they are still zero in this one.
if (LoadReportCountersAreZero(request)) {

@ -25,6 +25,8 @@
#include <grpc/support/atm.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gprpp/mutex_lock.h"
namespace grpc_core {
void GrpcLbClientStats::AddCallStarted() {
@ -43,11 +45,12 @@ void GrpcLbClientStats::AddCallFinished(
}
}
void GrpcLbClientStats::AddCallDroppedLocked(const char* token) {
void GrpcLbClientStats::AddCallDropped(const char* token) {
// Increment num_calls_started and num_calls_finished.
gpr_atm_full_fetch_add(&num_calls_started_, (gpr_atm)1);
gpr_atm_full_fetch_add(&num_calls_finished_, (gpr_atm)1);
// Record the drop.
MutexLock lock(&drop_count_mu_);
if (drop_token_counts_ == nullptr) {
drop_token_counts_.reset(New<DroppedCallCounts>());
}
@ -69,7 +72,7 @@ void AtomicGetAndResetCounter(int64_t* value, gpr_atm* counter) {
} // namespace
void GrpcLbClientStats::GetLocked(
void GrpcLbClientStats::Get(
int64_t* num_calls_started, int64_t* num_calls_finished,
int64_t* num_calls_finished_with_client_failed_to_send,
int64_t* num_calls_finished_known_received,
@ -80,6 +83,7 @@ void GrpcLbClientStats::GetLocked(
&num_calls_finished_with_client_failed_to_send_);
AtomicGetAndResetCounter(num_calls_finished_known_received,
&num_calls_finished_known_received_);
MutexLock lock(&drop_count_mu_);
*drop_token_counts = std::move(drop_token_counts_);
}

@ -41,20 +41,19 @@ class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
typedef InlinedVector<DropTokenCount, 10> DroppedCallCounts;
GrpcLbClientStats() {}
GrpcLbClientStats() { gpr_mu_init(&drop_count_mu_); }
~GrpcLbClientStats() { gpr_mu_destroy(&drop_count_mu_); }
void AddCallStarted();
void AddCallFinished(bool finished_with_client_failed_to_send,
bool finished_known_received);
// This method is not thread-safe; caller must synchronize.
void AddCallDroppedLocked(const char* token);
void AddCallDropped(const char* token);
// This method is not thread-safe; caller must synchronize.
void GetLocked(int64_t* num_calls_started, int64_t* num_calls_finished,
int64_t* num_calls_finished_with_client_failed_to_send,
int64_t* num_calls_finished_known_received,
UniquePtr<DroppedCallCounts>* drop_token_counts);
void Get(int64_t* num_calls_started, int64_t* num_calls_finished,
int64_t* num_calls_finished_with_client_failed_to_send,
int64_t* num_calls_finished_known_received,
UniquePtr<DroppedCallCounts>* drop_token_counts);
// A destruction function to use as the user_data key when attaching
// client stats to a grpc_mdelem.
@ -63,13 +62,12 @@ class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
}
private:
// This field must only be accessed via *_locked() methods.
UniquePtr<DroppedCallCounts> drop_token_counts_;
// These fields may be accessed from multiple threads at a time.
gpr_atm num_calls_started_ = 0;
gpr_atm num_calls_finished_ = 0;
gpr_atm num_calls_finished_with_client_failed_to_send_ = 0;
gpr_atm num_calls_finished_known_received_ = 0;
gpr_mu drop_count_mu_; // Guards drop_token_counts_.
UniquePtr<DroppedCallCounts> drop_token_counts_;
};
} // namespace grpc_core

@ -107,7 +107,7 @@ static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field,
return true;
}
grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked(
grpc_grpclb_request* grpc_grpclb_load_report_request_create(
grpc_core::GrpcLbClientStats* client_stats) {
grpc_grpclb_request* req = static_cast<grpc_grpclb_request*>(
gpr_zalloc(sizeof(grpc_grpclb_request)));
@ -122,7 +122,7 @@ grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked(
req->client_stats.calls_finished_with_drop.funcs.encode = encode_drops;
grpc_core::UniquePtr<grpc_core::GrpcLbClientStats::DroppedCallCounts>
drop_counts;
client_stats->GetLocked(
client_stats->Get(
&req->client_stats.num_calls_started,
&req->client_stats.num_calls_finished,
&req->client_stats.num_calls_finished_with_client_failed_to_send,

@ -43,7 +43,7 @@ typedef struct {
/** Create a request for a gRPC LB service under \a lb_service_name */
grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name);
grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked(
grpc_grpclb_request* grpc_grpclb_load_report_request_create(
grpc_core::GrpcLbClientStats* client_stats);
/** Protocol Buffers v3-encode \a request */

@ -186,10 +186,17 @@ void PickFirst::ShutdownLocked() {
}
void PickFirst::ExitIdleLocked() {
if (shutdown_) return;
if (idle_) {
idle_ = false;
if (subchannel_list_ != nullptr &&
subchannel_list_->num_subchannels() > 0) {
if (subchannel_list_ == nullptr ||
subchannel_list_->num_subchannels() == 0) {
grpc_error* error =
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No addresses to connect to");
channel_control_helper()->UpdateState(
GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error),
UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
} else {
subchannel_list_->subchannel(0)
->CheckConnectivityStateAndStartWatchingLocked();
}
@ -253,13 +260,19 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
grpc_channel_args_destroy(new_args);
if (subchannel_list->num_subchannels() == 0) {
// Empty update or no valid subchannels. Unsubscribe from all current
// subchannels and put the channel in TRANSIENT_FAILURE.
// subchannels.
subchannel_list_ = std::move(subchannel_list); // Empty list.
selected_ = nullptr;
grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update");
channel_control_helper()->UpdateState(
GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error),
UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
// If not idle, put the channel in TRANSIENT_FAILURE.
// (If we are idle, then this will happen in ExitIdleLocked() if we
// haven't gotten a non-empty update by the time the application tries
// to start a new call.)
if (!idle_) {
grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update");
channel_control_helper()->UpdateState(
GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error),
UniquePtr<SubchannelPicker>(New<TransientFailurePicker>(error)));
}
return;
}
// If one of the subchannels in the new list is already in state

@ -68,7 +68,9 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include "include/grpc/support/alloc.h"
#include "src/core/ext/filters/client_channel/client_channel.h"
#include "src/core/ext/filters/client_channel/lb_policy.h"
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds.h"
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h"
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h"
@ -85,6 +87,7 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/mutex_lock.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -114,6 +117,7 @@ TraceFlag grpc_lb_xds_trace(false, "xds");
namespace {
constexpr char kXds[] = "xds_experimental";
constexpr char kDefaultLocalityName[] = "xds_default_locality";
class XdsLb : public LoadBalancingPolicy {
public:
@ -128,6 +132,9 @@ class XdsLb : public LoadBalancingPolicy {
channelz::ChildRefsList* child_channels) override;
private:
struct LocalityServerlistEntry;
using LocalityList = InlinedVector<UniquePtr<LocalityServerlistEntry>, 1>;
/// Contains a channel to the LB server and all the data related to the
/// channel.
class BalancerChannelState
@ -266,25 +273,88 @@ class XdsLb : public LoadBalancingPolicy {
RefCountedPtr<XdsLbClientStats> client_stats_;
};
class Helper : public ChannelControlHelper {
class LocalityMap {
public:
explicit Helper(RefCountedPtr<XdsLb> parent) : parent_(std::move(parent)) {}
class LocalityEntry : public InternallyRefCounted<LocalityEntry> {
public:
explicit LocalityEntry(RefCountedPtr<XdsLb> parent)
: parent_(std::move(parent)) {
gpr_mu_init(&child_policy_mu_);
}
~LocalityEntry() { gpr_mu_destroy(&child_policy_mu_); }
void UpdateLocked(xds_grpclb_serverlist* serverlist,
LoadBalancingPolicy::Config* child_policy_config,
const grpc_channel_args* args);
void ShutdownLocked();
void ResetBackoffLocked();
void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* child_channels);
void Orphan() override;
private:
class Helper : public ChannelControlHelper {
public:
explicit Helper(RefCountedPtr<LocalityEntry> entry)
: entry_(std::move(entry)) {}
Subchannel* CreateSubchannel(const grpc_channel_args& args) override;
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override;
void UpdateState(grpc_connectivity_state state, grpc_error* state_error,
UniquePtr<SubchannelPicker> picker) override;
void RequestReresolution() override;
void set_child(LoadBalancingPolicy* child) { child_ = child; }
private:
bool CalledByPendingChild() const;
bool CalledByCurrentChild() const;
RefCountedPtr<LocalityEntry> entry_;
LoadBalancingPolicy* child_ = nullptr;
};
// Methods for dealing with the child policy.
OrphanablePtr<LoadBalancingPolicy> CreateChildPolicyLocked(
const char* name, const grpc_channel_args* args);
grpc_channel_args* CreateChildPolicyArgsLocked(
const grpc_channel_args* args);
OrphanablePtr<LoadBalancingPolicy> child_policy_;
OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
// Lock held when modifying the value of child_policy_ or
// pending_child_policy_.
gpr_mu child_policy_mu_;
RefCountedPtr<XdsLb> parent_;
};
Subchannel* CreateSubchannel(const grpc_channel_args& args) override;
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override;
void UpdateState(grpc_connectivity_state state, grpc_error* state_error,
UniquePtr<SubchannelPicker> picker) override;
void RequestReresolution() override;
LocalityMap() { gpr_mu_init(&child_refs_mu_); }
~LocalityMap() { gpr_mu_destroy(&child_refs_mu_); }
void set_child(LoadBalancingPolicy* child) { child_ = child; }
void UpdateLocked(const LocalityList& locality_list,
LoadBalancingPolicy::Config* child_policy_config,
const grpc_channel_args* args, XdsLb* parent);
void ShutdownLocked();
void ResetBackoffLocked();
void FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* child_channels);
private:
bool CalledByPendingChild() const;
bool CalledByCurrentChild() const;
void PruneLocalities(const LocalityList& locality_list);
Map<UniquePtr<char>, OrphanablePtr<LocalityEntry>, StringLess> map_;
// Lock held while filling child refs for all localities
// inside the map
gpr_mu child_refs_mu_;
};
RefCountedPtr<XdsLb> parent_;
LoadBalancingPolicy* child_ = nullptr;
struct LocalityServerlistEntry {
~LocalityServerlistEntry() {
gpr_free(locality_name);
xds_grpclb_destroy_serverlist(serverlist);
}
char* locality_name;
// The deserialized response from the balancer. May be nullptr until one
// such response has arrived.
xds_grpclb_serverlist* serverlist;
};
~XdsLb();
@ -309,12 +379,6 @@ class XdsLb : public LoadBalancingPolicy {
// Callback to enter fallback mode.
static void OnFallbackTimerLocked(void* arg, grpc_error* error);
// Methods for dealing with the child policy.
void CreateOrUpdateChildPolicyLocked();
grpc_channel_args* CreateChildPolicyArgsLocked();
OrphanablePtr<LoadBalancingPolicy> CreateChildPolicyLocked(
const char* name, const grpc_channel_args* args);
// Who the client is trying to communicate with.
const char* server_name_ = nullptr;
@ -338,10 +402,6 @@ class XdsLb : public LoadBalancingPolicy {
// Timeout in milliseconds for the LB call. 0 means no deadline.
int lb_call_timeout_ms_ = 0;
// The deserialized response from the balancer. May be nullptr until one
// such response has arrived.
xds_grpclb_serverlist* serverlist_ = nullptr;
// Timeout in milliseconds for before using fallback backend addresses.
// 0 means not using fallback.
RefCountedPtr<Config> fallback_policy_config_;
@ -355,11 +415,12 @@ class XdsLb : public LoadBalancingPolicy {
// The policy to use for the backends.
RefCountedPtr<Config> child_policy_config_;
OrphanablePtr<LoadBalancingPolicy> child_policy_;
OrphanablePtr<LoadBalancingPolicy> pending_child_policy_;
// Lock held when modifying the value of child_policy_ or
// pending_child_policy_.
gpr_mu child_policy_mu_;
// Map of policies to use in the backend
LocalityMap locality_map_;
LocalityList locality_serverlist_;
// TODO(mhaidry) : Add a pending locality map that may be swapped with the
// the current one when new localities in the pending map are ready
// to accept connections
};
//
@ -378,105 +439,6 @@ XdsLb::PickResult XdsLb::Picker::Pick(PickArgs* pick, grpc_error** error) {
return result;
}
//
// XdsLb::Helper
//
bool XdsLb::Helper::CalledByPendingChild() const {
GPR_ASSERT(child_ != nullptr);
return child_ == parent_->pending_child_policy_.get();
}
bool XdsLb::Helper::CalledByCurrentChild() const {
GPR_ASSERT(child_ != nullptr);
return child_ == parent_->child_policy_.get();
}
Subchannel* XdsLb::Helper::CreateSubchannel(const grpc_channel_args& args) {
if (parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* XdsLb::Helper::CreateChannel(const char* target,
const grpc_channel_args& args) {
if (parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return parent_->channel_control_helper()->CreateChannel(target, args);
}
void XdsLb::Helper::UpdateState(grpc_connectivity_state state,
grpc_error* state_error,
UniquePtr<SubchannelPicker> picker) {
if (parent_->shutting_down_) {
GRPC_ERROR_UNREF(state_error);
return;
}
// If this request is from the pending child policy, ignore it until
// it reports READY, at which point we swap it into place.
if (CalledByPendingChild()) {
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p helper %p] pending child policy %p reports state=%s",
parent_.get(), this, parent_->pending_child_policy_.get(),
grpc_connectivity_state_name(state));
}
if (state != GRPC_CHANNEL_READY) {
GRPC_ERROR_UNREF(state_error);
return;
}
grpc_pollset_set_del_pollset_set(
parent_->child_policy_->interested_parties(),
parent_->interested_parties());
MutexLock lock(&parent_->child_policy_mu_);
parent_->child_policy_ = std::move(parent_->pending_child_policy_);
} else if (!CalledByCurrentChild()) {
// This request is from an outdated child, so ignore it.
GRPC_ERROR_UNREF(state_error);
return;
}
// TODO(juanlishen): When in fallback mode, pass the child picker
// through without wrapping it. (Or maybe use a different helper for
// the fallback policy?)
GPR_ASSERT(parent_->lb_chand_ != nullptr);
RefCountedPtr<XdsLbClientStats> client_stats =
parent_->lb_chand_->lb_calld() == nullptr
? nullptr
: parent_->lb_chand_->lb_calld()->client_stats();
parent_->channel_control_helper()->UpdateState(
state, state_error,
UniquePtr<SubchannelPicker>(
New<Picker>(std::move(picker), std::move(client_stats))));
}
void XdsLb::Helper::RequestReresolution() {
if (parent_->shutting_down_) return;
// If there is a pending child policy, ignore re-resolution requests
// from the current child policy (or any outdated child).
if (parent_->pending_child_policy_ != nullptr && !CalledByPendingChild()) {
return;
}
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p] Re-resolution requested from the internal RR policy "
"(%p).",
parent_.get(), parent_->child_policy_.get());
}
GPR_ASSERT(parent_->lb_chand_ != nullptr);
// If we are talking to a balancer, we expect to get updated addresses
// from the balancer, so we can ignore the re-resolution request from
// the child policy. Otherwise, pass the re-resolution request up to the
// channel.
if (parent_->lb_chand_->lb_calld() == nullptr ||
!parent_->lb_chand_->lb_calld()->seen_initial_response()) {
parent_->channel_control_helper()->RequestReresolution();
}
}
//
// serverlist parsing code
//
@ -951,7 +913,9 @@ void XdsLb::BalancerChannelState::BalancerCallState::
self.release();
lb_calld->ScheduleNextClientLoadReportLocked();
}
if (xds_grpclb_serverlist_equals(xdslb_policy->serverlist_, serverlist)) {
if (!xdslb_policy->locality_serverlist_.empty() &&
xds_grpclb_serverlist_equals(
xdslb_policy->locality_serverlist_[0]->serverlist, serverlist)) {
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p] Incoming server list identical to current, "
@ -960,21 +924,31 @@ void XdsLb::BalancerChannelState::BalancerCallState::
}
xds_grpclb_destroy_serverlist(serverlist);
} else { /* new serverlist */
if (xdslb_policy->serverlist_ != nullptr) {
if (!xdslb_policy->locality_serverlist_.empty()) {
/* dispose of the old serverlist */
xds_grpclb_destroy_serverlist(xdslb_policy->serverlist_);
xds_grpclb_destroy_serverlist(
xdslb_policy->locality_serverlist_[0]->serverlist);
} else {
/* or dispose of the fallback */
xdslb_policy->fallback_backend_addresses_.reset();
if (xdslb_policy->fallback_timer_callback_pending_) {
grpc_timer_cancel(&xdslb_policy->lb_fallback_timer_);
}
/* Initialize locality serverlist, currently the list only handles
* one child */
xdslb_policy->locality_serverlist_.emplace_back(
MakeUnique<LocalityServerlistEntry>());
xdslb_policy->locality_serverlist_[0]->locality_name =
static_cast<char*>(gpr_strdup(kDefaultLocalityName));
}
// and update the copy in the XdsLb instance. This
// serverlist instance will be destroyed either upon the next
// update or when the XdsLb instance is destroyed.
xdslb_policy->serverlist_ = serverlist;
xdslb_policy->CreateOrUpdateChildPolicyLocked();
xdslb_policy->locality_serverlist_[0]->serverlist = serverlist;
xdslb_policy->locality_map_.UpdateLocked(
xdslb_policy->locality_serverlist_,
xdslb_policy->child_policy_config_.get(), xdslb_policy->args_,
xdslb_policy);
}
} else {
if (grpc_lb_xds_trace.enabled()) {
@ -1112,9 +1086,11 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) {
// ctor and dtor
//
XdsLb::XdsLb(Args args) : LoadBalancingPolicy(std::move(args)) {
XdsLb::XdsLb(Args args)
: LoadBalancingPolicy(std::move(args)),
locality_map_(),
locality_serverlist_() {
gpr_mu_init(&lb_chand_mu_);
gpr_mu_init(&child_policy_mu_);
// Record server name.
const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
const char* server_uri = grpc_channel_arg_get_string(arg);
@ -1141,10 +1117,7 @@ XdsLb::~XdsLb() {
gpr_mu_destroy(&lb_chand_mu_);
gpr_free((void*)server_name_);
grpc_channel_args_destroy(args_);
if (serverlist_ != nullptr) {
xds_grpclb_destroy_serverlist(serverlist_);
}
gpr_mu_destroy(&child_policy_mu_);
locality_serverlist_.clear();
}
void XdsLb::ShutdownLocked() {
@ -1152,19 +1125,7 @@ void XdsLb::ShutdownLocked() {
if (fallback_timer_callback_pending_) {
grpc_timer_cancel(&lb_fallback_timer_);
}
if (child_policy_ != nullptr) {
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
interested_parties());
}
if (pending_child_policy_ != nullptr) {
grpc_pollset_set_del_pollset_set(
pending_child_policy_->interested_parties(), interested_parties());
}
{
MutexLock lock(&child_policy_mu_);
child_policy_.reset();
pending_child_policy_.reset();
}
locality_map_.ShutdownLocked();
// We destroy the LB channel here instead of in our destructor because
// destroying the channel triggers a last callback to
// OnBalancerChannelConnectivityChangedLocked(), and we need to be
@ -1187,30 +1148,13 @@ void XdsLb::ResetBackoffLocked() {
if (pending_lb_chand_ != nullptr) {
grpc_channel_reset_connect_backoff(pending_lb_chand_->channel());
}
if (child_policy_ != nullptr) {
child_policy_->ResetBackoffLocked();
}
if (pending_child_policy_ != nullptr) {
pending_child_policy_->ResetBackoffLocked();
}
locality_map_.ResetBackoffLocked();
}
void XdsLb::FillChildRefsForChannelz(channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* child_channels) {
{
// Delegate to the child_policy_ to fill the children subchannels.
// This must be done holding child_policy_mu_, since this method does not
// run in the combiner.
MutexLock lock(&child_policy_mu_);
if (child_policy_ != nullptr) {
child_policy_->FillChildRefsForChannelz(child_subchannels,
child_channels);
}
if (pending_child_policy_ != nullptr) {
pending_child_policy_->FillChildRefsForChannelz(child_subchannels,
child_channels);
}
}
// Delegate to the child_policy_ to fill the children subchannels.
locality_map_.FillChildRefsForChannelz(child_subchannels, child_channels);
MutexLock lock(&lb_chand_mu_);
if (lb_chand_ != nullptr) {
grpc_core::channelz::ChannelNode* channel_node =
@ -1314,10 +1258,11 @@ void XdsLb::UpdateLocked(UpdateArgs args) {
// have been created from a serverlist.
// TODO(vpowar): Handle the fallback_address changes when we add support for
// fallback in xDS.
if (child_policy_ != nullptr) CreateOrUpdateChildPolicyLocked();
locality_map_.UpdateLocked(locality_serverlist_, child_policy_config_.get(),
args_, this);
// If this is the initial update, start the fallback timer.
if (is_initial_update) {
if (lb_fallback_timeout_ms_ > 0 && serverlist_ == nullptr &&
if (lb_fallback_timeout_ms_ > 0 && locality_serverlist_.empty() &&
!fallback_timer_callback_pending_) {
grpc_millis deadline = ExecCtx::Get()->Now() + lb_fallback_timeout_ms_;
Ref(DEBUG_LOCATION, "on_fallback_timer").release(); // Held by closure
@ -1341,8 +1286,8 @@ void XdsLb::OnFallbackTimerLocked(void* arg, grpc_error* error) {
xdslb_policy->fallback_timer_callback_pending_ = false;
// If we receive a serverlist after the timer fires but before this callback
// actually runs, don't fall back.
if (xdslb_policy->serverlist_ == nullptr && !xdslb_policy->shutting_down_ &&
error == GRPC_ERROR_NONE) {
if (xdslb_policy->locality_serverlist_.empty() &&
!xdslb_policy->shutting_down_ && error == GRPC_ERROR_NONE) {
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p] Fallback timer fired. Not using fallback backends",
@ -1352,11 +1297,70 @@ void XdsLb::OnFallbackTimerLocked(void* arg, grpc_error* error) {
xdslb_policy->Unref(DEBUG_LOCATION, "on_fallback_timer");
}
//
// code for interacting with the child policy
//
void XdsLb::LocalityMap::PruneLocalities(const LocalityList& locality_list) {
for (auto iter = map_.begin(); iter != map_.end();) {
bool found = false;
for (size_t i = 0; i < locality_list.size(); i++) {
if (!gpr_stricmp(locality_list[i]->locality_name, iter->first.get())) {
found = true;
}
}
if (!found) { // Remove entries not present in the locality list
MutexLock lock(&child_refs_mu_);
iter = map_.erase(iter);
} else
iter++;
}
}
void XdsLb::LocalityMap::UpdateLocked(
const LocalityList& locality_serverlist,
LoadBalancingPolicy::Config* child_policy_config,
const grpc_channel_args* args, XdsLb* parent) {
if (parent->shutting_down_) return;
for (size_t i = 0; i < locality_serverlist.size(); i++) {
UniquePtr<char> locality_name(
gpr_strdup(locality_serverlist[i]->locality_name));
auto iter = map_.find(locality_name);
if (iter == map_.end()) {
OrphanablePtr<LocalityEntry> new_entry =
MakeOrphanable<LocalityEntry>(parent->Ref());
MutexLock lock(&child_refs_mu_);
iter = map_.emplace(std::move(locality_name), std::move(new_entry)).first;
}
// Don't create new child policies if not directed to
xds_grpclb_serverlist* serverlist =
parent->locality_serverlist_[i]->serverlist;
iter->second->UpdateLocked(serverlist, child_policy_config, args);
}
PruneLocalities(locality_serverlist);
}
void grpc_core::XdsLb::LocalityMap::ShutdownLocked() {
MutexLock lock(&child_refs_mu_);
map_.clear();
}
void grpc_core::XdsLb::LocalityMap::ResetBackoffLocked() {
for (auto iter = map_.begin(); iter != map_.end(); iter++) {
iter->second->ResetBackoffLocked();
}
}
void grpc_core::XdsLb::LocalityMap::FillChildRefsForChannelz(
channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* child_channels) {
MutexLock lock(&child_refs_mu_);
for (auto iter = map_.begin(); iter != map_.end(); iter++) {
iter->second->FillChildRefsForChannelz(child_subchannels, child_channels);
}
}
grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
// Locality Entry child policy methods
grpc_channel_args*
XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyArgsLocked(
const grpc_channel_args* args_in) {
const grpc_arg args_to_add[] = {
// A channel arg indicating if the target is a backend inferred from a
// grpclb load balancer.
@ -1368,15 +1372,16 @@ grpc_channel_args* XdsLb::CreateChildPolicyArgsLocked() {
grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1),
};
return grpc_channel_args_copy_and_add(args_, args_to_add,
return grpc_channel_args_copy_and_add(args_in, args_to_add,
GPR_ARRAY_SIZE(args_to_add));
}
OrphanablePtr<LoadBalancingPolicy> XdsLb::CreateChildPolicyLocked(
OrphanablePtr<LoadBalancingPolicy>
XdsLb::LocalityMap::LocalityEntry::CreateChildPolicyLocked(
const char* name, const grpc_channel_args* args) {
Helper* helper = New<Helper>(Ref());
Helper* helper = New<Helper>(this->Ref());
LoadBalancingPolicy::Args lb_policy_args;
lb_policy_args.combiner = combiner();
lb_policy_args.combiner = parent_->combiner();
lb_policy_args.args = args;
lb_policy_args.channel_control_helper =
UniquePtr<ChannelControlHelper>(helper);
@ -1397,22 +1402,27 @@ OrphanablePtr<LoadBalancingPolicy> XdsLb::CreateChildPolicyLocked(
// child policy. This will make the child policy progress upon activity on xDS
// LB, which in turn is tied to the application's call.
grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
interested_parties());
parent_->interested_parties());
return lb_policy;
}
void XdsLb::CreateOrUpdateChildPolicyLocked() {
if (shutting_down_) return;
void XdsLb::LocalityMap::LocalityEntry::UpdateLocked(
xds_grpclb_serverlist* serverlist,
LoadBalancingPolicy::Config* child_policy_config,
const grpc_channel_args* args_in) {
if (parent_->shutting_down_) return;
// This should never be invoked if we do not have serverlist_, as fallback
// mode is disabled for xDS plugin.
// TODO(juanlishen): Change this as part of implementing fallback mode.
GPR_ASSERT(serverlist_ != nullptr);
GPR_ASSERT(serverlist_->num_servers > 0);
GPR_ASSERT(serverlist != nullptr);
GPR_ASSERT(serverlist->num_servers > 0);
// Construct update args.
UpdateArgs update_args;
update_args.addresses = ProcessServerlist(serverlist_);
update_args.config = child_policy_config_;
update_args.args = CreateChildPolicyArgsLocked();
update_args.addresses = ProcessServerlist(serverlist);
update_args.config =
child_policy_config == nullptr ? nullptr : child_policy_config->Ref();
update_args.args = CreateChildPolicyArgsLocked(args_in);
// If the child policy name changes, we need to create a new child
// policy. When this happens, we leave child_policy_ as-is and store
// the new child policy in pending_child_policy_. Once the new child
@ -1464,9 +1474,9 @@ void XdsLb::CreateOrUpdateChildPolicyLocked() {
// when the new child transitions into state READY.
// TODO(juanlishen): If the child policy is not configured via service config,
// use whatever algorithm is specified by the balancer.
const char* child_policy_name = child_policy_config_ == nullptr
const char* child_policy_name = child_policy_config == nullptr
? "round_robin"
: child_policy_config_->name();
: child_policy_config->name();
const bool create_policy =
// case 1
child_policy_ == nullptr ||
@ -1512,6 +1522,145 @@ void XdsLb::CreateOrUpdateChildPolicyLocked() {
policy_to_update->UpdateLocked(std::move(update_args));
}
void XdsLb::LocalityMap::LocalityEntry::ShutdownLocked() {
// Remove the child policy's interested_parties pollset_set from the
// xDS policy.
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
parent_->interested_parties());
if (pending_child_policy_ != nullptr) {
grpc_pollset_set_del_pollset_set(
pending_child_policy_->interested_parties(),
parent_->interested_parties());
}
{
MutexLock lock(&child_policy_mu_);
child_policy_.reset();
pending_child_policy_.reset();
}
}
void XdsLb::LocalityMap::LocalityEntry::ResetBackoffLocked() {
child_policy_->ResetBackoffLocked();
if (pending_child_policy_ != nullptr) {
pending_child_policy_->ResetBackoffLocked();
}
}
void XdsLb::LocalityMap::LocalityEntry::FillChildRefsForChannelz(
channelz::ChildRefsList* child_subchannels,
channelz::ChildRefsList* child_channels) {
MutexLock lock(&child_policy_mu_);
child_policy_->FillChildRefsForChannelz(child_subchannels, child_channels);
if (pending_child_policy_ != nullptr) {
pending_child_policy_->FillChildRefsForChannelz(child_subchannels,
child_channels);
}
}
void XdsLb::LocalityMap::LocalityEntry::Orphan() {
ShutdownLocked();
Unref();
}
//
// LocalityEntry::Helper implementation
//
bool XdsLb::LocalityMap::LocalityEntry::Helper::CalledByPendingChild() const {
GPR_ASSERT(child_ != nullptr);
return child_ == entry_->pending_child_policy_.get();
}
bool XdsLb::LocalityMap::LocalityEntry::Helper::CalledByCurrentChild() const {
GPR_ASSERT(child_ != nullptr);
return child_ == entry_->child_policy_.get();
}
Subchannel* XdsLb::LocalityMap::LocalityEntry::Helper::CreateSubchannel(
const grpc_channel_args& args) {
if (entry_->parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return entry_->parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* XdsLb::LocalityMap::LocalityEntry::Helper::CreateChannel(
const char* target, const grpc_channel_args& args) {
if (entry_->parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return entry_->parent_->channel_control_helper()->CreateChannel(target, args);
}
void XdsLb::LocalityMap::LocalityEntry::Helper::UpdateState(
grpc_connectivity_state state, grpc_error* state_error,
UniquePtr<SubchannelPicker> picker) {
if (entry_->parent_->shutting_down_) {
GRPC_ERROR_UNREF(state_error);
return;
}
// If this request is from the pending child policy, ignore it until
// it reports READY, at which point we swap it into place.
if (CalledByPendingChild()) {
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p helper %p] pending child policy %p reports state=%s",
entry_->parent_.get(), this, entry_->pending_child_policy_.get(),
grpc_connectivity_state_name(state));
}
if (state != GRPC_CHANNEL_READY) {
GRPC_ERROR_UNREF(state_error);
return;
}
grpc_pollset_set_del_pollset_set(
entry_->child_policy_->interested_parties(),
entry_->parent_->interested_parties());
MutexLock lock(&entry_->child_policy_mu_);
entry_->child_policy_ = std::move(entry_->pending_child_policy_);
} else if (!CalledByCurrentChild()) {
// This request is from an outdated child, so ignore it.
GRPC_ERROR_UNREF(state_error);
return;
}
// TODO(juanlishen): When in fallback mode, pass the child picker
// through without wrapping it. (Or maybe use a different helper for
// the fallback policy?)
GPR_ASSERT(entry_->parent_->lb_chand_ != nullptr);
RefCountedPtr<XdsLbClientStats> client_stats =
entry_->parent_->lb_chand_->lb_calld() == nullptr
? nullptr
: entry_->parent_->lb_chand_->lb_calld()->client_stats();
entry_->parent_->channel_control_helper()->UpdateState(
state, state_error,
UniquePtr<SubchannelPicker>(
New<Picker>(std::move(picker), std::move(client_stats))));
}
void XdsLb::LocalityMap::LocalityEntry::Helper::RequestReresolution() {
if (entry_->parent_->shutting_down_) return;
// If there is a pending child policy, ignore re-resolution requests
// from the current child policy (or any outdated child).
if (entry_->pending_child_policy_ != nullptr && !CalledByPendingChild()) {
return;
}
if (grpc_lb_xds_trace.enabled()) {
gpr_log(GPR_INFO,
"[xdslb %p] Re-resolution requested from the internal RR policy "
"(%p).",
entry_->parent_.get(), entry_->child_policy_.get());
}
GPR_ASSERT(entry_->parent_->lb_chand_ != nullptr);
// If we are talking to a balancer, we expect to get updated addresses
// from the balancer, so we can ignore the re-resolution request from
// the child policy. Otherwise, pass the re-resolution request up to the
// channel.
if (entry_->parent_->lb_chand_->lb_calld() == nullptr ||
!entry_->parent_->lb_chand_->lb_calld()->seen_initial_response()) {
entry_->parent_->channel_control_helper()->RequestReresolution();
}
}
//
// factory
//

@ -645,17 +645,22 @@ void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) {
}
#endif
grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
grpc_stream_refcount* refcount,
const void* server_data,
gpr_arena* arena)
: t(t), refcount(refcount), metadata_buffer{{arena}, {arena}} {
grpc_chttp2_stream::Reffer::Reffer(grpc_chttp2_stream* s) {
/* We reserve one 'active stream' that's dropped when the stream is
read-closed. The others are for Chttp2IncomingByteStreams that are
actively reading */
GRPC_CHTTP2_STREAM_REF(this, "chttp2");
GRPC_CHTTP2_REF_TRANSPORT(t, "stream");
GRPC_CHTTP2_STREAM_REF(s, "chttp2");
GRPC_CHTTP2_REF_TRANSPORT(s->t, "stream");
}
grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t,
grpc_stream_refcount* refcount,
const void* server_data,
gpr_arena* arena)
: t(t),
refcount(refcount),
reffer(this),
metadata_buffer{{arena}, {arena}} {
if (server_data) {
id = static_cast<uint32_t>((uintptr_t)server_data);
*t->accepting_stream = this;
@ -2598,6 +2603,9 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) {
gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string,
grpc_error_string(error));
}
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
return;
}
/* Reset the keepalive ping timer */
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
grpc_timer_cancel(&t->keepalive_ping_timer);
@ -2611,7 +2619,7 @@ static void finish_bdp_ping_locked(void* tp, grpc_error* error) {
gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string,
grpc_error_string(error));
}
if (error != GRPC_ERROR_NONE) {
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping");
return;
}

@ -510,6 +510,12 @@ struct grpc_chttp2_stream {
void* context;
grpc_chttp2_transport* t;
grpc_stream_refcount* refcount;
// Reffer is a 0-len structure, simply reffing `t` and `refcount` in its ctor
// before initializing the rest of the stream, to avoid cache misses. This
// field MUST be right after `t` and `refcount`.
struct Reffer {
explicit Reffer(grpc_chttp2_stream* s);
} reffer;
grpc_closure destroy_stream;
grpc_closure* destroy_stream_arg;

@ -108,6 +108,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
now.clock_type = clock;
switch (clock) {
case GPR_CLOCK_REALTIME:
// gettimeofday(...) function may return with a value whose tv_usec is
// greater than 1e6 on iOS The case is resolved with the guard at end of
// this function.
gettimeofday(&now_tv, nullptr);
now.tv_sec = now_tv.tv_sec;
now.tv_nsec = now_tv.tv_usec * 1000;
@ -124,6 +127,16 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
abort();
}
// Guard the tv_nsec field in valid range for all clock types
while (GPR_UNLIKELY(now.tv_nsec >= 1e9)) {
now.tv_sec++;
now.tv_nsec -= 1e9;
}
while (GPR_UNLIKELY(now.tv_nsec < 0)) {
now.tv_sec--;
now.tv_nsec += 1e9;
}
return now;
}
#endif

@ -160,8 +160,6 @@ void Fork::GlobalInit() {
if (!override_enabled_) {
#ifdef GRPC_ENABLE_FORK_SUPPORT
support_enabled_ = true;
#else
support_enabled_ = false;
#endif
bool env_var_set = false;
char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");

@ -0,0 +1,419 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_MAP_H
#define GRPC_CORE_LIB_GPRPP_MAP_H
#include <grpc/support/port_platform.h>
#include <string.h>
#include <functional>
#include <iterator>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/pair.h"
namespace grpc_core {
struct StringLess {
bool operator()(const char* a, const char* b) const {
return strcmp(a, b) < 0;
}
bool operator()(const UniquePtr<char>& k1, const UniquePtr<char>& k2) {
return strcmp(k1.get(), k2.get()) < 0;
}
};
namespace testing {
class MapTest;
}
// Alternative map implementation for grpc_core
template <class Key, class T, class Compare = std::less<Key>>
class Map {
public:
typedef Key key_type;
typedef T mapped_type;
typedef Pair<key_type, mapped_type> value_type;
typedef Compare key_compare;
class iterator;
~Map() { clear(); }
T& operator[](key_type&& key);
T& operator[](const key_type& key);
iterator find(const key_type& k);
size_t erase(const key_type& key);
// Removes the current entry and points to the next one
iterator erase(iterator iter);
size_t size() { return size_; }
template <class... Args>
Pair<iterator, bool> emplace(Args&&... args);
Pair<iterator, bool> insert(value_type&& pair) {
return emplace(std::move(pair));
}
Pair<iterator, bool> insert(const value_type& pair) { return emplace(pair); }
bool empty() const { return root_ == nullptr; }
void clear() {
auto iter = begin();
while (!empty()) {
iter = erase(iter);
}
}
iterator begin() {
Entry* curr = GetMinEntry(root_);
return iterator(this, curr);
}
iterator end() { return iterator(this, nullptr); }
private:
friend class testing::MapTest;
struct Entry {
explicit Entry(value_type&& pair) : pair(std::move(pair)) {}
value_type pair;
Entry* left = nullptr;
Entry* right = nullptr;
int32_t height = 1;
};
static int32_t EntryHeight(const Entry* e) {
return e == nullptr ? 0 : e->height;
}
static Entry* GetMinEntry(Entry* e);
Entry* InOrderSuccessor(const Entry* e) const;
static Entry* RotateLeft(Entry* e);
static Entry* RotateRight(Entry* e);
static Entry* RebalanceTreeAfterInsertion(Entry* root, const key_type& k);
static Entry* RebalanceTreeAfterDeletion(Entry* root);
// Returns a pair with the first value being an iterator pointing to the
// inserted entry and the second value being the new root of the subtree
// after a rebalance
Pair<iterator, Entry*> InsertRecursive(Entry* root, value_type&& p);
static Entry* RemoveRecursive(Entry* root, const key_type& k);
// Return 0 if lhs = rhs
// 1 if lhs > rhs
// -1 if lhs < rhs
static int CompareKeys(const Key& lhs, const Key& rhs);
Entry* root_ = nullptr;
size_t size_ = 0;
};
template <class Key, class T, class Compare>
class Map<Key, T, Compare>::iterator
: public std::iterator<std::input_iterator_tag, Pair<Key, T>, int32_t,
Pair<Key, T>*, Pair<Key, T>&> {
public:
iterator(const iterator& iter) : curr_(iter.curr_), map_(iter.map_) {}
bool operator==(const iterator& rhs) const { return (curr_ == rhs.curr_); }
bool operator!=(const iterator& rhs) const { return (curr_ != rhs.curr_); }
iterator& operator++() {
curr_ = map_->InOrderSuccessor(curr_);
return *this;
}
iterator operator++(int) {
Entry* prev = curr_;
curr_ = map_->InOrderSuccessor(curr_);
return iterator(map_, prev);
}
iterator& operator=(const iterator& other) {
if (this != &other) {
this->curr_ = other.curr_;
this->map_ = other.map_;
}
return *this;
}
// operator*()
value_type& operator*() { return curr_->pair; }
const value_type& operator*() const { return curr_->pair; }
// operator->()
value_type* operator->() { return &curr_->pair; }
value_type const* operator->() const { return &curr_->pair; }
private:
friend class Map<key_type, mapped_type, key_compare>;
using GrpcMap = typename ::grpc_core::Map<Key, T, Compare>;
iterator(GrpcMap* map, Entry* curr) : curr_(curr), map_(map) {}
Entry* curr_;
GrpcMap* map_;
};
template <class Key, class T, class Compare>
T& Map<Key, T, Compare>::operator[](key_type&& key) {
auto iter = find(key);
if (iter == end()) {
return emplace(std::move(key), T()).first->second;
}
return iter->second;
}
template <class Key, class T, class Compare>
T& Map<Key, T, Compare>::operator[](const key_type& key) {
auto iter = find(key);
if (iter == end()) {
return emplace(key, T()).first->second;
}
return iter->second;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::iterator Map<Key, T, Compare>::find(
const key_type& k) {
Entry* iter = root_;
while (iter != nullptr) {
int comp = CompareKeys(iter->pair.first, k);
if (comp == 0) {
return iterator(this, iter);
} else if (comp < 0) {
iter = iter->right;
} else {
iter = iter->left;
}
}
return end();
}
template <class Key, class T, class Compare>
template <class... Args>
typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator, bool>
Map<Key, T, Compare>::emplace(Args&&... args) {
Pair<key_type, mapped_type> pair(std::forward<Args>(args)...);
iterator ret = find(pair.first);
bool insertion = false;
if (ret == end()) {
Pair<iterator, Entry*> p = InsertRecursive(root_, std::move(pair));
root_ = p.second;
ret = p.first;
insertion = true;
size_++;
}
return MakePair(ret, insertion);
}
template <class Key, class T, class Compare>
size_t Map<Key, T, Compare>::erase(const key_type& key) {
iterator it = find(key);
if (it == end()) return 0;
erase(it);
return 1;
}
// TODO(mhaidry): Modify erase to use the iterator location
// to create an efficient erase method
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::iterator Map<Key, T, Compare>::erase(
iterator iter) {
if (iter == end()) return iter;
key_type& del_key = iter->first;
iter++;
root_ = RemoveRecursive(root_, del_key);
size_--;
return iter;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::InOrderSuccessor(
const Entry* e) const {
if (e->right != nullptr) {
return GetMinEntry(e->right);
}
Entry* successor = nullptr;
Entry* iter = root_;
while (iter != nullptr) {
int comp = CompareKeys(iter->pair.first, e->pair.first);
if (comp > 0) {
successor = iter;
iter = iter->left;
} else if (comp < 0) {
iter = iter->right;
} else
break;
}
return successor;
}
// Returns a pair with the first value being an iterator pointing to the
// inserted entry and the second value being the new root of the subtree
// after a rebalance
template <class Key, class T, class Compare>
typename ::grpc_core::Pair<typename Map<Key, T, Compare>::iterator,
typename Map<Key, T, Compare>::Entry*>
Map<Key, T, Compare>::InsertRecursive(Entry* root, value_type&& p) {
if (root == nullptr) {
Entry* e = New<Entry>(std::move(p));
return MakePair(iterator(this, e), e);
}
int comp = CompareKeys(root->pair.first, p.first);
if (comp > 0) {
Pair<iterator, Entry*> ret = InsertRecursive(root->left, std::move(p));
root->left = ret.second;
ret.second = RebalanceTreeAfterInsertion(root, ret.first->first);
return ret;
} else if (comp < 0) {
Pair<iterator, Entry*> ret = InsertRecursive(root->right, std::move(p));
root->right = ret.second;
ret.second = RebalanceTreeAfterInsertion(root, ret.first->first);
return ret;
} else {
root->pair = std::move(p);
return MakePair(iterator(this, root), root);
}
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::GetMinEntry(
Entry* e) {
if (e != nullptr) {
while (e->left != nullptr) {
e = e->left;
}
}
return e;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RotateLeft(
Entry* e) {
Entry* rightChild = e->right;
Entry* rightLeftChild = rightChild->left;
rightChild->left = e;
e->right = rightLeftChild;
e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right));
rightChild->height = 1 + GPR_MAX(EntryHeight(rightChild->left),
EntryHeight(rightChild->right));
return rightChild;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RotateRight(
Entry* e) {
Entry* leftChild = e->left;
Entry* leftRightChild = leftChild->right;
leftChild->right = e;
e->left = leftRightChild;
e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right));
leftChild->height =
1 + GPR_MAX(EntryHeight(leftChild->left), EntryHeight(leftChild->right));
return leftChild;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry*
Map<Key, T, Compare>::RebalanceTreeAfterInsertion(Entry* root,
const key_type& k) {
root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right));
int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right);
if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) > 0) {
return RotateRight(root);
}
if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) < 0) {
return RotateLeft(root);
}
if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) < 0) {
root->left = RotateLeft(root->left);
return RotateRight(root);
}
if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) > 0) {
root->right = RotateRight(root->right);
return RotateLeft(root);
}
return root;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry*
Map<Key, T, Compare>::RebalanceTreeAfterDeletion(Entry* root) {
root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right));
int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right);
if (heightDifference > 1) {
int leftHeightDifference =
EntryHeight(root->left->left) - EntryHeight(root->left->right);
if (leftHeightDifference < 0) {
root->left = RotateLeft(root->left);
}
return RotateRight(root);
}
if (heightDifference < -1) {
int rightHeightDifference =
EntryHeight(root->right->left) - EntryHeight(root->right->right);
if (rightHeightDifference > 0) {
root->right = RotateRight(root->right);
}
return RotateLeft(root);
}
return root;
}
template <class Key, class T, class Compare>
typename Map<Key, T, Compare>::Entry* Map<Key, T, Compare>::RemoveRecursive(
Entry* root, const key_type& k) {
if (root == nullptr) return root;
int comp = CompareKeys(root->pair.first, k);
if (comp > 0) {
root->left = RemoveRecursive(root->left, k);
} else if (comp < 0) {
root->right = RemoveRecursive(root->right, k);
} else {
Entry* ret;
if (root->left == nullptr) {
ret = root->right;
Delete(root);
return ret;
} else if (root->right == nullptr) {
ret = root->left;
Delete(root);
return ret;
} else {
ret = root->right;
while (ret->left != nullptr) {
ret = ret->left;
}
root->pair.swap(ret->pair);
root->right = RemoveRecursive(root->right, ret->pair.first);
}
}
return RebalanceTreeAfterDeletion(root);
}
template <class Key, class T, class Compare>
int Map<Key, T, Compare>::CompareKeys(const key_type& lhs,
const key_type& rhs) {
key_compare compare;
bool left_comparison = compare(lhs, rhs);
bool right_comparison = compare(rhs, lhs);
// Both values are equal
if (!left_comparison && !right_comparison) {
return 0;
}
return left_comparison ? -1 : 1;
}
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_MAP_H */

@ -0,0 +1,38 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_PAIR_H
#define GRPC_CORE_LIB_GPRPP_PAIR_H
#include <grpc/support/port_platform.h>
#include <utility>
namespace grpc_core {
template <class T1, class T2>
using Pair = std::pair<T1, T2>;
template <class T1, class T2>
inline Pair<typename std::decay<T1>::type, typename std::decay<T2>::type>
MakePair(T1&& u, T2&& v) {
typedef typename std::decay<T1>::type V1;
typedef typename std::decay<T2>::type V2;
return Pair<V1, V2>(std::forward<T1>(u), std::forward<T2>(v));
}
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_PAIR_H */

@ -192,4 +192,11 @@ void CFStreamHandle::Unref(const char* file, int line, const char* reason) {
}
}
#else
/* Creating a dummy function so that the grpc_cfstream library will be
* non-empty.
*/
void CFStreamDummy() {}
#endif

@ -172,7 +172,6 @@ static int is_metadata_server_reachable() {
detector.pollent = grpc_polling_entity_create_from_pollset(pollset);
detector.is_done = 0;
detector.success = 0;
memset(&detector.response, 0, sizeof(detector.response));
memset(&request, 0, sizeof(grpc_httpcli_request));
request.host = (char*)GRPC_COMPUTE_ENGINE_DETECTION_HOST;
request.http.path = (char*)"/";

@ -624,9 +624,8 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg,
gpr_log(GPR_ERROR, "EVP_DigestVerifyUpdate failed.");
goto end;
}
if (EVP_DigestVerifyFinal(
md_ctx, const_cast<uint8_t*>(GRPC_SLICE_START_PTR(signature)),
GRPC_SLICE_LENGTH(signature)) != 1) {
if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature),
GRPC_SLICE_LENGTH(signature)) != 1) {
gpr_log(GPR_ERROR, "JWT signature verification failed.");
goto end;
}

@ -44,24 +44,15 @@ namespace {
grpc_error* ssl_check_peer(
const char* peer_name, const tsi_peer* peer,
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context) {
#if TSI_OPENSSL_ALPN_SUPPORT
/* Check the ALPN if ALPN is supported. */
const tsi_peer_property* p =
tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
if (p == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Cannot check peer: missing selected ALPN property.");
}
if (!grpc_chttp2_is_alpn_version_supported(p->value.data, p->value.length)) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Cannot check peer: invalid ALPN value.");
grpc_error* error = grpc_ssl_check_alpn(peer);
if (error != GRPC_ERROR_NONE) {
return error;
}
#endif /* TSI_OPENSSL_ALPN_SUPPORT */
/* Check the peer name if specified. */
if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) {
char* msg;
gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name);
grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
gpr_free(msg);
return error;
}

@ -73,6 +73,7 @@ static void do_basic_init(void) {
g_shutting_down = false;
grpc_register_built_in_plugins();
grpc_cq_global_init();
gpr_time_init();
g_initializations = 0;
}
@ -132,7 +133,6 @@ void grpc_init(void) {
}
grpc_core::Fork::GlobalInit();
grpc_fork_handlers_auto_register();
gpr_time_init();
gpr_arena_init();
grpc_stats_init();
grpc_slice_intern_init();

@ -25,4 +25,4 @@
const char* grpc_version_string(void) { return "7.0.0"; }
const char* grpc_g_stands_for(void) { return "godric"; }
const char* grpc_g_stands_for(void) { return "gandalf"; }

@ -29,6 +29,7 @@
#include "src/core/lib/gpr/alloc.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/slice/slice_internal.h"
@ -243,25 +244,26 @@ void grpc_transport_stream_op_batch_finish_with_failure(
GRPC_ERROR_UNREF(error);
}
typedef struct {
struct made_transport_op {
grpc_closure outer_on_complete;
grpc_closure* inner_on_complete;
grpc_closure* inner_on_complete = nullptr;
grpc_transport_op op;
} made_transport_op;
made_transport_op() {
memset(&outer_on_complete, 0, sizeof(outer_on_complete));
}
};
static void destroy_made_transport_op(void* arg, grpc_error* error) {
made_transport_op* op = static_cast<made_transport_op*>(arg);
GRPC_CLOSURE_SCHED(op->inner_on_complete, GRPC_ERROR_REF(error));
gpr_free(op);
grpc_core::Delete<made_transport_op>(op);
}
grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete) {
made_transport_op* op =
static_cast<made_transport_op*>(gpr_malloc(sizeof(*op)));
made_transport_op* op = grpc_core::New<made_transport_op>();
GRPC_CLOSURE_INIT(&op->outer_on_complete, destroy_made_transport_op, op,
grpc_schedule_on_exec_ctx);
op->inner_on_complete = on_complete;
memset(&op->op, 0, sizeof(op->op));
op->op.on_consumed = &op->outer_on_complete;
return &op->op;
}

@ -273,40 +273,40 @@ struct grpc_transport_stream_op_batch_payload {
/** Transport op: a set of operations to perform on a transport as a whole */
typedef struct grpc_transport_op {
/** Called when processing of this op is done. */
grpc_closure* on_consumed;
grpc_closure* on_consumed = nullptr;
/** connectivity monitoring - set connectivity_state to NULL to unsubscribe */
grpc_closure* on_connectivity_state_change;
grpc_connectivity_state* connectivity_state;
grpc_closure* on_connectivity_state_change = nullptr;
grpc_connectivity_state* connectivity_state = nullptr;
/** should the transport be disconnected
* Error contract: the transport that gets this op must cause
* disconnect_with_error to be unref'ed after processing it */
grpc_error* disconnect_with_error;
grpc_error* disconnect_with_error = nullptr;
/** what should the goaway contain?
* Error contract: the transport that gets this op must cause
* goaway_error to be unref'ed after processing it */
grpc_error* goaway_error;
grpc_error* goaway_error = nullptr;
/** set the callback for accepting new streams;
this is a permanent callback, unlike the other one-shot closures.
If true, the callback is set to set_accept_stream_fn, with its
user_data argument set to set_accept_stream_user_data */
bool set_accept_stream;
bool set_accept_stream = false;
void (*set_accept_stream_fn)(void* user_data, grpc_transport* transport,
const void* server_data);
void* set_accept_stream_user_data;
const void* server_data) = nullptr;
void* set_accept_stream_user_data = nullptr;
/** add this transport to a pollset */
grpc_pollset* bind_pollset;
grpc_pollset* bind_pollset = nullptr;
/** add this transport to a pollset_set */
grpc_pollset_set* bind_pollset_set;
grpc_pollset_set* bind_pollset_set = nullptr;
/** send a ping, if either on_initiate or on_ack is not NULL */
struct {
/** Ping may be delayed by the transport, on_initiate callback will be
called when the ping is actually being sent. */
grpc_closure* on_initiate;
grpc_closure* on_initiate = nullptr;
/** Called when the ping ack is received */
grpc_closure* on_ack;
grpc_closure* on_ack = nullptr;
} send_ping;
// If true, will reset the channel's connection backoff.
bool reset_connect_backoff;
bool reset_connect_backoff = false;
/***************************************************************************
* remaining fields are initialized and used at the discretion of the

@ -18,8 +18,6 @@
#include <grpcpp/channel.h>
#include <chrono>
#include <condition_variable>
#include <cstring>
#include <memory>
#include <mutex>
@ -41,12 +39,7 @@
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/time.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/surface/completion_queue.h"
namespace grpc {

@ -19,7 +19,7 @@
#include <memory>
#include <grpcpp/channel.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/create_channel_impl.h>
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/support/channel_arguments.h>
@ -27,25 +27,30 @@
namespace grpc {
std::shared_ptr<Channel> CreateChannel(
class ChannelArguments;
}
namespace grpc_impl {
std::shared_ptr<grpc::Channel> CreateChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds) {
return CreateCustomChannel(target, creds, ChannelArguments());
const std::shared_ptr<grpc::ChannelCredentials>& creds) {
return CreateCustomChannel(target, creds, grpc::ChannelArguments());
}
std::shared_ptr<Channel> CreateCustomChannel(
std::shared_ptr<grpc::Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args) {
GrpcLibraryCodegen init_lib; // We need to call init in case of a bad creds.
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args) {
grpc::GrpcLibraryCodegen
init_lib; // We need to call init in case of a bad creds.
return creds ? creds->CreateChannel(target, args)
: CreateChannelInternal(
: grpc::CreateChannelInternal(
"",
grpc_lame_client_channel_create(
nullptr, GRPC_STATUS_INVALID_ARGUMENT,
"Invalid credentials."),
std::vector<std::unique_ptr<
experimental::ClientInterceptorFactoryInterface>>());
grpc::experimental::
ClientInterceptorFactoryInterface>>());
}
namespace experimental {
@ -60,23 +65,24 @@ namespace experimental {
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {
return creds ? creds->CreateChannelWithInterceptors(
target, args, std::move(interceptor_creators))
: CreateChannelInternal(
: grpc::CreateChannelInternal(
"",
grpc_lame_client_channel_create(
nullptr, GRPC_STATUS_INVALID_ARGUMENT,
"Invalid credentials."),
std::vector<std::unique_ptr<
experimental::ClientInterceptorFactoryInterface>>());
grpc::experimental::
ClientInterceptorFactoryInterface>>());
}
} // namespace experimental
} // namespace grpc
} // namespace grpc_impl

@ -24,45 +24,46 @@
#include "src/cpp/client/create_channel_internal.h"
namespace grpc {
namespace grpc_impl {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
int fd) {
internal::GrpcLibrary init_lib;
std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd(
const grpc::string& target, int fd) {
grpc::internal::GrpcLibrary init_lib;
init_lib.init();
return CreateChannelInternal(
return grpc::CreateChannelInternal(
"", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr),
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>());
}
std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const ChannelArguments& args) {
internal::GrpcLibrary init_lib;
std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args) {
grpc::internal::GrpcLibrary init_lib;
init_lib.init();
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return CreateChannelInternal(
return grpc::CreateChannelInternal(
"",
grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>());
}
namespace experimental {
std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const ChannelArguments& args,
std::shared_ptr<grpc::Channel>
CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {
internal::GrpcLibrary init_lib;
grpc::internal::GrpcLibrary init_lib;
init_lib.init();
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return CreateChannelInternal(
return grpc::CreateChannelInternal(
"",
grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
std::move(interceptor_creators));
@ -72,4 +73,4 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
} // namespace grpc
} // namespace grpc_impl

@ -22,63 +22,75 @@
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/client_callback.h>
namespace grpc {
namespace grpc_impl {
namespace {
std::unique_ptr<GenericClientAsyncReaderWriter> CallInternal(
ChannelInterface* channel, ClientContext* context,
const grpc::string& method, CompletionQueue* cq, bool start, void* tag) {
return std::unique_ptr<GenericClientAsyncReaderWriter>(
internal::ClientAsyncReaderWriterFactory<ByteBuffer, ByteBuffer>::Create(
channel, cq,
internal::RpcMethod(method.c_str(),
internal::RpcMethod::BIDI_STREAMING),
context, start, tag));
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> CallInternal(
grpc::ChannelInterface* channel, grpc::ClientContext* context,
const grpc::string& method, grpc::CompletionQueue* cq, bool start,
void* tag) {
return std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
grpc::internal::ClientAsyncReaderWriterFactory<grpc::ByteBuffer,
grpc::ByteBuffer>::
Create(channel, cq,
grpc::internal::RpcMethod(
method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING),
context, start, tag));
}
} // namespace
// begin a call to a named method
std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::Call(
ClientContext* context, const grpc::string& method, CompletionQueue* cq,
void* tag) {
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> GenericStub::Call(
grpc::ClientContext* context, const grpc::string& method,
grpc::CompletionQueue* cq, void* tag) {
return CallInternal(channel_.get(), context, method, cq, true, tag);
}
// setup a call to a named method
std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::PrepareCall(
ClientContext* context, const grpc::string& method, CompletionQueue* cq) {
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> GenericStub::PrepareCall(
grpc::ClientContext* context, const grpc::string& method,
grpc::CompletionQueue* cq) {
return CallInternal(channel_.get(), context, method, cq, false, nullptr);
}
// setup a unary call to a named method
std::unique_ptr<GenericClientAsyncResponseReader> GenericStub::PrepareUnaryCall(
ClientContext* context, const grpc::string& method,
const ByteBuffer& request, CompletionQueue* cq) {
return std::unique_ptr<GenericClientAsyncResponseReader>(
internal::ClientAsyncResponseReaderFactory<ByteBuffer>::Create(
channel_.get(), cq,
internal::RpcMethod(method.c_str(), internal::RpcMethod::NORMAL_RPC),
context, request, false));
std::unique_ptr<grpc::GenericClientAsyncResponseReader>
GenericStub::PrepareUnaryCall(grpc::ClientContext* context,
const grpc::string& method,
const grpc::ByteBuffer& request,
grpc::CompletionQueue* cq) {
return std::unique_ptr<grpc::GenericClientAsyncResponseReader>(
grpc::internal::ClientAsyncResponseReaderFactory<
grpc::ByteBuffer>::Create(channel_.get(), cq,
grpc::internal::RpcMethod(
method.c_str(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, false));
}
void GenericStub::experimental_type::UnaryCall(
ClientContext* context, const grpc::string& method,
const ByteBuffer* request, ByteBuffer* response,
std::function<void(Status)> on_completion) {
internal::CallbackUnaryCall(
grpc::ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request, grpc::ByteBuffer* response,
std::function<void(grpc::Status)> on_completion) {
grpc::internal::CallbackUnaryCall(
stub_->channel_.get(),
internal::RpcMethod(method.c_str(), internal::RpcMethod::NORMAL_RPC),
grpc::internal::RpcMethod(method.c_str(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, std::move(on_completion));
}
void GenericStub::experimental_type::PrepareBidiStreamingCall(
ClientContext* context, const grpc::string& method,
experimental::ClientBidiReactor<ByteBuffer, ByteBuffer>* reactor) {
internal::ClientCallbackReaderWriterFactory<ByteBuffer, ByteBuffer>::Create(
stub_->channel_.get(),
internal::RpcMethod(method.c_str(), internal::RpcMethod::BIDI_STREAMING),
context, reactor);
grpc::ClientContext* context, const grpc::string& method,
grpc::experimental::ClientBidiReactor<grpc::ByteBuffer, grpc::ByteBuffer>*
reactor) {
grpc::internal::ClientCallbackReaderWriterFactory<
grpc::ByteBuffer,
grpc::ByteBuffer>::Create(stub_->channel_.get(),
grpc::internal::RpcMethod(
method.c_str(),
grpc::internal::RpcMethod::BIDI_STREAMING),
context, reactor);
}
} // namespace grpc
} // namespace grpc_impl

@ -143,7 +143,7 @@ void ChannelArguments::SetUserAgentPrefix(
}
void ChannelArguments::SetResourceQuota(
const grpc::ResourceQuota& resource_quota) {
const grpc_impl::ResourceQuota& resource_quota) {
SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA,
resource_quota.c_resource_quota(),
grpc_resource_quota_arg_vtable());

@ -19,7 +19,7 @@
#include <grpc/grpc.h>
#include <grpcpp/resource_quota.h>
namespace grpc {
namespace grpc_impl {
ResourceQuota::ResourceQuota() : impl_(grpc_resource_quota_create(nullptr)) {}
@ -37,4 +37,4 @@ ResourceQuota& ResourceQuota::SetMaxThreads(int new_max_threads) {
grpc_resource_quota_set_max_threads(impl_, new_max_threads);
return *this;
}
} // namespace grpc
} // namespace grpc_impl

@ -22,5 +22,5 @@
#include <grpcpp/grpcpp.h>
namespace grpc {
grpc::string Version() { return "1.20.0-dev"; }
grpc::string Version() { return "1.21.0-dev"; }
} // namespace grpc

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save