grpc 1.30.2 → 1.31.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (317) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +560 -619
  3. data/include/grpc/grpc_security_constants.h +3 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +7 -5
  5. data/include/grpc/impl/codegen/port_platform.h +0 -32
  6. data/src/core/ext/filters/client_channel/backend_metric.cc +12 -9
  7. data/src/core/ext/filters/client_channel/client_channel.cc +406 -265
  8. data/src/core/ext/filters/client_channel/config_selector.cc +62 -0
  9. data/src/core/ext/filters/client_channel/config_selector.h +93 -0
  10. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -2
  11. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -0
  12. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +6 -5
  13. data/src/core/ext/filters/client_channel/http_proxy.cc +6 -4
  14. data/src/core/ext/filters/client_channel/lb_policy.h +2 -0
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +39 -23
  16. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +4 -6
  17. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +376 -68
  18. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -5
  19. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -2
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +6 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +8 -6
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +9 -7
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +7 -5
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +33 -48
  25. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -2
  26. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +21 -18
  27. data/src/core/ext/filters/client_channel/resolver_registry.cc +13 -14
  28. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +6 -7
  29. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +33 -28
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +39 -20
  31. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +142 -0
  32. data/src/core/ext/filters/client_channel/subchannel.cc +1 -1
  33. data/src/core/ext/filters/client_channel/xds/xds_api.cc +327 -123
  34. data/src/core/ext/filters/client_channel/xds/xds_api.h +72 -7
  35. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +12 -23
  36. data/src/core/ext/filters/client_channel/xds/xds_client.cc +112 -33
  37. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +10 -10
  38. data/src/core/ext/filters/http/client/http_client_filter.cc +5 -5
  39. data/src/core/ext/filters/http/http_filters_plugin.cc +2 -1
  40. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +74 -33
  41. data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +3 -1
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +56 -80
  43. data/src/core/ext/filters/message_size/message_size_filter.h +6 -0
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +383 -347
  45. data/src/core/ext/transport/chttp2/server/chttp2_server.h +6 -2
  46. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +1 -1
  47. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +7 -13
  48. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +7 -8
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +19 -4
  50. data/src/core/ext/transport/chttp2/transport/flow_control.cc +22 -27
  51. data/src/core/ext/transport/chttp2/transport/flow_control.h +14 -16
  52. data/src/core/ext/transport/chttp2/transport/frame_data.cc +9 -12
  53. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -6
  54. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
  55. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +12 -13
  56. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +9 -12
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +25 -29
  59. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +13 -17
  60. data/src/core/ext/transport/chttp2/transport/internal.h +13 -0
  61. data/src/core/ext/transport/chttp2/transport/parsing.cc +33 -43
  62. data/src/core/ext/transport/chttp2/transport/writing.cc +9 -14
  63. data/src/core/ext/transport/inproc/inproc_transport.cc +35 -15
  64. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +0 -1
  65. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +3 -4
  66. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -1
  67. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +80 -69
  68. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +24 -23
  69. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +66 -56
  70. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1 -2
  71. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +2 -2
  72. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +317 -311
  73. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +42 -34
  74. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +7 -7
  75. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +79 -61
  76. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +55 -49
  77. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +9 -8
  78. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +1 -1
  79. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +163 -169
  80. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +51 -45
  81. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +4 -5
  82. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +107 -100
  83. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +137 -117
  84. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +9 -9
  85. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +105 -87
  86. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +12 -13
  87. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +1 -1
  88. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +95 -101
  89. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +1 -2
  90. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +1 -1
  91. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +49 -65
  92. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -1
  93. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +49 -42
  94. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +70 -62
  95. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +1 -2
  96. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +81 -65
  97. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -1
  98. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +1 -1
  99. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +91 -80
  100. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +9 -10
  101. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +1 -2
  102. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +36 -31
  103. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -1
  104. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +7 -7
  105. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +648 -696
  106. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +16 -15
  107. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +1 -2
  108. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +1 -1
  109. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +95 -88
  110. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +234 -199
  111. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +5 -5
  112. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +13 -13
  113. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +1 -2
  114. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +20 -18
  115. data/src/core/ext/upb-generated/envoy/type/http.upb.h +0 -1
  116. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +18 -17
  117. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +14 -14
  118. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +23 -23
  119. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +8 -9
  120. data/src/core/ext/upb-generated/envoy/type/range.upb.h +15 -16
  121. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +7 -8
  122. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +36 -35
  123. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -1
  124. data/src/core/ext/upb-generated/google/api/annotations.upb.h +0 -1
  125. data/src/core/ext/upb-generated/google/api/http.upb.h +29 -28
  126. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +5 -6
  127. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +3 -3
  128. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +412 -386
  129. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +5 -6
  130. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +1 -2
  131. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +1 -1
  132. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +33 -54
  133. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +5 -6
  134. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -28
  135. data/src/core/ext/upb-generated/google/rpc/status.upb.h +8 -8
  136. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +1 -1
  137. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +32 -45
  138. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +4 -4
  139. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +157 -178
  140. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +14 -13
  141. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -7
  142. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +59 -56
  143. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +11 -12
  144. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +0 -1
  145. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +5 -6
  146. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +6 -6
  147. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +41 -68
  148. data/src/core/ext/upb-generated/validate/validate.upb.h +536 -535
  149. data/src/core/lib/channel/channel_trace.cc +2 -6
  150. data/src/core/lib/channel/channelz.cc +5 -15
  151. data/src/core/lib/gpr/log_linux.cc +6 -8
  152. data/src/core/lib/gpr/log_posix.cc +6 -8
  153. data/src/core/lib/gpr/string.cc +10 -9
  154. data/src/core/lib/gpr/string.h +4 -2
  155. data/src/core/lib/gprpp/global_config_env.cc +8 -6
  156. data/src/core/lib/http/httpcli.cc +13 -10
  157. data/src/core/lib/http/httpcli_security_connector.cc +5 -5
  158. data/src/core/lib/iomgr/cfstream_handle.cc +1 -0
  159. data/src/core/lib/iomgr/endpoint_pair_posix.cc +10 -10
  160. data/src/core/lib/iomgr/error_cfstream.cc +9 -8
  161. data/src/core/lib/iomgr/ev_epoll1_linux.cc +5 -6
  162. data/src/core/lib/iomgr/ev_epollex_linux.cc +15 -21
  163. data/src/core/lib/iomgr/ev_poll_posix.cc +6 -5
  164. data/src/core/lib/iomgr/ev_posix.cc +2 -0
  165. data/src/core/lib/iomgr/iomgr.cc +10 -0
  166. data/src/core/lib/iomgr/iomgr.h +10 -0
  167. data/src/core/lib/iomgr/is_epollexclusive_available.cc +14 -0
  168. data/src/core/lib/iomgr/port.h +1 -21
  169. data/src/core/lib/iomgr/resolve_address_custom.cc +13 -18
  170. data/src/core/lib/iomgr/resolve_address_windows.cc +8 -8
  171. data/src/core/lib/iomgr/resource_quota.cc +34 -31
  172. data/src/core/lib/iomgr/sockaddr_utils.cc +7 -5
  173. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  174. data/src/core/lib/iomgr/socket_utils_common_posix.cc +95 -55
  175. data/src/core/lib/iomgr/socket_windows.cc +4 -5
  176. data/src/core/lib/iomgr/tcp_client_cfstream.cc +9 -11
  177. data/src/core/lib/iomgr/tcp_client_custom.cc +6 -9
  178. data/src/core/lib/iomgr/tcp_client_posix.cc +27 -36
  179. data/src/core/lib/iomgr/tcp_client_windows.cc +9 -9
  180. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  181. data/src/core/lib/iomgr/tcp_custom.h +1 -1
  182. data/src/core/lib/iomgr/tcp_server.cc +3 -4
  183. data/src/core/lib/iomgr/tcp_server.h +7 -5
  184. data/src/core/lib/iomgr/tcp_server_custom.cc +6 -14
  185. data/src/core/lib/iomgr/tcp_server_posix.cc +34 -41
  186. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -4
  187. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -7
  188. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +4 -9
  189. data/src/core/lib/iomgr/tcp_server_windows.cc +16 -16
  190. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  191. data/src/core/lib/iomgr/udp_server.cc +24 -23
  192. data/src/core/lib/iomgr/udp_server.h +5 -2
  193. data/src/core/lib/iomgr/unix_sockets_posix.cc +9 -14
  194. data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
  195. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +5 -2
  196. data/src/core/lib/json/json_reader.cc +20 -21
  197. data/src/core/lib/security/credentials/credentials.h +5 -3
  198. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +8 -6
  199. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +12 -9
  200. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -4
  201. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +19 -28
  202. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -6
  203. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -0
  204. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -0
  205. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +10 -0
  206. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +10 -10
  207. data/src/core/lib/security/security_connector/security_connector.cc +2 -0
  208. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  209. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +18 -11
  210. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +5 -0
  211. data/src/core/lib/security/security_connector/ssl_utils.cc +44 -23
  212. data/src/core/lib/security/security_connector/ssl_utils.h +6 -2
  213. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +27 -24
  214. data/src/core/lib/security/transport/client_auth_filter.cc +10 -9
  215. data/src/core/lib/security/util/json_util.cc +12 -13
  216. data/src/core/lib/slice/slice.cc +38 -1
  217. data/src/core/lib/slice/slice_internal.h +1 -0
  218. data/src/core/lib/surface/call.cc +40 -41
  219. data/src/core/lib/surface/completion_queue.cc +271 -14
  220. data/src/core/lib/surface/completion_queue.h +8 -0
  221. data/src/core/lib/surface/init.cc +2 -0
  222. data/src/core/lib/surface/server.cc +565 -632
  223. data/src/core/lib/surface/server.h +34 -12
  224. data/src/core/lib/surface/version.cc +2 -2
  225. data/src/core/lib/transport/transport.h +6 -0
  226. data/src/core/lib/uri/uri_parser.cc +8 -15
  227. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  228. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +23 -13
  229. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -0
  230. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +2 -0
  231. data/src/core/tsi/ssl_transport_security.cc +102 -11
  232. data/src/core/tsi/ssl_transport_security.h +14 -2
  233. data/src/core/tsi/transport_security_interface.h +5 -0
  234. data/src/ruby/ext/grpc/extconf.rb +5 -2
  235. data/src/ruby/ext/grpc/rb_call.c +3 -2
  236. data/src/ruby/ext/grpc/rb_call.h +4 -0
  237. data/src/ruby/ext/grpc/rb_call_credentials.c +54 -10
  238. data/src/ruby/lib/grpc/generic/interceptors.rb +1 -1
  239. data/src/ruby/lib/grpc/version.rb +1 -1
  240. data/third_party/boringssl-with-bazel/err_data.c +89 -83
  241. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
  242. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +3 -3
  243. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +1 -1
  244. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -3
  245. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
  246. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
  247. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -1
  248. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn_pack.c +1 -1
  249. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_enum.c +1 -1
  250. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_int.c +1 -1
  251. data/third_party/boringssl-with-bazel/src/crypto/asn1/f_string.c +1 -1
  252. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +1 -0
  253. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +12 -52
  254. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +0 -22
  255. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +143 -0
  256. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.c +17 -1
  257. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +11 -1
  258. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +2 -1
  259. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +13 -11
  260. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +24 -23
  261. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +20 -16
  262. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +2 -2
  263. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/util.c +3 -3
  264. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +62 -0
  265. data/third_party/boringssl-with-bazel/src/crypto/mem.c +29 -15
  266. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +7 -0
  267. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +36 -5
  268. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +0 -29
  269. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +116 -363
  270. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +7 -45
  271. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +4 -4
  272. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +8 -0
  273. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +4 -4
  274. data/third_party/boringssl-with-bazel/src/crypto/x509/x509.c +0 -67
  275. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +13 -6
  276. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +10 -0
  277. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +41 -0
  278. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +4 -1
  279. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +28 -9
  280. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +25 -0
  281. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -13
  282. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +0 -154
  283. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +28 -6
  284. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +5 -0
  285. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +74 -35
  286. data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +16 -4
  287. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +22 -22
  288. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  289. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +69 -0
  290. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +33 -16
  291. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +1 -10
  292. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +789 -715
  293. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +3 -3
  294. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +9 -2
  295. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -2
  296. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +9 -0
  297. data/third_party/boringssl-with-bazel/src/ssl/internal.h +17 -14
  298. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +7 -7
  299. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +28 -0
  300. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +4 -24
  301. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +5 -5
  302. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +45 -24
  303. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +31 -21
  304. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +12 -9
  305. data/third_party/upb/upb/decode.c +467 -504
  306. data/third_party/upb/upb/encode.c +163 -121
  307. data/third_party/upb/upb/msg.c +130 -64
  308. data/third_party/upb/upb/msg.h +418 -14
  309. data/third_party/upb/upb/port_def.inc +35 -6
  310. data/third_party/upb/upb/port_undef.inc +8 -1
  311. data/third_party/upb/upb/table.c +53 -75
  312. data/third_party/upb/upb/table.int.h +11 -43
  313. data/third_party/upb/upb/upb.c +148 -124
  314. data/third_party/upb/upb/upb.h +65 -147
  315. data/third_party/upb/upb/upb.hpp +86 -0
  316. metadata +40 -37
  317. data/third_party/upb/upb/generated_util.h +0 -105
@@ -69,6 +69,14 @@ void grpc_cq_internal_unref(grpc_completion_queue* cc);
69
69
  /* Initializes global variables used by completion queues */
70
70
  void grpc_cq_global_init();
71
71
 
72
+ // Completion queue initializations that must be done after iomgr
73
+ // TODO(vjpai): Remove when callback_alternative is no longer needed.
74
+ void grpc_cq_init();
75
+
76
+ // Completion queue shutdowns that must be done before iomgr shutdown.
77
+ // TODO(vjpai): Remove when callback_alternative is no longer needed.
78
+ void grpc_cq_shutdown();
79
+
72
80
  /* Flag that an operation is beginning: the completion channel will not finish
73
81
  shutdown until a corrensponding grpc_cq_end_* call is made.
74
82
  \a tag is currently used only in debug builds. Return true on success, and
@@ -144,6 +144,7 @@ void grpc_init(void) {
144
144
  grpc_core::ApplicationCallbackExecCtx::GlobalInit();
145
145
  grpc_core::ExecCtx::GlobalInit();
146
146
  grpc_iomgr_init();
147
+ grpc_cq_init();
147
148
  gpr_timers_global_init();
148
149
  grpc_core::HandshakerRegistry::Init();
149
150
  grpc_security_init();
@@ -169,6 +170,7 @@ void grpc_shutdown_internal_locked(void) {
169
170
  int i;
170
171
  {
171
172
  grpc_core::ExecCtx exec_ctx(0);
173
+ grpc_cq_shutdown();
172
174
  grpc_iomgr_shutdown_background_closure();
173
175
  {
174
176
  grpc_timer_manager_set_threading(false); // shutdown timer_manager thread
@@ -24,11 +24,18 @@
24
24
  #include <stdlib.h>
25
25
  #include <string.h>
26
26
 
27
+ #include <algorithm>
28
+ #include <atomic>
29
+ #include <iterator>
30
+ #include <list>
31
+ #include <utility>
32
+ #include <vector>
33
+
27
34
  #include <grpc/support/alloc.h>
28
35
  #include <grpc/support/log.h>
29
36
  #include <grpc/support/string_util.h>
30
37
 
31
- #include <utility>
38
+ #include "absl/types/optional.h"
32
39
 
33
40
  #include "src/core/lib/channel/channel_args.h"
34
41
  #include "src/core/lib/channel/channelz.h"
@@ -48,26 +55,24 @@
48
55
  #include "src/core/lib/transport/metadata.h"
49
56
  #include "src/core/lib/transport/static_metadata.h"
50
57
 
51
- grpc_core::TraceFlag grpc_server_channel_trace(false, "server_channel");
58
+ namespace grpc_core {
52
59
 
53
- using grpc_core::LockedMultiProducerSingleConsumerQueue;
60
+ TraceFlag grpc_server_channel_trace(false, "server_channel");
54
61
 
55
62
  namespace {
56
63
 
57
64
  void server_on_recv_initial_metadata(void* ptr, grpc_error* error);
58
65
  void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error);
59
66
 
60
- struct listener {
61
- void* arg;
62
- void (*start)(grpc_server* server, void* arg, grpc_pollset** pollsets,
63
- size_t pollset_count);
64
- void (*destroy)(grpc_server* server, void* arg, grpc_closure* closure);
65
- struct listener* next;
66
- intptr_t socket_uuid;
67
+ struct Listener {
68
+ explicit Listener(OrphanablePtr<ServerListenerInterface> l)
69
+ : listener(std::move(l)) {}
70
+
71
+ OrphanablePtr<ServerListenerInterface> listener;
67
72
  grpc_closure destroy_done;
68
73
  };
69
74
 
70
- enum requested_call_type { BATCH_CALL, REGISTERED_CALL };
75
+ enum class RequestedCallType { BATCH_CALL, REGISTERED_CALL };
71
76
 
72
77
  struct registered_method;
73
78
 
@@ -75,7 +80,7 @@ struct requested_call {
75
80
  requested_call(void* tag_arg, grpc_completion_queue* call_cq,
76
81
  grpc_call** call_arg, grpc_metadata_array* initial_md,
77
82
  grpc_call_details* details)
78
- : type(BATCH_CALL),
83
+ : type(RequestedCallType::BATCH_CALL),
79
84
  tag(tag_arg),
80
85
  cq_bound_to_call(call_cq),
81
86
  call(call_arg),
@@ -88,7 +93,7 @@ struct requested_call {
88
93
  grpc_call** call_arg, grpc_metadata_array* initial_md,
89
94
  registered_method* rm, gpr_timespec* deadline,
90
95
  grpc_byte_buffer** optional_payload)
91
- : type(REGISTERED_CALL),
96
+ : type(RequestedCallType::REGISTERED_CALL),
92
97
  tag(tag_arg),
93
98
  cq_bound_to_call(call_cq),
94
99
  call(call_arg),
@@ -98,8 +103,8 @@ struct requested_call {
98
103
  data.registered.optional_payload = optional_payload;
99
104
  }
100
105
 
101
- grpc_core::MultiProducerSingleConsumerQueue::Node mpscq_node;
102
- const requested_call_type type;
106
+ MultiProducerSingleConsumerQueue::Node mpscq_node;
107
+ const RequestedCallType type;
103
108
  void* const tag;
104
109
  grpc_completion_queue* const cq_bound_to_call;
105
110
  grpc_call** const call;
@@ -118,34 +123,43 @@ struct requested_call {
118
123
  };
119
124
 
120
125
  struct channel_registered_method {
121
- registered_method* server_registered_method;
126
+ registered_method* server_registered_method = nullptr;
122
127
  uint32_t flags;
123
128
  bool has_host;
124
- grpc_core::ExternallyManagedSlice method;
125
- grpc_core::ExternallyManagedSlice host;
129
+ ExternallyManagedSlice method;
130
+ ExternallyManagedSlice host;
126
131
  };
127
132
 
128
133
  struct channel_data {
129
- grpc_server* server;
134
+ channel_data() = default;
135
+ ~channel_data();
136
+
137
+ grpc_server* server = nullptr;
130
138
  grpc_channel* channel;
131
139
  size_t cq_idx;
132
- /* linked list of all channels on a server */
133
- channel_data* next;
134
- channel_data* prev;
135
- channel_registered_method* registered_methods;
136
- uint32_t registered_method_slots;
140
+ absl::optional<std::list<channel_data*>::iterator> list_position;
141
+
142
+ // registered_methods is a hash-table of the methods and hosts of the
143
+ // registered methods.
144
+ // TODO(vjpai): Convert this to an STL map type as opposed to a direct bucket
145
+ // implementation. (Consider performance impact, hash function to use, etc.)
146
+ std::unique_ptr<std::vector<channel_registered_method>> registered_methods;
137
147
  uint32_t registered_method_max_probes;
148
+
138
149
  grpc_closure finish_destroy_channel_closure;
139
150
  intptr_t channelz_socket_uuid;
140
151
  };
141
152
 
142
153
  struct shutdown_tag {
143
- void* tag;
144
- grpc_completion_queue* cq;
154
+ shutdown_tag(void* tag_arg, grpc_completion_queue* cq_arg)
155
+ : tag(tag_arg), cq(cq_arg) {}
156
+
157
+ void* const tag;
158
+ grpc_completion_queue* const cq;
145
159
  grpc_cq_completion completion;
146
160
  };
147
161
 
148
- enum call_state {
162
+ enum class CallState {
149
163
  /* waiting for metadata */
150
164
  NOT_STARTED,
151
165
  /* initial metadata read, not flow controlled in yet */
@@ -213,15 +227,16 @@ struct call_data {
213
227
  call_data(grpc_call_element* elem, const grpc_call_element_args& args)
214
228
  : call(grpc_call_from_top_element(elem)),
215
229
  call_combiner(args.call_combiner) {
216
- GRPC_CLOSURE_INIT(&server_on_recv_initial_metadata,
217
- ::server_on_recv_initial_metadata, elem,
230
+ GRPC_CLOSURE_INIT(&on_recv_initial_metadata,
231
+ server_on_recv_initial_metadata, elem,
218
232
  grpc_schedule_on_exec_ctx);
219
233
  GRPC_CLOSURE_INIT(&recv_trailing_metadata_ready,
220
- ::server_recv_trailing_metadata_ready, elem,
234
+ server_recv_trailing_metadata_ready, elem,
221
235
  grpc_schedule_on_exec_ctx);
222
236
  }
223
237
  ~call_data() {
224
- GPR_ASSERT(state != PENDING);
238
+ GPR_ASSERT(state.Load(grpc_core::MemoryOrder::RELAXED) !=
239
+ CallState::PENDING);
225
240
  GRPC_ERROR_UNREF(recv_initial_metadata_error);
226
241
  if (host_set) {
227
242
  grpc_slice_unref_internal(host);
@@ -235,7 +250,7 @@ struct call_data {
235
250
 
236
251
  grpc_call* call;
237
252
 
238
- gpr_atm state = NOT_STARTED;
253
+ Atomic<CallState> state{CallState::NOT_STARTED};
239
254
 
240
255
  bool path_set = false;
241
256
  bool host_set = false;
@@ -254,7 +269,7 @@ struct call_data {
254
269
  grpc_byte_buffer* payload = nullptr;
255
270
 
256
271
  grpc_closure got_initial_metadata;
257
- grpc_closure server_on_recv_initial_metadata;
272
+ grpc_closure on_recv_initial_metadata;
258
273
  grpc_closure kill_zombie_closure;
259
274
  grpc_closure* on_done_recv_initial_metadata;
260
275
  grpc_closure recv_trailing_metadata_ready;
@@ -265,8 +280,7 @@ struct call_data {
265
280
 
266
281
  grpc_closure publish;
267
282
 
268
- call_data* pending_next = nullptr;
269
- grpc_core::CallCombiner* call_combiner;
283
+ CallCombiner* call_combiner;
270
284
  };
271
285
 
272
286
  struct registered_method {
@@ -287,25 +301,51 @@ struct registered_method {
287
301
  const uint32_t flags;
288
302
  /* one request matcher per method */
289
303
  std::unique_ptr<RequestMatcherInterface> matcher;
290
- registered_method* next;
291
304
  };
292
305
 
293
- struct channel_broadcaster {
294
- grpc_channel** channels;
295
- size_t num_channels;
296
- };
297
306
  } // namespace
307
+ } // namespace grpc_core
298
308
 
299
309
  struct grpc_server {
300
- grpc_channel_args* channel_args;
310
+ explicit grpc_server(const grpc_channel_args* args)
311
+ : channel_args(grpc_channel_args_copy(args)) {
312
+ if (grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_CHANNELZ,
313
+ GRPC_ENABLE_CHANNELZ_DEFAULT)) {
314
+ size_t channel_tracer_max_memory = grpc_channel_args_find_integer(
315
+ args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE,
316
+ {GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
317
+ channelz_server =
318
+ grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
319
+ this, channel_tracer_max_memory);
320
+ channelz_server->AddTraceEvent(
321
+ grpc_core::channelz::ChannelTrace::Severity::Info,
322
+ grpc_slice_from_static_string("Server created"));
323
+ }
301
324
 
302
- grpc_resource_user* default_resource_user;
325
+ if (args != nullptr) {
326
+ grpc_resource_quota* resource_quota =
327
+ grpc_resource_quota_from_channel_args(args, false /* create */);
328
+ if (resource_quota != nullptr) {
329
+ default_resource_user =
330
+ grpc_resource_user_create(resource_quota, "default");
331
+ }
332
+ }
333
+ }
303
334
 
304
- grpc_completion_queue** cqs;
305
- grpc_pollset** pollsets;
306
- size_t cq_count;
307
- size_t pollset_count;
308
- bool started;
335
+ ~grpc_server() {
336
+ grpc_channel_args_destroy(channel_args);
337
+ for (size_t i = 0; i < cqs.size(); i++) {
338
+ GRPC_CQ_INTERNAL_UNREF(cqs[i], "server");
339
+ }
340
+ }
341
+
342
+ grpc_channel_args* const channel_args;
343
+
344
+ grpc_resource_user* default_resource_user = nullptr;
345
+
346
+ std::vector<grpc_completion_queue*> cqs;
347
+ std::vector<grpc_pollset*> pollsets;
348
+ bool started = false;
309
349
 
310
350
  /* The two following mutexes control access to server-state
311
351
  mu_global controls access to non-call-related state (e.g., channel state)
@@ -314,31 +354,28 @@ struct grpc_server {
314
354
  If they are ever required to be nested, you must lock mu_global
315
355
  before mu_call. This is currently used in shutdown processing
316
356
  (grpc_server_shutdown_and_notify and maybe_finish_shutdown) */
317
- gpr_mu mu_global; /* mutex for server and channel state */
318
- gpr_mu mu_call; /* mutex for call-specific state */
357
+ grpc_core::Mutex mu_global; // mutex for server and channel state
358
+ grpc_core::Mutex mu_call; // mutex for call-specific state
319
359
 
320
360
  /* startup synchronization: flag is protected by mu_global, signals whether
321
361
  we are doing the listener start routine or not */
322
- bool starting;
323
- gpr_cv starting_cv;
324
-
325
- // TODO(vjpai): Convert from a linked-list head pointer to a std::vector once
326
- // grpc_server has a real constructor/destructor
327
- registered_method* registered_methods;
328
- /** one request matcher for unregistered methods */
329
- // TODO(vjpai): Convert to a std::unique_ptr once grpc_server has a real
330
- // constructor and destructor.
331
- RequestMatcherInterface* unregistered_request_matcher;
332
-
333
- gpr_atm shutdown_flag;
334
- uint8_t shutdown_published;
335
- size_t num_shutdown_tags;
336
- shutdown_tag* shutdown_tags;
337
-
338
- channel_data root_channel_data;
339
-
340
- listener* listeners;
341
- int listeners_destroyed;
362
+ bool starting = false;
363
+ grpc_core::CondVar starting_cv;
364
+
365
+ std::vector<std::unique_ptr<grpc_core::registered_method>> registered_methods;
366
+
367
+ // one request matcher for unregistered methods
368
+ std::unique_ptr<grpc_core::RequestMatcherInterface>
369
+ unregistered_request_matcher;
370
+
371
+ std::atomic_bool shutdown_flag{false};
372
+ bool shutdown_published = false;
373
+ std::vector<grpc_core::shutdown_tag> shutdown_tags;
374
+
375
+ std::list<grpc_core::channel_data*> channels;
376
+
377
+ std::list<grpc_core::Listener> listeners;
378
+ size_t listeners_destroyed = 0;
342
379
  grpc_core::RefCount internal_refcount;
343
380
 
344
381
  /** when did we print the last shutdown progress message */
@@ -347,10 +384,43 @@ struct grpc_server {
347
384
  grpc_core::RefCountedPtr<grpc_core::channelz::ServerNode> channelz_server;
348
385
  };
349
386
 
350
- #define SERVER_FROM_CALL_ELEM(elem) \
351
- (((channel_data*)(elem)->channel_data)->server)
387
+ // Non-API functions of the server that are only for gRPC core internal use.
388
+ // TODO(markdroth): Make these class member functions
389
+ void grpc_server_add_listener(
390
+ grpc_server* server,
391
+ grpc_core::OrphanablePtr<grpc_core::ServerListenerInterface> listener) {
392
+ grpc_core::channelz::ListenSocketNode* listen_socket_node =
393
+ listener->channelz_listen_socket_node();
394
+ if (listen_socket_node != nullptr && server->channelz_server != nullptr) {
395
+ server->channelz_server->AddChildListenSocket(listen_socket_node->Ref());
396
+ }
397
+ server->listeners.emplace_back(std::move(listener));
398
+ }
399
+
400
+ const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) {
401
+ return server->channel_args;
402
+ }
403
+
404
+ grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server) {
405
+ return server->default_resource_user;
406
+ }
407
+
408
+ bool grpc_server_has_open_connections(grpc_server* server) {
409
+ grpc_core::MutexLock lock(&server->mu_global);
410
+ return !server->channels.empty();
411
+ }
412
+
413
+ grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
414
+ grpc_server* server) {
415
+ if (server == nullptr) {
416
+ return nullptr;
417
+ }
418
+ return server->channelz_server.get();
419
+ }
352
420
 
421
+ namespace grpc_core {
353
422
  namespace {
423
+
354
424
  void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
355
425
  requested_call* rc);
356
426
  void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
@@ -364,26 +434,47 @@ void kill_zombie(void* elem, grpc_error* /*error*/) {
364
434
  grpc_call_from_top_element(static_cast<grpc_call_element*>(elem)));
365
435
  }
366
436
 
367
- /*
368
- * channel broadcaster
369
- */
437
+ // Validate a requested RPC for a server CQ and bind it to that CQ
438
+ grpc_call_error ValidateServerRequest(
439
+ grpc_completion_queue* cq_for_notification, void* tag,
440
+ grpc_byte_buffer** optional_payload, registered_method* rm) {
441
+ if ((rm == nullptr && optional_payload != nullptr) ||
442
+ ((rm != nullptr) && ((optional_payload == nullptr) !=
443
+ (rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)))) {
444
+ return GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
445
+ }
446
+ if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
447
+ return GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
448
+ }
449
+ return GRPC_CALL_OK;
450
+ }
370
451
 
371
- /* assumes server locked */
372
- void channel_broadcaster_init(grpc_server* s, channel_broadcaster* cb) {
373
- channel_data* c;
374
- size_t count = 0;
375
- for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
376
- count++;
377
- }
378
- cb->num_channels = count;
379
- cb->channels = static_cast<grpc_channel**>(
380
- gpr_malloc(sizeof(*cb->channels) * cb->num_channels));
381
- count = 0;
382
- for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
383
- cb->channels[count++] = c->channel;
384
- GRPC_CHANNEL_INTERNAL_REF(c->channel, "broadcast");
452
+ // Validate that a requested RPC has a valid server CQ and is valid, and bind it
453
+ grpc_call_error ValidateServerRequestAndCq(
454
+ size_t* cq_idx, grpc_server* server,
455
+ grpc_completion_queue* cq_for_notification, void* tag,
456
+ grpc_byte_buffer** optional_payload, registered_method* rm) {
457
+ size_t idx;
458
+ for (idx = 0; idx < server->cqs.size(); idx++) {
459
+ if (server->cqs[idx] == cq_for_notification) {
460
+ break;
461
+ }
462
+ }
463
+ if (idx == server->cqs.size()) {
464
+ return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
385
465
  }
466
+ grpc_call_error error =
467
+ ValidateServerRequest(cq_for_notification, tag, optional_payload, rm);
468
+ if (error != GRPC_CALL_OK) {
469
+ return error;
470
+ }
471
+
472
+ *cq_idx = idx;
473
+ return GRPC_CALL_OK;
386
474
  }
475
+ /*
476
+ * channel broadcaster
477
+ */
387
478
 
388
479
  struct shutdown_cleanup_args {
389
480
  grpc_closure closure;
@@ -391,16 +482,14 @@ struct shutdown_cleanup_args {
391
482
  };
392
483
 
393
484
  void shutdown_cleanup(void* arg, grpc_error* /*error*/) {
394
- struct shutdown_cleanup_args* a =
395
- static_cast<struct shutdown_cleanup_args*>(arg);
485
+ shutdown_cleanup_args* a = static_cast<shutdown_cleanup_args*>(arg);
396
486
  grpc_slice_unref_internal(a->slice);
397
- gpr_free(a);
487
+ delete a;
398
488
  }
399
489
 
400
490
  void send_shutdown(grpc_channel* channel, bool send_goaway,
401
491
  grpc_error* send_disconnect) {
402
- struct shutdown_cleanup_args* sc =
403
- static_cast<struct shutdown_cleanup_args*>(gpr_malloc(sizeof(*sc)));
492
+ shutdown_cleanup_args* sc = new shutdown_cleanup_args;
404
493
  GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc,
405
494
  grpc_schedule_on_exec_ctx);
406
495
  grpc_transport_op* op = grpc_make_transport_op(&sc->closure);
@@ -419,18 +508,34 @@ void send_shutdown(grpc_channel* channel, bool send_goaway,
419
508
  elem->filter->start_transport_op(elem, op);
420
509
  }
421
510
 
422
- void channel_broadcaster_shutdown(channel_broadcaster* cb, bool send_goaway,
423
- grpc_error* force_disconnect) {
424
- size_t i;
511
+ class ChannelBroadcaster {
512
+ public:
513
+ // This can have an empty constructor and destructor since we want to control
514
+ // when the actual setup and shutdown broadcast take place
515
+
516
+ // This function copies over the channels from the locked server
517
+ void FillChannelsLocked(const grpc_server* s) {
518
+ GPR_DEBUG_ASSERT(channels_.empty());
519
+ channels_.reserve(s->channels.size());
520
+ for (const channel_data* chand : s->channels) {
521
+ channels_.push_back(chand->channel);
522
+ GRPC_CHANNEL_INTERNAL_REF(chand->channel, "broadcast");
523
+ }
524
+ }
425
525
 
426
- for (i = 0; i < cb->num_channels; i++) {
427
- send_shutdown(cb->channels[i], send_goaway,
428
- GRPC_ERROR_REF(force_disconnect));
429
- GRPC_CHANNEL_INTERNAL_UNREF(cb->channels[i], "broadcast");
526
+ // Broadcast a shutdown on each channel
527
+ void BroadcastShutdown(bool send_goaway, grpc_error* force_disconnect) {
528
+ for (grpc_channel* channel : channels_) {
529
+ send_shutdown(channel, send_goaway, GRPC_ERROR_REF(force_disconnect));
530
+ GRPC_CHANNEL_INTERNAL_UNREF(channel, "broadcast");
531
+ }
532
+ channels_.clear(); // just for safety against double broadcast
533
+ GRPC_ERROR_UNREF(force_disconnect);
430
534
  }
431
- gpr_free(cb->channels);
432
- GRPC_ERROR_UNREF(force_disconnect);
433
- }
535
+
536
+ private:
537
+ std::vector<grpc_channel*> channels_;
538
+ };
434
539
 
435
540
  /*
436
541
  * request_matcher
@@ -444,7 +549,7 @@ void channel_broadcaster_shutdown(channel_broadcaster* cb, bool send_goaway,
444
549
  class RealRequestMatcher : public RequestMatcherInterface {
445
550
  public:
446
551
  explicit RealRequestMatcher(grpc_server* server)
447
- : server_(server), requests_per_cq_(server->cq_count) {}
552
+ : server_(server), requests_per_cq_(server->cqs.size()) {}
448
553
 
449
554
  ~RealRequestMatcher() override {
450
555
  for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) {
@@ -453,17 +558,16 @@ class RealRequestMatcher : public RequestMatcherInterface {
453
558
  }
454
559
 
455
560
  void ZombifyPending() override {
456
- while (pending_head_ != nullptr) {
457
- call_data* calld = pending_head_;
458
- pending_head_ = calld->pending_next;
459
- gpr_atm_no_barrier_store(&calld->state, ZOMBIED);
561
+ for (call_data* calld : pending_) {
562
+ calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
460
563
  GRPC_CLOSURE_INIT(
461
564
  &calld->kill_zombie_closure, kill_zombie,
462
565
  grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
463
566
  grpc_schedule_on_exec_ctx);
464
- grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
465
- GRPC_ERROR_NONE);
567
+ ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
568
+ GRPC_ERROR_NONE);
466
569
  }
570
+ pending_.clear();
467
571
  }
468
572
 
469
573
  void KillRequests(grpc_error* error) override {
@@ -486,28 +590,46 @@ class RealRequestMatcher : public RequestMatcherInterface {
486
590
  if (requests_per_cq_[request_queue_index].Push(&call->mpscq_node)) {
487
591
  /* this was the first queued request: we need to lock and start
488
592
  matching calls */
489
- gpr_mu_lock(&server_->mu_call);
490
- call_data* calld;
491
- while ((calld = pending_head_) != nullptr) {
492
- requested_call* rc = reinterpret_cast<requested_call*>(
493
- requests_per_cq_[request_queue_index].Pop());
494
- if (rc == nullptr) break;
495
- pending_head_ = calld->pending_next;
496
- gpr_mu_unlock(&server_->mu_call);
497
- if (!gpr_atm_full_cas(&calld->state, PENDING, ACTIVATED)) {
593
+ struct PendingCall {
594
+ requested_call* rc = nullptr;
595
+ call_data* calld;
596
+ };
597
+ auto pop_next_pending = [this, request_queue_index] {
598
+ PendingCall pending;
599
+ {
600
+ MutexLock lock(&server_->mu_call);
601
+ if (!pending_.empty()) {
602
+ pending.rc = reinterpret_cast<requested_call*>(
603
+ requests_per_cq_[request_queue_index].Pop());
604
+ if (pending.rc != nullptr) {
605
+ pending.calld = pending_.front();
606
+ pending_.pop_front();
607
+ }
608
+ }
609
+ }
610
+ return pending;
611
+ };
612
+ while (true) {
613
+ PendingCall next_pending = pop_next_pending();
614
+ if (next_pending.rc == nullptr) break;
615
+ CallState expect_pending = CallState::PENDING;
616
+ if (!next_pending.calld->state.CompareExchangeStrong(
617
+ &expect_pending, CallState::ACTIVATED,
618
+ grpc_core::MemoryOrder::ACQ_REL,
619
+ grpc_core::MemoryOrder::RELAXED)) {
498
620
  // Zombied Call
499
621
  GRPC_CLOSURE_INIT(
500
- &calld->kill_zombie_closure, kill_zombie,
501
- grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
622
+ &next_pending.calld->kill_zombie_closure, kill_zombie,
623
+ grpc_call_stack_element(
624
+ grpc_call_get_call_stack(next_pending.calld->call), 0),
502
625
  grpc_schedule_on_exec_ctx);
503
- grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
504
- GRPC_ERROR_NONE);
626
+ ExecCtx::Run(DEBUG_LOCATION, &next_pending.calld->kill_zombie_closure,
627
+ GRPC_ERROR_NONE);
505
628
  } else {
506
- publish_call(server_, calld, request_queue_index, rc);
629
+ publish_call(server_, next_pending.calld, request_queue_index,
630
+ next_pending.rc);
507
631
  }
508
- gpr_mu_lock(&server_->mu_call);
509
632
  }
510
- gpr_mu_unlock(&server_->mu_call);
511
633
  }
512
634
  }
513
635
 
@@ -521,7 +643,8 @@ class RealRequestMatcher : public RequestMatcherInterface {
521
643
  continue;
522
644
  } else {
523
645
  GRPC_STATS_INC_SERVER_CQS_CHECKED(i);
524
- gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
646
+ calld->state.Store(CallState::ACTIVATED,
647
+ grpc_core::MemoryOrder::RELAXED);
525
648
  publish_call(server_, calld, cq_idx, rc);
526
649
  return; /* early out */
527
650
  }
@@ -529,43 +652,40 @@ class RealRequestMatcher : public RequestMatcherInterface {
529
652
 
530
653
  /* no cq to take the request found: queue it on the slow list */
531
654
  GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED();
532
- gpr_mu_lock(&server_->mu_call);
533
655
 
534
656
  // We need to ensure that all the queues are empty. We do this under
535
657
  // the server mu_call lock to ensure that if something is added to
536
658
  // an empty request queue, it will block until the call is actually
537
659
  // added to the pending list.
538
- for (size_t i = 0; i < requests_per_cq_.size(); i++) {
539
- size_t cq_idx = (start_request_queue_index + i) % requests_per_cq_.size();
540
- requested_call* rc =
541
- reinterpret_cast<requested_call*>(requests_per_cq_[cq_idx].Pop());
660
+ requested_call* rc = nullptr;
661
+ size_t cq_idx = 0;
662
+ size_t loop_count;
663
+ {
664
+ MutexLock lock(&server_->mu_call);
665
+ for (loop_count = 0; loop_count < requests_per_cq_.size(); loop_count++) {
666
+ cq_idx =
667
+ (start_request_queue_index + loop_count) % requests_per_cq_.size();
668
+ rc = reinterpret_cast<requested_call*>(requests_per_cq_[cq_idx].Pop());
669
+ if (rc != nullptr) {
670
+ break;
671
+ }
672
+ }
542
673
  if (rc == nullptr) {
543
- continue;
544
- } else {
545
- gpr_mu_unlock(&server_->mu_call);
546
- GRPC_STATS_INC_SERVER_CQS_CHECKED(i + requests_per_cq_.size());
547
- gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
548
- publish_call(server_, calld, cq_idx, rc);
549
- return; /* early out */
674
+ calld->state.Store(CallState::PENDING, grpc_core::MemoryOrder::RELAXED);
675
+ pending_.push_back(calld);
676
+ return;
550
677
  }
551
678
  }
552
-
553
- gpr_atm_no_barrier_store(&calld->state, PENDING);
554
- if (pending_head_ == nullptr) {
555
- pending_tail_ = pending_head_ = calld;
556
- } else {
557
- pending_tail_->pending_next = calld;
558
- pending_tail_ = calld;
559
- }
560
- gpr_mu_unlock(&server_->mu_call);
679
+ GRPC_STATS_INC_SERVER_CQS_CHECKED(loop_count + requests_per_cq_.size());
680
+ calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
681
+ publish_call(server_, calld, cq_idx, rc);
561
682
  }
562
683
 
563
684
  grpc_server* server() const override { return server_; }
564
685
 
565
686
  private:
566
687
  grpc_server* const server_;
567
- call_data* pending_head_ = nullptr;
568
- call_data* pending_tail_ = nullptr;
688
+ std::list<call_data*> pending_;
569
689
  std::vector<LockedMultiProducerSingleConsumerQueue> requests_per_cq_;
570
690
  };
571
691
 
@@ -579,12 +699,12 @@ class AllocatingRequestMatcherBase : public RequestMatcherInterface {
579
699
  AllocatingRequestMatcherBase(grpc_server* server, grpc_completion_queue* cq)
580
700
  : server_(server), cq_(cq) {
581
701
  size_t idx;
582
- for (idx = 0; idx < server->cq_count; idx++) {
702
+ for (idx = 0; idx < server->cqs.size(); idx++) {
583
703
  if (server->cqs[idx] == cq) {
584
704
  break;
585
705
  }
586
706
  }
587
- GPR_ASSERT(idx < server->cq_count);
707
+ GPR_ASSERT(idx < server->cqs.size());
588
708
  cq_idx_ = idx;
589
709
  }
590
710
 
@@ -619,23 +739,23 @@ class AllocatingRequestMatcherBatch : public AllocatingRequestMatcherBase {
619
739
  public:
620
740
  AllocatingRequestMatcherBatch(
621
741
  grpc_server* server, grpc_completion_queue* cq,
622
- std::function<grpc_core::ServerBatchCallAllocation()> allocator)
742
+ std::function<ServerBatchCallAllocation()> allocator)
623
743
  : AllocatingRequestMatcherBase(server, cq),
624
744
  allocator_(std::move(allocator)) {}
625
745
  void MatchOrQueue(size_t /*start_request_queue_index*/,
626
746
  call_data* calld) override {
627
- grpc_core::ServerBatchCallAllocation call_info = allocator_();
747
+ ServerBatchCallAllocation call_info = allocator_();
628
748
  GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
629
749
  nullptr, nullptr) == GRPC_CALL_OK);
630
750
  requested_call* rc = new requested_call(
631
751
  static_cast<void*>(call_info.tag), cq(), call_info.call,
632
752
  call_info.initial_metadata, call_info.details);
633
- gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
753
+ calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
634
754
  publish_call(server(), calld, cq_idx(), rc);
635
755
  }
636
756
 
637
757
  private:
638
- std::function<grpc_core::ServerBatchCallAllocation()> allocator_;
758
+ std::function<ServerBatchCallAllocation()> allocator_;
639
759
  };
640
760
 
641
761
  // An allocating request matcher for registered methods.
@@ -643,13 +763,13 @@ class AllocatingRequestMatcherRegistered : public AllocatingRequestMatcherBase {
643
763
  public:
644
764
  AllocatingRequestMatcherRegistered(
645
765
  grpc_server* server, grpc_completion_queue* cq, registered_method* rm,
646
- std::function<grpc_core::ServerRegisteredCallAllocation()> allocator)
766
+ std::function<ServerRegisteredCallAllocation()> allocator)
647
767
  : AllocatingRequestMatcherBase(server, cq),
648
768
  registered_method_(rm),
649
769
  allocator_(std::move(allocator)) {}
650
770
  void MatchOrQueue(size_t /*start_request_queue_index*/,
651
771
  call_data* calld) override {
652
- grpc_core::ServerRegisteredCallAllocation call_info = allocator_();
772
+ ServerRegisteredCallAllocation call_info = allocator_();
653
773
  GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
654
774
  call_info.optional_payload,
655
775
  registered_method_) == GRPC_CALL_OK);
@@ -657,13 +777,13 @@ class AllocatingRequestMatcherRegistered : public AllocatingRequestMatcherBase {
657
777
  static_cast<void*>(call_info.tag), cq(), call_info.call,
658
778
  call_info.initial_metadata, registered_method_, call_info.deadline,
659
779
  call_info.optional_payload);
660
- gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
780
+ calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
661
781
  publish_call(server(), calld, cq_idx(), rc);
662
782
  }
663
783
 
664
784
  private:
665
785
  registered_method* const registered_method_;
666
- std::function<grpc_core::ServerRegisteredCallAllocation()> allocator_;
786
+ std::function<ServerRegisteredCallAllocation()> allocator_;
667
787
  };
668
788
 
669
789
  /*
@@ -672,42 +792,12 @@ class AllocatingRequestMatcherRegistered : public AllocatingRequestMatcherBase {
672
792
 
673
793
  void server_ref(grpc_server* server) { server->internal_refcount.Ref(); }
674
794
 
675
- void server_delete(grpc_server* server) {
676
- registered_method* rm;
677
- size_t i;
678
- server->channelz_server.reset();
679
- grpc_channel_args_destroy(server->channel_args);
680
- gpr_mu_destroy(&server->mu_global);
681
- gpr_mu_destroy(&server->mu_call);
682
- gpr_cv_destroy(&server->starting_cv);
683
- while ((rm = server->registered_methods) != nullptr) {
684
- server->registered_methods = rm->next;
685
- delete rm;
686
- }
687
- delete server->unregistered_request_matcher;
688
- for (i = 0; i < server->cq_count; i++) {
689
- GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server");
690
- }
691
- gpr_free(server->cqs);
692
- gpr_free(server->pollsets);
693
- gpr_free(server->shutdown_tags);
694
- gpr_free(server);
695
- }
696
-
697
795
  void server_unref(grpc_server* server) {
698
796
  if (GPR_UNLIKELY(server->internal_refcount.Unref())) {
699
- server_delete(server);
797
+ delete server;
700
798
  }
701
799
  }
702
800
 
703
- int is_channel_orphaned(channel_data* chand) { return chand->next == chand; }
704
-
705
- void orphan_channel(channel_data* chand) {
706
- chand->next->prev = chand->prev;
707
- chand->prev->next = chand->next;
708
- chand->next = chand->prev = chand;
709
- }
710
-
711
801
  void finish_destroy_channel(void* cd, grpc_error* /*error*/) {
712
802
  channel_data* chand = static_cast<channel_data*>(cd);
713
803
  grpc_server* server = chand->server;
@@ -716,9 +806,10 @@ void finish_destroy_channel(void* cd, grpc_error* /*error*/) {
716
806
  }
717
807
 
718
808
  void destroy_channel(channel_data* chand) {
719
- if (is_channel_orphaned(chand)) return;
809
+ if (!chand->list_position.has_value()) return;
720
810
  GPR_ASSERT(chand->server != nullptr);
721
- orphan_channel(chand);
811
+ chand->server->channels.erase(*chand->list_position);
812
+ chand->list_position.reset();
722
813
  server_ref(chand->server);
723
814
  maybe_finish_shutdown(chand->server);
724
815
  GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure,
@@ -748,7 +839,7 @@ void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
748
839
  calld->cq_new = server->cqs[cq_idx];
749
840
  GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata);
750
841
  switch (rc->type) {
751
- case BATCH_CALL:
842
+ case RequestedCallType::BATCH_CALL:
752
843
  GPR_ASSERT(calld->host_set);
753
844
  GPR_ASSERT(calld->path_set);
754
845
  rc->data.batch.details->host = grpc_slice_ref_internal(calld->host);
@@ -757,7 +848,7 @@ void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
757
848
  grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
758
849
  rc->data.batch.details->flags = calld->recv_initial_metadata_flags;
759
850
  break;
760
- case REGISTERED_CALL:
851
+ case RequestedCallType::REGISTERED_CALL:
761
852
  *rc->data.registered.deadline =
762
853
  grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
763
854
  if (rc->data.registered.optional_payload) {
@@ -780,14 +871,15 @@ void publish_new_rpc(void* arg, grpc_error* error) {
780
871
  RequestMatcherInterface* rm = calld->matcher;
781
872
  grpc_server* server = rm->server();
782
873
 
783
- if (error != GRPC_ERROR_NONE || gpr_atm_acq_load(&server->shutdown_flag)) {
784
- gpr_atm_no_barrier_store(&calld->state, ZOMBIED);
874
+ if (error != GRPC_ERROR_NONE ||
875
+ server->shutdown_flag.load(std::memory_order_acquire)) {
876
+ calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
785
877
  GRPC_CLOSURE_INIT(
786
878
  &calld->kill_zombie_closure, kill_zombie,
787
879
  grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
788
880
  grpc_schedule_on_exec_ctx);
789
- grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
790
- GRPC_ERROR_REF(error));
881
+ ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
882
+ GRPC_ERROR_REF(error));
791
883
  return;
792
884
  }
793
885
 
@@ -799,12 +891,11 @@ void finish_start_new_rpc(
799
891
  grpc_server_register_method_payload_handling payload_handling) {
800
892
  call_data* calld = static_cast<call_data*>(elem->call_data);
801
893
 
802
- if (gpr_atm_acq_load(&server->shutdown_flag)) {
803
- gpr_atm_no_barrier_store(&calld->state, ZOMBIED);
894
+ if (server->shutdown_flag.load(std::memory_order_acquire)) {
895
+ calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
804
896
  GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
805
897
  grpc_schedule_on_exec_ctx);
806
- grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
807
- GRPC_ERROR_NONE);
898
+ ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure, GRPC_ERROR_NONE);
808
899
  return;
809
900
  }
810
901
 
@@ -842,8 +933,8 @@ void start_new_rpc(grpc_call_element* elem) {
842
933
  hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash_internal(calld->host),
843
934
  grpc_slice_hash_internal(calld->path));
844
935
  for (i = 0; i <= chand->registered_method_max_probes; i++) {
845
- rm = &chand->registered_methods[(hash + i) %
846
- chand->registered_method_slots];
936
+ rm = &(*chand->registered_methods)[(hash + i) %
937
+ chand->registered_methods->size()];
847
938
  if (rm->server_registered_method == nullptr) break;
848
939
  if (!rm->has_host) continue;
849
940
  if (rm->host != calld->host) continue;
@@ -861,8 +952,8 @@ void start_new_rpc(grpc_call_element* elem) {
861
952
  /* check for a wildcard method definition (no host set) */
862
953
  hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash_internal(calld->path));
863
954
  for (i = 0; i <= chand->registered_method_max_probes; i++) {
864
- rm = &chand->registered_methods[(hash + i) %
865
- chand->registered_method_slots];
955
+ rm = &(*chand->registered_methods)[(hash + i) %
956
+ chand->registered_methods->size()];
866
957
  if (rm->server_registered_method == nullptr) break;
867
958
  if (rm->has_host) continue;
868
959
  if (rm->method != calld->path) continue;
@@ -877,39 +968,21 @@ void start_new_rpc(grpc_call_element* elem) {
877
968
  return;
878
969
  }
879
970
  }
880
- finish_start_new_rpc(server, elem, server->unregistered_request_matcher,
971
+ finish_start_new_rpc(server, elem, server->unregistered_request_matcher.get(),
881
972
  GRPC_SRM_PAYLOAD_NONE);
882
973
  }
883
974
 
884
- int num_listeners(grpc_server* server) {
885
- listener* l;
886
- int n = 0;
887
- for (l = server->listeners; l; l = l->next) {
888
- n++;
889
- }
890
- return n;
891
- }
892
-
893
975
  void done_shutdown_event(void* server, grpc_cq_completion* /*completion*/) {
894
976
  server_unref(static_cast<grpc_server*>(server));
895
977
  }
896
978
 
897
- int num_channels(grpc_server* server) {
898
- channel_data* chand;
899
- int n = 0;
900
- for (chand = server->root_channel_data.next;
901
- chand != &server->root_channel_data; chand = chand->next) {
902
- n++;
903
- }
904
- return n;
905
- }
979
+ int num_channels(grpc_server* server) { return server->channels.size(); }
906
980
 
907
981
  void kill_pending_work_locked(grpc_server* server, grpc_error* error) {
908
982
  if (server->started) {
909
983
  server->unregistered_request_matcher->KillRequests(GRPC_ERROR_REF(error));
910
984
  server->unregistered_request_matcher->ZombifyPending();
911
- for (registered_method* rm = server->registered_methods; rm;
912
- rm = rm->next) {
985
+ for (std::unique_ptr<registered_method>& rm : server->registered_methods) {
913
986
  rm->matcher->KillRequests(GRPC_ERROR_REF(error));
914
987
  rm->matcher->ZombifyPending();
915
988
  }
@@ -919,32 +992,34 @@ void kill_pending_work_locked(grpc_server* server, grpc_error* error) {
919
992
 
920
993
  void maybe_finish_shutdown(grpc_server* server) {
921
994
  size_t i;
922
- if (!gpr_atm_acq_load(&server->shutdown_flag) || server->shutdown_published) {
995
+ if (!server->shutdown_flag.load(std::memory_order_acquire) ||
996
+ server->shutdown_published) {
923
997
  return;
924
998
  }
925
999
 
926
- gpr_mu_lock(&server->mu_call);
927
- kill_pending_work_locked(
928
- server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
929
- gpr_mu_unlock(&server->mu_call);
1000
+ {
1001
+ MutexLock lock(&server->mu_call);
1002
+ kill_pending_work_locked(
1003
+ server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1004
+ }
930
1005
 
931
- if (server->root_channel_data.next != &server->root_channel_data ||
932
- server->listeners_destroyed < num_listeners(server)) {
1006
+ if (!server->channels.empty() ||
1007
+ server->listeners_destroyed < server->listeners.size()) {
933
1008
  if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
934
1009
  server->last_shutdown_message_time),
935
1010
  gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
936
1011
  server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
937
1012
  gpr_log(GPR_DEBUG,
938
- "Waiting for %d channels and %d/%d listeners to be destroyed"
939
- " before shutting down server",
1013
+ "Waiting for %d channels and %" PRIuPTR "/%" PRIuPTR
1014
+ " listeners to be destroyed before shutting down server",
940
1015
  num_channels(server),
941
- num_listeners(server) - server->listeners_destroyed,
942
- num_listeners(server));
1016
+ server->listeners.size() - server->listeners_destroyed,
1017
+ server->listeners.size());
943
1018
  }
944
1019
  return;
945
1020
  }
946
1021
  server->shutdown_published = 1;
947
- for (i = 0; i < server->num_shutdown_tags; i++) {
1022
+ for (i = 0; i < server->shutdown_tags.size(); i++) {
948
1023
  server_ref(server);
949
1024
  grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag,
950
1025
  GRPC_ERROR_NONE, done_shutdown_event, server,
@@ -995,7 +1070,7 @@ void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
995
1070
  calld->recv_trailing_metadata_error,
996
1071
  "continue server_recv_trailing_metadata_ready");
997
1072
  }
998
- grpc_core::Closure::Run(DEBUG_LOCATION, closure, error);
1073
+ Closure::Run(DEBUG_LOCATION, closure, error);
999
1074
  }
1000
1075
 
1001
1076
  void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error) {
@@ -1015,8 +1090,8 @@ void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error) {
1015
1090
  error =
1016
1091
  grpc_error_add_child(GRPC_ERROR_REF(error),
1017
1092
  GRPC_ERROR_REF(calld->recv_initial_metadata_error));
1018
- grpc_core::Closure::Run(DEBUG_LOCATION,
1019
- calld->original_recv_trailing_metadata_ready, error);
1093
+ Closure::Run(DEBUG_LOCATION, calld->original_recv_trailing_metadata_ready,
1094
+ error);
1020
1095
  }
1021
1096
 
1022
1097
  void server_mutate_op(grpc_call_element* elem,
@@ -1030,7 +1105,7 @@ void server_mutate_op(grpc_call_element* elem,
1030
1105
  calld->on_done_recv_initial_metadata =
1031
1106
  op->payload->recv_initial_metadata.recv_initial_metadata_ready;
1032
1107
  op->payload->recv_initial_metadata.recv_initial_metadata_ready =
1033
- &calld->server_on_recv_initial_metadata;
1108
+ &calld->on_recv_initial_metadata;
1034
1109
  op->payload->recv_initial_metadata.recv_flags =
1035
1110
  &calld->recv_initial_metadata_flags;
1036
1111
  }
@@ -1054,12 +1129,19 @@ void got_initial_metadata(void* ptr, grpc_error* error) {
1054
1129
  if (error == GRPC_ERROR_NONE) {
1055
1130
  start_new_rpc(elem);
1056
1131
  } else {
1057
- if (gpr_atm_full_cas(&calld->state, NOT_STARTED, ZOMBIED)) {
1132
+ CallState expect_not_started = CallState::NOT_STARTED;
1133
+ CallState expect_pending = CallState::PENDING;
1134
+ if (calld->state.CompareExchangeStrong(
1135
+ &expect_not_started, CallState::ZOMBIED,
1136
+ grpc_core::MemoryOrder::ACQ_REL, grpc_core::MemoryOrder::RELAXED)) {
1058
1137
  GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
1059
1138
  grpc_schedule_on_exec_ctx);
1060
- grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
1061
- GRPC_ERROR_NONE);
1062
- } else if (gpr_atm_full_cas(&calld->state, PENDING, ZOMBIED)) {
1139
+ ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
1140
+ GRPC_ERROR_NONE);
1141
+ } else if (calld->state.CompareExchangeStrong(
1142
+ &expect_pending, CallState::ZOMBIED,
1143
+ grpc_core::MemoryOrder::ACQ_REL,
1144
+ grpc_core::MemoryOrder::RELAXED)) {
1063
1145
  /* zombied call will be destroyed when it's removed from the pending
1064
1146
  queue... later */
1065
1147
  }
@@ -1121,63 +1203,56 @@ void server_destroy_call_elem(grpc_call_element* elem,
1121
1203
 
1122
1204
  grpc_error* server_init_channel_elem(grpc_channel_element* elem,
1123
1205
  grpc_channel_element_args* args) {
1124
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1125
1206
  GPR_ASSERT(args->is_first);
1126
1207
  GPR_ASSERT(!args->is_last);
1127
- chand->server = nullptr;
1128
- chand->channel = nullptr;
1129
- chand->next = chand->prev = chand;
1130
- chand->registered_methods = nullptr;
1208
+
1209
+ new (static_cast<channel_data*>(elem->channel_data)) channel_data;
1131
1210
  return GRPC_ERROR_NONE;
1132
1211
  }
1133
1212
 
1134
- void server_destroy_channel_elem(grpc_channel_element* elem) {
1135
- size_t i;
1136
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1137
- if (chand->registered_methods) {
1138
- for (i = 0; i < chand->registered_method_slots; i++) {
1139
- grpc_slice_unref_internal(chand->registered_methods[i].method);
1140
- GPR_DEBUG_ASSERT(chand->registered_methods[i].method.refcount ==
1141
- &grpc_core::kNoopRefcount ||
1142
- chand->registered_methods[i].method.refcount == nullptr);
1143
- if (chand->registered_methods[i].has_host) {
1144
- grpc_slice_unref_internal(chand->registered_methods[i].host);
1145
- GPR_DEBUG_ASSERT(chand->registered_methods[i].host.refcount ==
1146
- &grpc_core::kNoopRefcount ||
1147
- chand->registered_methods[i].host.refcount == nullptr);
1213
+ channel_data::~channel_data() {
1214
+ if (registered_methods) {
1215
+ for (const channel_registered_method& crm : *registered_methods) {
1216
+ grpc_slice_unref_internal(crm.method);
1217
+ GPR_DEBUG_ASSERT(crm.method.refcount == &kNoopRefcount ||
1218
+ crm.method.refcount == nullptr);
1219
+ if (crm.has_host) {
1220
+ grpc_slice_unref_internal(crm.host);
1221
+ GPR_DEBUG_ASSERT(crm.host.refcount == &kNoopRefcount ||
1222
+ crm.host.refcount == nullptr);
1148
1223
  }
1149
1224
  }
1150
- gpr_free(chand->registered_methods);
1151
1225
  }
1152
- if (chand->server) {
1153
- if (chand->server->channelz_server != nullptr &&
1154
- chand->channelz_socket_uuid != 0) {
1155
- chand->server->channelz_server->RemoveChildSocket(
1156
- chand->channelz_socket_uuid);
1226
+ if (server) {
1227
+ if (server->channelz_server != nullptr && channelz_socket_uuid != 0) {
1228
+ server->channelz_server->RemoveChildSocket(channelz_socket_uuid);
1229
+ }
1230
+ {
1231
+ MutexLock lock(&server->mu_global);
1232
+ if (list_position.has_value()) {
1233
+ server->channels.erase(*list_position);
1234
+ }
1235
+ maybe_finish_shutdown(server);
1157
1236
  }
1158
- gpr_mu_lock(&chand->server->mu_global);
1159
- chand->next->prev = chand->prev;
1160
- chand->prev->next = chand->next;
1161
- chand->next = chand->prev = chand;
1162
- maybe_finish_shutdown(chand->server);
1163
- gpr_mu_unlock(&chand->server->mu_global);
1164
- server_unref(chand->server);
1237
+ server_unref(server);
1165
1238
  }
1166
1239
  }
1167
1240
 
1241
+ void server_destroy_channel_elem(grpc_channel_element* elem) {
1242
+ channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1243
+ chand->~channel_data();
1244
+ }
1245
+
1168
1246
  void register_completion_queue(grpc_server* server, grpc_completion_queue* cq,
1169
1247
  void* reserved) {
1170
- size_t i, n;
1248
+ size_t i;
1171
1249
  GPR_ASSERT(!reserved);
1172
- for (i = 0; i < server->cq_count; i++) {
1250
+ for (i = 0; i < server->cqs.size(); i++) {
1173
1251
  if (server->cqs[i] == cq) return;
1174
1252
  }
1175
1253
 
1176
1254
  GRPC_CQ_INTERNAL_REF(cq, "server");
1177
- n = server->cq_count++;
1178
- server->cqs = static_cast<grpc_completion_queue**>(gpr_realloc(
1179
- server->cqs, server->cq_count * sizeof(grpc_completion_queue*)));
1180
- server->cqs[n] = cq;
1255
+ server->cqs.push_back(cq);
1181
1256
  }
1182
1257
 
1183
1258
  bool streq(const std::string& a, const char* b) {
@@ -1185,8 +1260,7 @@ bool streq(const std::string& a, const char* b) {
1185
1260
  ((b != nullptr) && !strcmp(a.c_str(), b));
1186
1261
  }
1187
1262
 
1188
- class ConnectivityWatcher
1189
- : public grpc_core::AsyncConnectivityStateWatcherInterface {
1263
+ class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface {
1190
1264
  public:
1191
1265
  explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) {
1192
1266
  GRPC_CHANNEL_INTERNAL_REF(chand_->channel, "connectivity");
@@ -1202,40 +1276,37 @@ class ConnectivityWatcher
1202
1276
  if (new_state != GRPC_CHANNEL_SHUTDOWN) return;
1203
1277
  // Shut down channel.
1204
1278
  grpc_server* server = chand_->server;
1205
- gpr_mu_lock(&server->mu_global);
1279
+ MutexLock lock(&server->mu_global);
1206
1280
  destroy_channel(chand_);
1207
- gpr_mu_unlock(&server->mu_global);
1208
1281
  }
1209
1282
 
1210
1283
  channel_data* chand_;
1211
1284
  };
1212
1285
 
1213
- void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) {
1214
- (void)done_arg;
1215
- gpr_free(storage);
1286
+ void done_published_shutdown(void* /*done_arg*/, grpc_cq_completion* storage) {
1287
+ delete storage;
1216
1288
  }
1217
1289
 
1218
1290
  void listener_destroy_done(void* s, grpc_error* /*error*/) {
1219
1291
  grpc_server* server = static_cast<grpc_server*>(s);
1220
- gpr_mu_lock(&server->mu_global);
1292
+ MutexLock lock(&server->mu_global);
1221
1293
  server->listeners_destroyed++;
1222
1294
  maybe_finish_shutdown(server);
1223
- gpr_mu_unlock(&server->mu_global);
1224
1295
  }
1225
1296
 
1226
1297
  grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx,
1227
1298
  requested_call* rc) {
1228
- if (gpr_atm_acq_load(&server->shutdown_flag)) {
1299
+ if (server->shutdown_flag.load(std::memory_order_acquire)) {
1229
1300
  fail_call(server, cq_idx, rc,
1230
1301
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1231
1302
  return GRPC_CALL_OK;
1232
1303
  }
1233
1304
  RequestMatcherInterface* rm;
1234
1305
  switch (rc->type) {
1235
- case BATCH_CALL:
1236
- rm = server->unregistered_request_matcher;
1306
+ case RequestedCallType::BATCH_CALL:
1307
+ rm = server->unregistered_request_matcher.get();
1237
1308
  break;
1238
- case REGISTERED_CALL:
1309
+ case RequestedCallType::REGISTERED_CALL:
1239
1310
  rm = rc->data.registered.method->matcher.get();
1240
1311
  break;
1241
1312
  }
@@ -1252,16 +1323,15 @@ void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
1252
1323
  grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc,
1253
1324
  &rc->completion);
1254
1325
  }
1255
- } // namespace
1256
1326
 
1257
- namespace grpc_core {
1327
+ } // namespace
1258
1328
 
1259
1329
  void SetServerRegisteredMethodAllocator(
1260
1330
  grpc_server* server, grpc_completion_queue* cq, void* method_tag,
1261
1331
  std::function<ServerRegisteredCallAllocation()> allocator) {
1262
1332
  registered_method* rm = static_cast<registered_method*>(method_tag);
1263
- rm->matcher.reset(new AllocatingRequestMatcherRegistered(
1264
- server, cq, rm, std::move(allocator)));
1333
+ rm->matcher = absl::make_unique<AllocatingRequestMatcherRegistered>(
1334
+ server, cq, rm, std::move(allocator));
1265
1335
  }
1266
1336
 
1267
1337
  void SetServerBatchMethodAllocator(
@@ -1269,25 +1339,28 @@ void SetServerBatchMethodAllocator(
1269
1339
  std::function<ServerBatchCallAllocation()> allocator) {
1270
1340
  GPR_DEBUG_ASSERT(server->unregistered_request_matcher == nullptr);
1271
1341
  server->unregistered_request_matcher =
1272
- new AllocatingRequestMatcherBatch(server, cq, std::move(allocator));
1342
+ absl::make_unique<AllocatingRequestMatcherBatch>(server, cq,
1343
+ std::move(allocator));
1273
1344
  }
1274
1345
 
1275
- }; // namespace grpc_core
1346
+ } // namespace grpc_core
1276
1347
 
1277
1348
  const grpc_channel_filter grpc_server_top_filter = {
1278
- server_start_transport_stream_op_batch,
1349
+ grpc_core::server_start_transport_stream_op_batch,
1279
1350
  grpc_channel_next_op,
1280
- sizeof(call_data),
1281
- server_init_call_elem,
1351
+ sizeof(grpc_core::call_data),
1352
+ grpc_core::server_init_call_elem,
1282
1353
  grpc_call_stack_ignore_set_pollset_or_pollset_set,
1283
- server_destroy_call_elem,
1284
- sizeof(channel_data),
1285
- server_init_channel_elem,
1286
- server_destroy_channel_elem,
1354
+ grpc_core::server_destroy_call_elem,
1355
+ sizeof(grpc_core::channel_data),
1356
+ grpc_core::server_init_channel_elem,
1357
+ grpc_core::server_destroy_channel_elem,
1287
1358
  grpc_channel_next_get_info,
1288
1359
  "server",
1289
1360
  };
1290
1361
 
1362
+ // The following are core surface API functions.
1363
+
1291
1364
  void grpc_server_register_completion_queue(grpc_server* server,
1292
1365
  grpc_completion_queue* cq,
1293
1366
  void* reserved) {
@@ -1305,59 +1378,20 @@ void grpc_server_register_completion_queue(grpc_server* server,
1305
1378
  calls grpc_completion_queue_pluck() on server completion queues */
1306
1379
  }
1307
1380
 
1308
- register_completion_queue(server, cq, reserved);
1381
+ grpc_core::register_completion_queue(server, cq, reserved);
1309
1382
  }
1310
1383
 
1311
1384
  grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
1312
1385
  grpc_core::ExecCtx exec_ctx;
1313
1386
  GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
1314
1387
 
1315
- grpc_server* server =
1316
- static_cast<grpc_server*>(gpr_zalloc(sizeof(grpc_server)));
1317
-
1318
- gpr_mu_init(&server->mu_global);
1319
- gpr_mu_init(&server->mu_call);
1320
- gpr_cv_init(&server->starting_cv);
1321
-
1322
- /* decremented by grpc_server_destroy */
1323
- new (&server->internal_refcount) grpc_core::RefCount();
1324
- server->root_channel_data.next = server->root_channel_data.prev =
1325
- &server->root_channel_data;
1326
-
1327
- server->channel_args = grpc_channel_args_copy(args);
1328
-
1329
- const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_ENABLE_CHANNELZ);
1330
- if (grpc_channel_arg_get_bool(arg, GRPC_ENABLE_CHANNELZ_DEFAULT)) {
1331
- arg = grpc_channel_args_find(
1332
- args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE);
1333
- size_t channel_tracer_max_memory = grpc_channel_arg_get_integer(
1334
- arg,
1335
- {GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
1336
- server->channelz_server =
1337
- grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
1338
- server, channel_tracer_max_memory);
1339
- server->channelz_server->AddTraceEvent(
1340
- grpc_core::channelz::ChannelTrace::Severity::Info,
1341
- grpc_slice_from_static_string("Server created"));
1342
- }
1343
-
1344
- if (args != nullptr) {
1345
- grpc_resource_quota* resource_quota =
1346
- grpc_resource_quota_from_channel_args(args, false /* create */);
1347
- if (resource_quota != nullptr) {
1348
- server->default_resource_user =
1349
- grpc_resource_user_create(resource_quota, "default");
1350
- }
1351
- }
1352
-
1353
- return server;
1388
+ return new grpc_server(args);
1354
1389
  }
1355
1390
 
1356
1391
  void* grpc_server_register_method(
1357
1392
  grpc_server* server, const char* method, const char* host,
1358
1393
  grpc_server_register_method_payload_handling payload_handling,
1359
1394
  uint32_t flags) {
1360
- registered_method* m;
1361
1395
  GRPC_API_TRACE(
1362
1396
  "grpc_server_register_method(server=%p, method=%s, host=%s, "
1363
1397
  "flags=0x%08x)",
@@ -1367,8 +1401,10 @@ void* grpc_server_register_method(
1367
1401
  "grpc_server_register_method method string cannot be NULL");
1368
1402
  return nullptr;
1369
1403
  }
1370
- for (m = server->registered_methods; m; m = m->next) {
1371
- if (streq(m->method, method) && streq(m->host, host)) {
1404
+ for (std::unique_ptr<grpc_core::registered_method>& m :
1405
+ server->registered_methods) {
1406
+ if (grpc_core::streq(m->method, method) &&
1407
+ grpc_core::streq(m->host, host)) {
1372
1408
  gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method,
1373
1409
  host ? host : "*");
1374
1410
  return nullptr;
@@ -1379,10 +1415,9 @@ void* grpc_server_register_method(
1379
1415
  flags);
1380
1416
  return nullptr;
1381
1417
  }
1382
- m = new registered_method(method, host, payload_handling, flags);
1383
- m->next = server->registered_methods;
1384
- server->registered_methods = m;
1385
- return m;
1418
+ server->registered_methods.emplace_back(
1419
+ new grpc_core::registered_method(method, host, payload_handling, flags));
1420
+ return static_cast<void*>(server->registered_methods.back().get());
1386
1421
  }
1387
1422
 
1388
1423
  void grpc_server_start(grpc_server* server) {
@@ -1392,42 +1427,156 @@ void grpc_server_start(grpc_server* server) {
1392
1427
  GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server));
1393
1428
 
1394
1429
  server->started = true;
1395
- server->pollset_count = 0;
1396
- server->pollsets = static_cast<grpc_pollset**>(
1397
- gpr_malloc(sizeof(grpc_pollset*) * server->cq_count));
1398
- for (i = 0; i < server->cq_count; i++) {
1430
+ for (i = 0; i < server->cqs.size(); i++) {
1399
1431
  if (grpc_cq_can_listen(server->cqs[i])) {
1400
- server->pollsets[server->pollset_count++] =
1401
- grpc_cq_pollset(server->cqs[i]);
1432
+ server->pollsets.push_back(grpc_cq_pollset(server->cqs[i]));
1402
1433
  }
1403
1434
  }
1404
1435
  if (server->unregistered_request_matcher == nullptr) {
1405
- server->unregistered_request_matcher = new RealRequestMatcher(server);
1436
+ server->unregistered_request_matcher =
1437
+ absl::make_unique<grpc_core::RealRequestMatcher>(server);
1406
1438
  }
1407
- for (registered_method* rm = server->registered_methods; rm; rm = rm->next) {
1439
+ for (std::unique_ptr<grpc_core::registered_method>& rm :
1440
+ server->registered_methods) {
1408
1441
  if (rm->matcher == nullptr) {
1409
- rm->matcher.reset(new RealRequestMatcher(server));
1442
+ rm->matcher = absl::make_unique<grpc_core::RealRequestMatcher>(server);
1410
1443
  }
1411
1444
  }
1412
1445
 
1413
- gpr_mu_lock(&server->mu_global);
1414
- server->starting = true;
1415
- gpr_mu_unlock(&server->mu_global);
1446
+ {
1447
+ grpc_core::MutexLock lock(&server->mu_global);
1448
+ server->starting = true;
1449
+ }
1416
1450
 
1417
- for (listener* l = server->listeners; l; l = l->next) {
1418
- l->start(server, l->arg, server->pollsets, server->pollset_count);
1451
+ for (auto& listener : server->listeners) {
1452
+ listener.listener->Start(server, &server->pollsets);
1419
1453
  }
1420
1454
 
1421
- gpr_mu_lock(&server->mu_global);
1455
+ grpc_core::MutexLock lock(&server->mu_global);
1422
1456
  server->starting = false;
1423
- gpr_cv_signal(&server->starting_cv);
1424
- gpr_mu_unlock(&server->mu_global);
1457
+ server->starting_cv.Signal();
1458
+ }
1459
+
1460
+ /*
1461
+ - Kills all pending requests-for-incoming-RPC-calls (i.e the requests made via
1462
+ grpc_server_request_call and grpc_server_request_registered call will now be
1463
+ cancelled). See 'kill_pending_work_locked()'
1464
+
1465
+ - Shuts down the listeners (i.e the server will no longer listen on the port
1466
+ for new incoming channels).
1467
+
1468
+ - Iterates through all channels on the server and sends shutdown msg (see
1469
+ 'ChannelBroadcaster::BroadcastShutdown' for details) to the clients via the
1470
+ transport layer. The transport layer then guarantees the following:
1471
+ -- Sends shutdown to the client (for eg: HTTP2 transport sends GOAWAY)
1472
+ -- If the server has outstanding calls that are in the process, the
1473
+ connection is NOT closed until the server is done with all those calls
1474
+ -- Once, there are no more calls in progress, the channel is closed
1475
+ */
1476
+ void grpc_server_shutdown_and_notify(grpc_server* server,
1477
+ grpc_completion_queue* cq, void* tag) {
1478
+ grpc_core::ChannelBroadcaster broadcaster;
1479
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1480
+ grpc_core::ExecCtx exec_ctx;
1481
+
1482
+ GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
1483
+ (server, cq, tag));
1484
+
1485
+ {
1486
+ /* wait for startup to be finished: locks mu_global */
1487
+ grpc_core::MutexLock lock(&server->mu_global);
1488
+ server->starting_cv.WaitUntil(&server->mu_global,
1489
+ [server] { return !server->starting; });
1490
+
1491
+ /* stay locked, and gather up some stuff to do */
1492
+ GPR_ASSERT(grpc_cq_begin_op(cq, tag));
1493
+ if (server->shutdown_published) {
1494
+ grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE,
1495
+ grpc_core::done_published_shutdown, nullptr,
1496
+ new grpc_cq_completion);
1497
+ return;
1498
+ }
1499
+ server->shutdown_tags.emplace_back(tag, cq);
1500
+ if (server->shutdown_flag.load(std::memory_order_acquire)) {
1501
+ return;
1502
+ }
1503
+
1504
+ server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
1505
+
1506
+ broadcaster.FillChannelsLocked(server);
1507
+
1508
+ server->shutdown_flag.store(true, std::memory_order_release);
1509
+
1510
+ /* collect all unregistered then registered calls */
1511
+ {
1512
+ grpc_core::MutexLock lock(&server->mu_call);
1513
+ grpc_core::kill_pending_work_locked(
1514
+ server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1515
+ }
1516
+
1517
+ grpc_core::maybe_finish_shutdown(server);
1518
+ }
1519
+
1520
+ /* Shutdown listeners */
1521
+ for (auto& listener : server->listeners) {
1522
+ grpc_core::channelz::ListenSocketNode* channelz_listen_socket_node =
1523
+ listener.listener->channelz_listen_socket_node();
1524
+ if (server->channelz_server != nullptr &&
1525
+ channelz_listen_socket_node != nullptr) {
1526
+ server->channelz_server->RemoveChildListenSocket(
1527
+ channelz_listen_socket_node->uuid());
1528
+ }
1529
+ GRPC_CLOSURE_INIT(&listener.destroy_done, grpc_core::listener_destroy_done,
1530
+ server, grpc_schedule_on_exec_ctx);
1531
+ listener.listener->SetOnDestroyDone(&listener.destroy_done);
1532
+ listener.listener.reset();
1533
+ }
1534
+
1535
+ broadcaster.BroadcastShutdown(/*send_goaway=*/true, GRPC_ERROR_NONE);
1425
1536
  }
1426
1537
 
1427
- void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets,
1428
- size_t* pollset_count) {
1429
- *pollset_count = server->pollset_count;
1430
- *pollsets = server->pollsets;
1538
+ void grpc_server_cancel_all_calls(grpc_server* server) {
1539
+ grpc_core::ChannelBroadcaster broadcaster;
1540
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1541
+ grpc_core::ExecCtx exec_ctx;
1542
+
1543
+ GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server));
1544
+
1545
+ {
1546
+ grpc_core::MutexLock lock(&server->mu_global);
1547
+ broadcaster.FillChannelsLocked(server);
1548
+ }
1549
+
1550
+ broadcaster.BroadcastShutdown(
1551
+ /*send_goaway=*/false,
1552
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
1553
+ }
1554
+
1555
+ void grpc_server_destroy(grpc_server* server) {
1556
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1557
+ grpc_core::ExecCtx exec_ctx;
1558
+
1559
+ GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server));
1560
+
1561
+ {
1562
+ grpc_core::MutexLock lock(&server->mu_global);
1563
+ GPR_ASSERT(server->shutdown_flag.load(std::memory_order_acquire) ||
1564
+ server->listeners.empty());
1565
+ GPR_ASSERT(server->listeners_destroyed == server->listeners.size());
1566
+ }
1567
+
1568
+ if (server->default_resource_user != nullptr) {
1569
+ grpc_resource_quota_unref(
1570
+ grpc_resource_user_quota(server->default_resource_user));
1571
+ grpc_resource_user_shutdown(server->default_resource_user);
1572
+ grpc_resource_user_unref(server->default_resource_user);
1573
+ }
1574
+ grpc_core::server_unref(server);
1575
+ }
1576
+
1577
+ const std::vector<grpc_pollset*>& grpc_server_get_pollsets(
1578
+ grpc_server* server) {
1579
+ return server->pollsets;
1431
1580
  }
1432
1581
 
1433
1582
  void grpc_server_setup_transport(
@@ -1437,11 +1586,9 @@ void grpc_server_setup_transport(
1437
1586
  socket_node,
1438
1587
  grpc_resource_user* resource_user) {
1439
1588
  size_t num_registered_methods;
1440
- size_t alloc;
1441
- registered_method* rm;
1442
- channel_registered_method* crm;
1589
+ grpc_core::channel_registered_method* crm;
1443
1590
  grpc_channel* channel;
1444
- channel_data* chand;
1591
+ grpc_core::channel_data* chand;
1445
1592
  uint32_t hash;
1446
1593
  size_t slots;
1447
1594
  uint32_t probes;
@@ -1450,11 +1597,11 @@ void grpc_server_setup_transport(
1450
1597
 
1451
1598
  channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport,
1452
1599
  resource_user);
1453
- chand = static_cast<channel_data*>(
1600
+ chand = static_cast<grpc_core::channel_data*>(
1454
1601
  grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0)
1455
1602
  ->channel_data);
1456
1603
  chand->server = s;
1457
- server_ref(s);
1604
+ grpc_core::server_ref(s);
1458
1605
  chand->channel = channel;
1459
1606
  if (socket_node != nullptr) {
1460
1607
  chand->channelz_socket_uuid = socket_node->uuid();
@@ -1464,27 +1611,24 @@ void grpc_server_setup_transport(
1464
1611
  }
1465
1612
 
1466
1613
  size_t cq_idx;
1467
- for (cq_idx = 0; cq_idx < s->cq_count; cq_idx++) {
1614
+ for (cq_idx = 0; cq_idx < s->cqs.size(); cq_idx++) {
1468
1615
  if (grpc_cq_pollset(s->cqs[cq_idx]) == accepting_pollset) break;
1469
1616
  }
1470
- if (cq_idx == s->cq_count) {
1617
+ if (cq_idx == s->cqs.size()) {
1471
1618
  /* completion queue not found: pick a random one to publish new calls to */
1472
- cq_idx = static_cast<size_t>(rand()) % s->cq_count;
1619
+ cq_idx = static_cast<size_t>(rand()) % s->cqs.size();
1473
1620
  }
1474
1621
  chand->cq_idx = cq_idx;
1475
1622
 
1476
- num_registered_methods = 0;
1477
- for (rm = s->registered_methods; rm; rm = rm->next) {
1478
- num_registered_methods++;
1479
- }
1623
+ num_registered_methods = s->registered_methods.size();
1480
1624
  /* build a lookup table phrased in terms of mdstr's in this channels context
1481
1625
  to quickly find registered methods */
1482
1626
  if (num_registered_methods > 0) {
1483
1627
  slots = 2 * num_registered_methods;
1484
- alloc = sizeof(channel_registered_method) * slots;
1485
- chand->registered_methods =
1486
- static_cast<channel_registered_method*>(gpr_zalloc(alloc));
1487
- for (rm = s->registered_methods; rm; rm = rm->next) {
1628
+ chand->registered_methods.reset(
1629
+ new std::vector<grpc_core::channel_registered_method>(slots));
1630
+ for (std::unique_ptr<grpc_core::registered_method>& rm :
1631
+ s->registered_methods) {
1488
1632
  grpc_core::ExternallyManagedSlice host;
1489
1633
  grpc_core::ExternallyManagedSlice method(rm->method.c_str());
1490
1634
  const bool has_host = !rm->host.empty();
@@ -1492,13 +1636,13 @@ void grpc_server_setup_transport(
1492
1636
  host = grpc_core::ExternallyManagedSlice(rm->host.c_str());
1493
1637
  }
1494
1638
  hash = GRPC_MDSTR_KV_HASH(has_host ? host.Hash() : 0, method.Hash());
1495
- for (probes = 0; chand->registered_methods[(hash + probes) % slots]
1639
+ for (probes = 0; (*chand->registered_methods)[(hash + probes) % slots]
1496
1640
  .server_registered_method != nullptr;
1497
- probes++)
1498
- ;
1641
+ probes++) {
1642
+ }
1499
1643
  if (probes > max_probes) max_probes = probes;
1500
- crm = &chand->registered_methods[(hash + probes) % slots];
1501
- crm->server_registered_method = rm;
1644
+ crm = &(*chand->registered_methods)[(hash + probes) % slots];
1645
+ crm->server_registered_method = rm.get();
1502
1646
  crm->flags = rm->flags;
1503
1647
  crm->has_host = has_host;
1504
1648
  if (has_host) {
@@ -1507,215 +1651,27 @@ void grpc_server_setup_transport(
1507
1651
  crm->method = method;
1508
1652
  }
1509
1653
  GPR_ASSERT(slots <= UINT32_MAX);
1510
- chand->registered_method_slots = static_cast<uint32_t>(slots);
1511
1654
  chand->registered_method_max_probes = max_probes;
1512
1655
  }
1513
1656
 
1514
- gpr_mu_lock(&s->mu_global);
1515
- chand->next = &s->root_channel_data;
1516
- chand->prev = chand->next->prev;
1517
- chand->next->prev = chand->prev->next = chand;
1518
- gpr_mu_unlock(&s->mu_global);
1657
+ {
1658
+ grpc_core::MutexLock lock(&s->mu_global);
1659
+ s->channels.push_front(chand);
1660
+ chand->list_position = s->channels.begin();
1661
+ }
1519
1662
 
1520
1663
  op = grpc_make_transport_op(nullptr);
1521
1664
  op->set_accept_stream = true;
1522
- op->set_accept_stream_fn = accept_stream;
1665
+ op->set_accept_stream_fn = grpc_core::accept_stream;
1523
1666
  op->set_accept_stream_user_data = chand;
1524
- op->start_connectivity_watch.reset(new ConnectivityWatcher(chand));
1525
- if (gpr_atm_acq_load(&s->shutdown_flag) != 0) {
1667
+ op->start_connectivity_watch.reset(new grpc_core::ConnectivityWatcher(chand));
1668
+ if (s->shutdown_flag.load(std::memory_order_acquire)) {
1526
1669
  op->disconnect_with_error =
1527
1670
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown");
1528
1671
  }
1529
1672
  grpc_transport_perform_op(transport, op);
1530
1673
  }
1531
1674
 
1532
- /*
1533
- - Kills all pending requests-for-incoming-RPC-calls (i.e the requests made via
1534
- grpc_server_request_call and grpc_server_request_registered call will now be
1535
- cancelled). See 'kill_pending_work_locked()'
1536
-
1537
- - Shuts down the listeners (i.e the server will no longer listen on the port
1538
- for new incoming channels).
1539
-
1540
- - Iterates through all channels on the server and sends shutdown msg (see
1541
- 'channel_broadcaster_shutdown()' for details) to the clients via the
1542
- transport layer. The transport layer then guarantees the following:
1543
- -- Sends shutdown to the client (for eg: HTTP2 transport sends GOAWAY)
1544
- -- If the server has outstanding calls that are in the process, the
1545
- connection is NOT closed until the server is done with all those calls
1546
- -- Once, there are no more calls in progress, the channel is closed
1547
- */
1548
- void grpc_server_shutdown_and_notify(grpc_server* server,
1549
- grpc_completion_queue* cq, void* tag) {
1550
- listener* l;
1551
- shutdown_tag* sdt;
1552
- channel_broadcaster broadcaster;
1553
- grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1554
- grpc_core::ExecCtx exec_ctx;
1555
-
1556
- GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
1557
- (server, cq, tag));
1558
-
1559
- /* wait for startup to be finished: locks mu_global */
1560
- gpr_mu_lock(&server->mu_global);
1561
- while (server->starting) {
1562
- gpr_cv_wait(&server->starting_cv, &server->mu_global,
1563
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
1564
- }
1565
-
1566
- /* stay locked, and gather up some stuff to do */
1567
- GPR_ASSERT(grpc_cq_begin_op(cq, tag));
1568
- if (server->shutdown_published) {
1569
- grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr,
1570
- static_cast<grpc_cq_completion*>(
1571
- gpr_malloc(sizeof(grpc_cq_completion))));
1572
- gpr_mu_unlock(&server->mu_global);
1573
- return;
1574
- }
1575
- server->shutdown_tags = static_cast<shutdown_tag*>(
1576
- gpr_realloc(server->shutdown_tags,
1577
- sizeof(shutdown_tag) * (server->num_shutdown_tags + 1)));
1578
- sdt = &server->shutdown_tags[server->num_shutdown_tags++];
1579
- sdt->tag = tag;
1580
- sdt->cq = cq;
1581
- if (gpr_atm_acq_load(&server->shutdown_flag)) {
1582
- gpr_mu_unlock(&server->mu_global);
1583
- return;
1584
- }
1585
-
1586
- server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
1587
-
1588
- channel_broadcaster_init(server, &broadcaster);
1589
-
1590
- gpr_atm_rel_store(&server->shutdown_flag, 1);
1591
-
1592
- /* collect all unregistered then registered calls */
1593
- gpr_mu_lock(&server->mu_call);
1594
- kill_pending_work_locked(
1595
- server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1596
- gpr_mu_unlock(&server->mu_call);
1597
-
1598
- maybe_finish_shutdown(server);
1599
- gpr_mu_unlock(&server->mu_global);
1600
-
1601
- /* Shutdown listeners */
1602
- for (l = server->listeners; l; l = l->next) {
1603
- GRPC_CLOSURE_INIT(&l->destroy_done, listener_destroy_done, server,
1604
- grpc_schedule_on_exec_ctx);
1605
- l->destroy(server, l->arg, &l->destroy_done);
1606
- if (server->channelz_server != nullptr && l->socket_uuid != 0) {
1607
- server->channelz_server->RemoveChildListenSocket(l->socket_uuid);
1608
- }
1609
- }
1610
-
1611
- channel_broadcaster_shutdown(&broadcaster, true /* send_goaway */,
1612
- GRPC_ERROR_NONE);
1613
-
1614
- if (server->default_resource_user != nullptr) {
1615
- grpc_resource_quota_unref(
1616
- grpc_resource_user_quota(server->default_resource_user));
1617
- grpc_resource_user_shutdown(server->default_resource_user);
1618
- grpc_resource_user_unref(server->default_resource_user);
1619
- }
1620
- }
1621
-
1622
- void grpc_server_cancel_all_calls(grpc_server* server) {
1623
- channel_broadcaster broadcaster;
1624
- grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1625
- grpc_core::ExecCtx exec_ctx;
1626
-
1627
- GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server));
1628
-
1629
- gpr_mu_lock(&server->mu_global);
1630
- channel_broadcaster_init(server, &broadcaster);
1631
- gpr_mu_unlock(&server->mu_global);
1632
-
1633
- channel_broadcaster_shutdown(
1634
- &broadcaster, false /* send_goaway */,
1635
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
1636
- }
1637
-
1638
- void grpc_server_destroy(grpc_server* server) {
1639
- listener* l;
1640
- grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1641
- grpc_core::ExecCtx exec_ctx;
1642
-
1643
- GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server));
1644
-
1645
- gpr_mu_lock(&server->mu_global);
1646
- GPR_ASSERT(gpr_atm_acq_load(&server->shutdown_flag) || !server->listeners);
1647
- GPR_ASSERT(server->listeners_destroyed == num_listeners(server));
1648
-
1649
- while (server->listeners) {
1650
- l = server->listeners;
1651
- server->listeners = l->next;
1652
- gpr_free(l);
1653
- }
1654
-
1655
- gpr_mu_unlock(&server->mu_global);
1656
-
1657
- server_unref(server);
1658
- }
1659
-
1660
- void grpc_server_add_listener(
1661
- grpc_server* server, void* listener_arg,
1662
- void (*start)(grpc_server* server, void* arg, grpc_pollset** pollsets,
1663
- size_t pollset_count),
1664
- void (*destroy)(grpc_server* server, void* arg, grpc_closure* on_done),
1665
- grpc_core::RefCountedPtr<grpc_core::channelz::ListenSocketNode> node) {
1666
- listener* l = static_cast<listener*>(gpr_malloc(sizeof(listener)));
1667
- l->arg = listener_arg;
1668
- l->start = start;
1669
- l->destroy = destroy;
1670
- l->socket_uuid = 0;
1671
- if (node != nullptr) {
1672
- l->socket_uuid = node->uuid();
1673
- if (server->channelz_server != nullptr) {
1674
- server->channelz_server->AddChildListenSocket(std::move(node));
1675
- }
1676
- }
1677
- l->next = server->listeners;
1678
- server->listeners = l;
1679
- }
1680
-
1681
- namespace {
1682
- grpc_call_error ValidateServerRequest(
1683
- grpc_completion_queue* cq_for_notification, void* tag,
1684
- grpc_byte_buffer** optional_payload, registered_method* rm) {
1685
- if ((rm == nullptr && optional_payload != nullptr) ||
1686
- ((rm != nullptr) && ((optional_payload == nullptr) !=
1687
- (rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)))) {
1688
- return GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
1689
- }
1690
- if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
1691
- return GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
1692
- }
1693
- return GRPC_CALL_OK;
1694
- }
1695
- grpc_call_error ValidateServerRequestAndCq(
1696
- size_t* cq_idx, grpc_server* server,
1697
- grpc_completion_queue* cq_for_notification, void* tag,
1698
- grpc_byte_buffer** optional_payload, registered_method* rm) {
1699
- size_t idx;
1700
- for (idx = 0; idx < server->cq_count; idx++) {
1701
- if (server->cqs[idx] == cq_for_notification) {
1702
- break;
1703
- }
1704
- }
1705
- if (idx == server->cq_count) {
1706
- return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
1707
- }
1708
- grpc_call_error error =
1709
- ValidateServerRequest(cq_for_notification, tag, optional_payload, rm);
1710
- if (error != GRPC_CALL_OK) {
1711
- return error;
1712
- }
1713
-
1714
- *cq_idx = idx;
1715
- return GRPC_CALL_OK;
1716
- }
1717
- } // namespace
1718
-
1719
1675
  grpc_call_error grpc_server_request_call(
1720
1676
  grpc_server* server, grpc_call** call, grpc_call_details* details,
1721
1677
  grpc_metadata_array* initial_metadata,
@@ -1733,14 +1689,14 @@ grpc_call_error grpc_server_request_call(
1733
1689
  cq_for_notification, tag));
1734
1690
 
1735
1691
  size_t cq_idx;
1736
- grpc_call_error error = ValidateServerRequestAndCq(
1692
+ grpc_call_error error = grpc_core::ValidateServerRequestAndCq(
1737
1693
  &cq_idx, server, cq_for_notification, tag, nullptr, nullptr);
1738
1694
  if (error != GRPC_CALL_OK) {
1739
1695
  return error;
1740
1696
  }
1741
1697
 
1742
- requested_call* rc = new requested_call(tag, cq_bound_to_call, call,
1743
- initial_metadata, details);
1698
+ grpc_core::requested_call* rc = new grpc_core::requested_call(
1699
+ tag, cq_bound_to_call, call, initial_metadata, details);
1744
1700
  return queue_call_request(server, cq_idx, rc);
1745
1701
  }
1746
1702
 
@@ -1748,11 +1704,12 @@ grpc_call_error grpc_server_request_registered_call(
1748
1704
  grpc_server* server, void* rmp, grpc_call** call, gpr_timespec* deadline,
1749
1705
  grpc_metadata_array* initial_metadata, grpc_byte_buffer** optional_payload,
1750
1706
  grpc_completion_queue* cq_bound_to_call,
1751
- grpc_completion_queue* cq_for_notification, void* tag) {
1707
+ grpc_completion_queue* cq_for_notification, void* tag_new) {
1752
1708
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1753
1709
  grpc_core::ExecCtx exec_ctx;
1754
1710
  GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
1755
- registered_method* rm = static_cast<registered_method*>(rmp);
1711
+ grpc_core::registered_method* rm =
1712
+ static_cast<grpc_core::registered_method*>(rmp);
1756
1713
  GRPC_API_TRACE(
1757
1714
  "grpc_server_request_registered_call("
1758
1715
  "server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, "
@@ -1760,41 +1717,17 @@ grpc_call_error grpc_server_request_registered_call(
1760
1717
  "tag=%p)",
1761
1718
  9,
1762
1719
  (server, rmp, call, deadline, initial_metadata, optional_payload,
1763
- cq_bound_to_call, cq_for_notification, tag));
1720
+ cq_bound_to_call, cq_for_notification, tag_new));
1764
1721
 
1765
1722
  size_t cq_idx;
1766
1723
  grpc_call_error error = ValidateServerRequestAndCq(
1767
- &cq_idx, server, cq_for_notification, tag, optional_payload, rm);
1724
+ &cq_idx, server, cq_for_notification, tag_new, optional_payload, rm);
1768
1725
  if (error != GRPC_CALL_OK) {
1769
1726
  return error;
1770
1727
  }
1771
1728
 
1772
- requested_call* rc =
1773
- new requested_call(tag, cq_bound_to_call, call, initial_metadata, rm,
1774
- deadline, optional_payload);
1729
+ grpc_core::requested_call* rc = new grpc_core::requested_call(
1730
+ tag_new, cq_bound_to_call, call, initial_metadata, rm, deadline,
1731
+ optional_payload);
1775
1732
  return queue_call_request(server, cq_idx, rc);
1776
1733
  }
1777
-
1778
- const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) {
1779
- return server->channel_args;
1780
- }
1781
-
1782
- grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server) {
1783
- return server->default_resource_user;
1784
- }
1785
-
1786
- int grpc_server_has_open_connections(grpc_server* server) {
1787
- int r;
1788
- gpr_mu_lock(&server->mu_global);
1789
- r = server->root_channel_data.next != &server->root_channel_data;
1790
- gpr_mu_unlock(&server->mu_global);
1791
- return r;
1792
- }
1793
-
1794
- grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
1795
- grpc_server* server) {
1796
- if (server == nullptr) {
1797
- return nullptr;
1798
- }
1799
- return server->channelz_server.get();
1800
- }