grpc 1.28.0.pre2 → 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.
- checksums.yaml +4 -4
- data/Makefile +8313 -11862
- data/include/grpc/grpc.h +2 -2
- data/include/grpc/grpc_security.h +30 -9
- data/include/grpc/grpc_security_constants.h +4 -0
- data/include/grpc/impl/codegen/grpc_types.h +23 -23
- data/include/grpc/impl/codegen/port_platform.h +6 -34
- data/include/grpc/module.modulemap +24 -39
- data/src/core/ext/filters/client_channel/backend_metric.cc +18 -12
- data/src/core/ext/filters/client_channel/client_channel.cc +618 -482
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -2
- data/src/core/ext/filters/client_channel/config_selector.cc +62 -0
- data/src/core/ext/filters/client_channel/config_selector.h +93 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -2
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +9 -22
- data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +6 -5
- data/src/core/ext/filters/client_channel/http_proxy.cc +23 -14
- data/src/core/ext/filters/client_channel/lb_policy.cc +19 -18
- data/src/core/ext/filters/client_channel/lb_policy.h +44 -33
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +83 -0
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +99 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +297 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +83 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +311 -497
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +11 -9
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +871 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -17
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +734 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +117 -41
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +938 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +528 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +1142 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +10 -7
- data/src/core/ext/filters/client_channel/local_subchannel_pool.h +2 -1
- data/src/core/ext/filters/client_channel/parse_address.cc +22 -21
- data/src/core/ext/filters/client_channel/resolver.cc +5 -8
- data/src/core/ext/filters/client_channel/resolver.h +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +78 -61
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +41 -40
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +8 -7
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +22 -24
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +12 -10
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +79 -122
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +199 -163
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +7 -4
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +46 -45
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +93 -102
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +0 -4
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +64 -12
- data/src/core/ext/filters/client_channel/resolver_factory.h +2 -2
- data/src/core/ext/filters/client_channel/resolver_registry.cc +19 -17
- data/src/core/ext/filters/client_channel/resolver_registry.h +8 -8
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +21 -22
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +19 -16
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +73 -217
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +45 -27
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +6 -12
- data/src/core/ext/filters/client_channel/service_config.cc +104 -144
- data/src/core/ext/filters/client_channel/service_config.h +28 -98
- data/src/core/ext/filters/client_channel/service_config_call_data.h +68 -0
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +142 -0
- data/src/core/ext/filters/client_channel/service_config_parser.cc +87 -0
- data/src/core/ext/filters/client_channel/service_config_parser.h +89 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +55 -25
- data/src/core/ext/filters/client_channel/subchannel.h +35 -11
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +1200 -246
- data/src/core/ext/filters/client_channel/xds/xds_api.h +130 -44
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +90 -29
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +9 -4
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +4 -2
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +839 -431
- data/src/core/ext/filters/client_channel/xds/xds_client.h +84 -33
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +11 -12
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +40 -28
- data/src/core/ext/filters/http/client/http_client_filter.cc +28 -33
- data/src/core/ext/filters/http/client_authority_filter.cc +4 -4
- data/src/core/ext/filters/http/http_filters_plugin.cc +28 -12
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +258 -221
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +399 -0
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +31 -0
- data/src/core/ext/filters/message_size/message_size_filter.cc +61 -88
- data/src/core/ext/filters/message_size/message_size_filter.h +10 -4
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +386 -350
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +6 -2
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +7 -13
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +7 -8
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +4 -6
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +42 -26
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +25 -30
- data/src/core/ext/transport/chttp2/transport/flow_control.h +14 -16
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +9 -12
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -6
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +12 -13
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -7
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -3
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +9 -12
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +29 -16
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +25 -29
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +13 -17
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +2 -2
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +4 -5
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +2 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +27 -21
- data/src/core/ext/transport/chttp2/transport/parsing.cc +33 -43
- data/src/core/ext/transport/chttp2/transport/stream_map.h +2 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +24 -22
- data/src/core/ext/transport/inproc/inproc_transport.cc +54 -15
- data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +3 -4
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +4 -229
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +5 -876
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +114 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +429 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +72 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +198 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +105 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +388 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +23 -10
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +352 -310
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +42 -34
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +7 -7
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +79 -61
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +55 -49
- data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +79 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +48 -27
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +258 -214
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +51 -45
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +71 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +107 -100
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +24 -20
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +157 -122
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +9 -9
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +38 -18
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +173 -73
- data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +88 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +95 -101
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +49 -65
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +9 -6
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +53 -38
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +70 -62
- data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +15 -10
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +95 -63
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +3 -2
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +91 -80
- data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +9 -10
- data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +36 -31
- data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +68 -46
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +770 -722
- data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +16 -15
- data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +2 -1
- data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +95 -88
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +48 -28
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +305 -210
- data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +5 -5
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +51 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +125 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +1 -2
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +4 -2
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +22 -16
- data/src/core/ext/upb-generated/envoy/type/http.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/http.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +16 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +48 -11
- data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +14 -14
- data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +23 -23
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.h +8 -9
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.h +15 -16
- data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +7 -8
- data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +1 -0
- data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +36 -35
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -1
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +0 -1
- data/src/core/ext/upb-generated/google/api/http.upb.h +29 -28
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +12 -11
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +421 -389
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +1 -2
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +1 -1
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +33 -54
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -28
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +8 -8
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +1 -1
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +32 -45
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +4 -4
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +157 -178
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +14 -13
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -7
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +59 -56
- data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +11 -12
- data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +0 -1
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +28 -0
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +64 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +6 -6
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +41 -68
- data/src/core/ext/upb-generated/validate/validate.upb.c +21 -20
- data/src/core/ext/upb-generated/validate/validate.upb.h +569 -562
- data/src/core/lib/channel/channel_args.cc +15 -14
- data/src/core/lib/channel/channel_args.h +3 -1
- data/src/core/lib/channel/channel_stack.h +20 -13
- data/src/core/lib/channel/channel_trace.cc +2 -6
- data/src/core/lib/channel/channelz.cc +10 -21
- data/src/core/lib/channel/channelz.h +3 -2
- data/src/core/lib/channel/channelz_registry.cc +5 -3
- data/src/core/lib/channel/connected_channel.cc +7 -5
- data/src/core/lib/channel/context.h +1 -1
- data/src/core/lib/channel/handshaker.cc +11 -13
- data/src/core/lib/channel/handshaker.h +4 -2
- data/src/core/lib/channel/handshaker_registry.cc +5 -17
- data/src/core/lib/channel/status_util.cc +2 -3
- data/src/core/lib/compression/message_compress.cc +5 -1
- data/src/core/lib/debug/stats.cc +21 -27
- data/src/core/lib/debug/stats.h +3 -1
- data/src/core/lib/gpr/log_linux.cc +6 -8
- data/src/core/lib/gpr/log_posix.cc +6 -8
- data/src/core/lib/gpr/spinlock.h +2 -3
- data/src/core/lib/gpr/string.cc +10 -33
- data/src/core/lib/gpr/string.h +4 -18
- data/src/core/lib/gpr/sync_abseil.cc +2 -0
- data/src/core/lib/gpr/time.cc +4 -0
- data/src/core/lib/gpr/time_posix.cc +1 -1
- data/src/core/lib/gprpp/atomic.h +6 -6
- data/src/core/lib/gprpp/fork.cc +1 -1
- data/src/core/lib/gprpp/global_config_env.cc +8 -6
- data/src/core/lib/gprpp/host_port.cc +29 -35
- data/src/core/lib/gprpp/host_port.h +14 -17
- data/src/core/lib/gprpp/map.h +5 -11
- data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
- data/src/core/lib/gprpp/sync.h +9 -0
- data/src/core/lib/http/format_request.cc +46 -65
- data/src/core/lib/http/httpcli.cc +15 -13
- data/src/core/lib/http/httpcli.h +2 -3
- data/src/core/lib/http/httpcli_security_connector.cc +10 -10
- data/src/core/lib/http/parser.h +2 -3
- data/src/core/lib/iomgr/buffer_list.h +22 -21
- data/src/core/lib/iomgr/call_combiner.h +3 -2
- data/src/core/lib/iomgr/cfstream_handle.cc +4 -2
- data/src/core/lib/iomgr/closure.h +2 -3
- data/src/core/lib/iomgr/dualstack_socket_posix.cc +47 -0
- data/src/core/lib/iomgr/endpoint_cfstream.cc +2 -3
- data/src/core/lib/iomgr/endpoint_pair.h +2 -3
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +10 -10
- data/src/core/lib/iomgr/error.cc +6 -9
- data/src/core/lib/iomgr/error.h +0 -1
- data/src/core/lib/iomgr/error_cfstream.cc +9 -8
- data/src/core/lib/iomgr/ev_apple.cc +356 -0
- data/src/core/lib/iomgr/ev_apple.h +43 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +25 -29
- data/src/core/lib/iomgr/ev_epollex_linux.cc +17 -24
- data/src/core/lib/iomgr/ev_poll_posix.cc +9 -8
- data/src/core/lib/iomgr/ev_posix.cc +4 -3
- data/src/core/lib/iomgr/exec_ctx.h +14 -2
- data/src/core/lib/iomgr/iomgr.cc +10 -0
- data/src/core/lib/iomgr/iomgr.h +10 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +84 -20
- data/src/core/lib/iomgr/is_epollexclusive_available.cc +14 -0
- data/src/core/lib/iomgr/pollset_set_custom.cc +10 -10
- data/src/core/lib/{gprpp/optional.h → iomgr/pollset_uv.h} +11 -12
- data/src/core/lib/iomgr/port.h +2 -21
- data/src/core/lib/iomgr/python_util.h +46 -0
- data/src/core/lib/iomgr/resolve_address.h +4 -6
- data/src/core/lib/iomgr/resolve_address_custom.cc +42 -57
- data/src/core/lib/iomgr/resolve_address_custom.h +4 -2
- data/src/core/lib/iomgr/resolve_address_posix.cc +10 -11
- data/src/core/lib/iomgr/resolve_address_windows.cc +16 -25
- data/src/core/lib/iomgr/resource_quota.cc +38 -37
- data/src/core/lib/iomgr/sockaddr_utils.cc +29 -33
- data/src/core/lib/iomgr/sockaddr_utils.h +10 -15
- data/src/core/lib/iomgr/socket_factory_posix.h +2 -3
- data/src/core/lib/iomgr/socket_mutator.h +2 -3
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +102 -81
- data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
- data/src/core/lib/iomgr/socket_windows.cc +4 -5
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +14 -18
- data/src/core/lib/iomgr/tcp_client_custom.cc +6 -9
- data/src/core/lib/iomgr/tcp_client_posix.cc +30 -36
- data/src/core/lib/iomgr/tcp_client_windows.cc +10 -11
- data/src/core/lib/iomgr/tcp_custom.cc +3 -4
- data/src/core/lib/iomgr/tcp_custom.h +1 -1
- data/src/core/lib/iomgr/tcp_server.cc +3 -4
- data/src/core/lib/iomgr/tcp_server.h +7 -5
- data/src/core/lib/iomgr/tcp_server_custom.cc +11 -23
- data/src/core/lib/iomgr/tcp_server_posix.cc +38 -44
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -4
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +7 -8
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +10 -18
- data/src/core/lib/iomgr/tcp_server_windows.cc +16 -16
- data/src/core/lib/iomgr/tcp_uv.cc +3 -2
- data/src/core/lib/iomgr/time_averaged_stats.h +2 -3
- data/src/core/lib/iomgr/timer_generic.cc +15 -15
- data/src/core/lib/{gprpp/inlined_vector.h → iomgr/timer_generic.h} +19 -17
- data/src/core/lib/iomgr/timer_heap.h +2 -3
- data/src/core/lib/iomgr/udp_server.cc +32 -36
- data/src/core/lib/iomgr/udp_server.h +5 -2
- data/src/core/lib/iomgr/unix_sockets_posix.cc +9 -14
- data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +5 -2
- data/src/core/lib/json/json.h +3 -2
- data/src/core/lib/json/json_reader.cc +25 -26
- data/src/core/lib/json/json_writer.cc +13 -12
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +12 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +6 -3
- data/src/core/lib/security/credentials/credentials.cc +0 -84
- data/src/core/lib/security/credentials/credentials.h +13 -62
- data/src/core/lib/security/credentials/fake/fake_credentials.h +4 -0
- data/src/core/lib/security/credentials/google_default/credentials_generic.cc +8 -6
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -17
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +8 -6
- data/src/core/lib/security/credentials/iam/iam_credentials.h +4 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
- data/src/core/lib/security/credentials/jwt/json_token.h +2 -5
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +12 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -15
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +73 -54
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +9 -3
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +19 -6
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -13
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +48 -11
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +21 -6
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +17 -17
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +3 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
- data/src/core/lib/security/security_connector/security_connector.cc +2 -0
- data/src/core/lib/security/security_connector/security_connector.h +2 -2
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +38 -36
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +8 -5
- data/src/core/lib/security/security_connector/ssl_utils.cc +89 -21
- data/src/core/lib/security/security_connector/ssl_utils.h +18 -12
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +101 -72
- data/src/core/lib/security/security_connector/tls/tls_security_connector.h +27 -5
- data/src/core/lib/security/transport/auth_filters.h +0 -5
- data/src/core/lib/security/transport/client_auth_filter.cc +11 -11
- data/src/core/lib/security/util/json_util.cc +12 -13
- data/src/core/lib/slice/slice.cc +38 -1
- data/src/core/lib/slice/slice_intern.cc +2 -3
- data/src/core/lib/slice/slice_internal.h +15 -0
- data/src/core/lib/slice/slice_utils.h +9 -0
- data/src/core/lib/surface/byte_buffer_reader.cc +2 -47
- data/src/core/lib/surface/call.cc +42 -44
- data/src/core/lib/surface/call_log_batch.cc +50 -58
- data/src/core/lib/surface/channel.cc +53 -31
- data/src/core/lib/surface/channel.h +35 -4
- data/src/core/lib/surface/channel_ping.cc +2 -3
- data/src/core/lib/surface/completion_queue.cc +304 -47
- data/src/core/lib/surface/completion_queue.h +8 -0
- data/src/core/lib/surface/event_string.cc +18 -25
- data/src/core/lib/surface/event_string.h +3 -1
- data/src/core/lib/surface/init.cc +2 -0
- data/src/core/lib/surface/init_secure.cc +1 -4
- data/src/core/lib/surface/server.cc +971 -837
- data/src/core/lib/surface/server.h +66 -12
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/byte_stream.h +7 -2
- data/src/core/lib/transport/connectivity_state.cc +7 -6
- data/src/core/lib/transport/connectivity_state.h +5 -3
- data/src/core/lib/transport/metadata.cc +3 -3
- data/src/core/lib/transport/metadata_batch.h +2 -3
- data/src/core/lib/transport/static_metadata.h +1 -1
- data/src/core/lib/transport/status_conversion.cc +6 -14
- data/src/core/lib/transport/transport.cc +2 -3
- data/src/core/lib/transport/transport.h +9 -2
- data/src/core/lib/transport/transport_op_string.cc +61 -102
- data/src/core/lib/uri/uri_parser.cc +8 -15
- data/src/core/lib/uri/uri_parser.h +2 -3
- data/src/core/plugin_registry/grpc_plugin_registry.cc +24 -4
- data/src/core/tsi/alts/crypt/aes_gcm.cc +0 -2
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +31 -14
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +8 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +9 -1
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +2 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +2 -3
- data/src/core/tsi/fake_transport_security.cc +10 -15
- data/src/core/tsi/ssl/session_cache/ssl_session.h +0 -2
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +0 -2
- data/src/core/tsi/ssl_transport_security.cc +154 -50
- data/src/core/tsi/ssl_transport_security.h +22 -10
- data/src/core/tsi/ssl_types.h +0 -2
- data/src/core/tsi/transport_security.h +6 -9
- data/src/core/tsi/transport_security_grpc.h +2 -3
- data/src/core/tsi/transport_security_interface.h +8 -3
- data/src/ruby/ext/grpc/extconf.rb +5 -2
- data/src/ruby/ext/grpc/rb_call.c +12 -3
- data/src/ruby/ext/grpc/rb_call.h +4 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +57 -12
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
- data/src/ruby/lib/grpc/errors.rb +103 -42
- data/src/ruby/lib/grpc/generic/active_call.rb +2 -3
- data/src/ruby/lib/grpc/generic/interceptors.rb +5 -5
- data/src/ruby/lib/grpc/generic/rpc_server.rb +9 -10
- data/src/ruby/lib/grpc/generic/service.rb +5 -4
- data/src/ruby/lib/grpc/structs.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/generate_proto_ruby.sh +5 -3
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +11 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +16 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/generic/service_spec.rb +2 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +7 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +7 -1
- data/src/ruby/spec/support/services.rb +10 -4
- data/src/ruby/spec/testdata/ca.pem +18 -13
- data/src/ruby/spec/testdata/client.key +26 -14
- data/src/ruby/spec/testdata/client.pem +18 -12
- data/src/ruby/spec/testdata/server1.key +26 -14
- data/src/ruby/spec/testdata/server1.pem +20 -14
- data/third_party/abseil-cpp/absl/time/civil_time.cc +175 -0
- data/third_party/abseil-cpp/absl/time/civil_time.h +538 -0
- data/third_party/abseil-cpp/absl/time/clock.cc +569 -0
- data/third_party/abseil-cpp/absl/time/clock.h +74 -0
- data/third_party/abseil-cpp/absl/time/duration.cc +922 -0
- data/third_party/abseil-cpp/absl/time/format.cc +153 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time.h +332 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +622 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +384 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +102 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/civil_time_detail.cc +94 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +140 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.h +52 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +922 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +45 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +76 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +121 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +93 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +958 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +138 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +308 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +55 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +187 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.cc +159 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +132 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +122 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +115 -0
- data/third_party/abseil-cpp/absl/time/internal/get_current_time_chrono.inc +31 -0
- data/third_party/abseil-cpp/absl/time/internal/get_current_time_posix.inc +24 -0
- data/third_party/abseil-cpp/absl/time/time.cc +499 -0
- data/third_party/abseil-cpp/absl/time/time.h +1584 -0
- data/third_party/boringssl-with-bazel/err_data.c +335 -297
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/asn_pack.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_enum.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_int.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_string.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/derive_key.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c +7 -5
- data/third_party/boringssl-with-bazel/src/crypto/cpu-intel.c +13 -4
- data/third_party/boringssl-with-bazel/src/crypto/crypto.c +11 -0
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519.c +18 -26
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519_tables.h +13 -21
- data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/internal.h +14 -22
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/dh/dh.c +15 -0
- data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +385 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +56 -0
- data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/err/err.c +33 -32
- data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +143 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/aes_nohw.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.c +17 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +25 -12
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +8 -8
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.c +30 -154
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +16 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +289 -117
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +13 -27
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +96 -55
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +25 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +434 -161
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +63 -71
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +18 -25
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64-table.h +9481 -9485
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +104 -122
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +740 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +297 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +90 -11
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +125 -148
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +189 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/util.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +61 -18
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +20 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +137 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.h +49 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/getrandom_fillin.h +64 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +41 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +32 -17
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +24 -114
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/blinding.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +51 -38
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +15 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +62 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +44 -35
- data/third_party/boringssl-with-bazel/src/crypto/mem.c +47 -16
- data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +15 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +7 -0
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +36 -5
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +6 -10
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +16 -0
- data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +4 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +249 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +1227 -0
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +682 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +8 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509.c +0 -67
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +13 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +57 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +4 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +33 -9
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +25 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +4 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -13
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +0 -154
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +28 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +5 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +74 -35
- data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +16 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +22 -22
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +6 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +9 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +20 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +1 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +16 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +6 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/err.h +2 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +69 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +5 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +3 -17
- data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +31 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +26 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +191 -79
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +1 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +282 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +791 -715
- data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +1 -0
- data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +0 -4
- data/third_party/boringssl-with-bazel/src/ssl/d1_lib.cc +3 -3
- data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +13 -4
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +146 -57
- data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +23 -5
- data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +30 -22
- data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +21 -4
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +74 -54
- data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +10 -10
- data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
- data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +21 -21
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +29 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +34 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +13 -2
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +44 -5
- data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +6 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +5 -5
- data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +51 -26
- data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +47 -53
- data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -1
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +129 -48
- data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +23 -75
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +55 -22
- data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +63 -25
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_32.h +245 -175
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64.h +135 -75
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_32.h +1593 -1672
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +512 -503
- data/third_party/upb/upb/decode.c +467 -504
- data/third_party/upb/upb/encode.c +163 -121
- data/third_party/upb/upb/msg.c +130 -64
- data/third_party/upb/upb/msg.h +418 -14
- data/third_party/upb/upb/port_def.inc +35 -6
- data/third_party/upb/upb/port_undef.inc +8 -1
- data/third_party/upb/upb/table.c +53 -75
- data/third_party/upb/upb/table.int.h +11 -43
- data/third_party/upb/upb/upb.c +148 -124
- data/third_party/upb/upb/upb.h +65 -147
- data/third_party/upb/upb/upb.hpp +86 -0
- metadata +122 -41
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +0 -1908
- data/src/core/lib/gprpp/string_view.h +0 -60
- data/src/core/tsi/grpc_shadow_boringssl.h +0 -3311
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256.c +0 -1063
- 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
|
@@ -22,47 +22,40 @@
|
|
22
22
|
|
23
23
|
#include <stdio.h>
|
24
24
|
|
25
|
+
#include <vector>
|
26
|
+
|
27
|
+
#include "absl/strings/str_format.h"
|
28
|
+
#include "absl/strings/str_join.h"
|
29
|
+
|
25
30
|
#include <grpc/byte_buffer.h>
|
26
31
|
#include <grpc/support/string_util.h>
|
27
32
|
#include "src/core/lib/gpr/string.h"
|
28
33
|
|
29
|
-
static void addhdr(
|
30
|
-
|
31
|
-
gpr_asprintf(&tmp, "tag:%p", ev->tag);
|
32
|
-
gpr_strvec_add(buf, tmp);
|
34
|
+
static void addhdr(grpc_event* ev, std::vector<std::string>* buf) {
|
35
|
+
buf->push_back(absl::StrFormat("tag:%p", ev->tag));
|
33
36
|
}
|
34
37
|
|
35
38
|
static const char* errstr(int success) { return success ? "OK" : "ERROR"; }
|
36
39
|
|
37
|
-
static void adderr(
|
38
|
-
|
39
|
-
gpr_asprintf(&tmp, " %s", errstr(success));
|
40
|
-
gpr_strvec_add(buf, tmp);
|
40
|
+
static void adderr(int success, std::vector<std::string>* buf) {
|
41
|
+
buf->push_back(absl::StrFormat(" %s", errstr(success)));
|
41
42
|
}
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if (ev == nullptr) return gpr_strdup("null");
|
48
|
-
|
49
|
-
gpr_strvec_init(&buf);
|
50
|
-
|
44
|
+
std::string grpc_event_string(grpc_event* ev) {
|
45
|
+
if (ev == nullptr) return "null";
|
46
|
+
std::vector<std::string> out;
|
51
47
|
switch (ev->type) {
|
52
48
|
case GRPC_QUEUE_TIMEOUT:
|
53
|
-
|
49
|
+
out.push_back("QUEUE_TIMEOUT");
|
54
50
|
break;
|
55
51
|
case GRPC_QUEUE_SHUTDOWN:
|
56
|
-
|
52
|
+
out.push_back("QUEUE_SHUTDOWN");
|
57
53
|
break;
|
58
54
|
case GRPC_OP_COMPLETE:
|
59
|
-
|
60
|
-
addhdr(
|
61
|
-
adderr(
|
55
|
+
out.push_back("OP_COMPLETE: ");
|
56
|
+
addhdr(ev, &out);
|
57
|
+
adderr(ev->success, &out);
|
62
58
|
break;
|
63
59
|
}
|
64
|
-
|
65
|
-
out = gpr_strvec_flatten(&buf, nullptr);
|
66
|
-
gpr_strvec_destroy(&buf);
|
67
|
-
return out;
|
60
|
+
return absl::StrJoin(out, "");
|
68
61
|
}
|
@@ -21,9 +21,11 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
+
#include <string>
|
25
|
+
|
24
26
|
#include <grpc/grpc.h>
|
25
27
|
|
26
28
|
/* Returns a string describing an event. Must be later freed with gpr_free() */
|
27
|
-
|
29
|
+
std::string grpc_event_string(grpc_event* ev);
|
28
30
|
|
29
31
|
#endif /* GRPC_CORE_LIB_SURFACE_EVENT_STRING_H */
|
@@ -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
|
@@ -78,7 +78,4 @@ void grpc_register_security_filters(void) {
|
|
78
78
|
maybe_prepend_server_auth_filter, nullptr);
|
79
79
|
}
|
80
80
|
|
81
|
-
void grpc_security_init() {
|
82
|
-
grpc_core::SecurityRegisterHandshakerFactories();
|
83
|
-
grpc_control_plane_credentials_init();
|
84
|
-
}
|
81
|
+
void grpc_security_init() { grpc_core::SecurityRegisterHandshakerFactories(); }
|
@@ -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
|
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,41 +55,61 @@
|
|
48
55
|
#include "src/core/lib/transport/metadata.h"
|
49
56
|
#include "src/core/lib/transport/static_metadata.h"
|
50
57
|
|
51
|
-
grpc_core
|
52
|
-
|
53
|
-
using grpc_core::LockedMultiProducerSingleConsumerQueue;
|
58
|
+
namespace grpc_core {
|
54
59
|
|
55
|
-
|
56
|
-
static void server_recv_trailing_metadata_ready(void* user_data,
|
57
|
-
grpc_error* error);
|
60
|
+
TraceFlag grpc_server_channel_trace(false, "server_channel");
|
58
61
|
|
59
62
|
namespace {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
|
64
|
+
void server_on_recv_initial_metadata(void* ptr, grpc_error* error);
|
65
|
+
void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error);
|
66
|
+
|
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
|
75
|
+
enum class RequestedCallType { BATCH_CALL, REGISTERED_CALL };
|
71
76
|
|
72
77
|
struct registered_method;
|
73
78
|
|
74
79
|
struct requested_call {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
requested_call(void* tag_arg, grpc_completion_queue* call_cq,
|
81
|
+
grpc_call** call_arg, grpc_metadata_array* initial_md,
|
82
|
+
grpc_call_details* details)
|
83
|
+
: type(RequestedCallType::BATCH_CALL),
|
84
|
+
tag(tag_arg),
|
85
|
+
cq_bound_to_call(call_cq),
|
86
|
+
call(call_arg),
|
87
|
+
initial_metadata(initial_md) {
|
88
|
+
details->reserved = nullptr;
|
89
|
+
data.batch.details = details;
|
90
|
+
}
|
91
|
+
|
92
|
+
requested_call(void* tag_arg, grpc_completion_queue* call_cq,
|
93
|
+
grpc_call** call_arg, grpc_metadata_array* initial_md,
|
94
|
+
registered_method* rm, gpr_timespec* deadline,
|
95
|
+
grpc_byte_buffer** optional_payload)
|
96
|
+
: type(RequestedCallType::REGISTERED_CALL),
|
97
|
+
tag(tag_arg),
|
98
|
+
cq_bound_to_call(call_cq),
|
99
|
+
call(call_arg),
|
100
|
+
initial_metadata(initial_md) {
|
101
|
+
data.registered.method = rm;
|
102
|
+
data.registered.deadline = deadline;
|
103
|
+
data.registered.optional_payload = optional_payload;
|
104
|
+
}
|
105
|
+
|
106
|
+
MultiProducerSingleConsumerQueue::Node mpscq_node;
|
107
|
+
const RequestedCallType type;
|
108
|
+
void* const tag;
|
109
|
+
grpc_completion_queue* const cq_bound_to_call;
|
110
|
+
grpc_call** const call;
|
84
111
|
grpc_cq_completion completion;
|
85
|
-
grpc_metadata_array* initial_metadata;
|
112
|
+
grpc_metadata_array* const initial_metadata;
|
86
113
|
union {
|
87
114
|
struct {
|
88
115
|
grpc_call_details* details;
|
@@ -96,34 +123,43 @@ struct requested_call {
|
|
96
123
|
};
|
97
124
|
|
98
125
|
struct channel_registered_method {
|
99
|
-
registered_method* server_registered_method;
|
126
|
+
registered_method* server_registered_method = nullptr;
|
100
127
|
uint32_t flags;
|
101
128
|
bool has_host;
|
102
|
-
|
103
|
-
|
129
|
+
ExternallyManagedSlice method;
|
130
|
+
ExternallyManagedSlice host;
|
104
131
|
};
|
105
132
|
|
106
133
|
struct channel_data {
|
107
|
-
|
134
|
+
channel_data() = default;
|
135
|
+
~channel_data();
|
136
|
+
|
137
|
+
grpc_server* server = nullptr;
|
108
138
|
grpc_channel* channel;
|
109
139
|
size_t cq_idx;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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;
|
115
147
|
uint32_t registered_method_max_probes;
|
148
|
+
|
116
149
|
grpc_closure finish_destroy_channel_closure;
|
117
150
|
intptr_t channelz_socket_uuid;
|
118
151
|
};
|
119
152
|
|
120
|
-
|
121
|
-
void*
|
122
|
-
|
153
|
+
struct shutdown_tag {
|
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;
|
123
159
|
grpc_cq_completion completion;
|
124
|
-
}
|
160
|
+
};
|
125
161
|
|
126
|
-
|
162
|
+
enum class CallState {
|
127
163
|
/* waiting for metadata */
|
128
164
|
NOT_STARTED,
|
129
165
|
/* initial metadata read, not flow controlled in yet */
|
@@ -132,23 +168,75 @@ typedef enum {
|
|
132
168
|
ACTIVATED,
|
133
169
|
/* cancelled before being queued */
|
134
170
|
ZOMBIED
|
135
|
-
}
|
171
|
+
};
|
136
172
|
|
137
|
-
|
173
|
+
struct call_data;
|
174
|
+
|
175
|
+
grpc_call_error ValidateServerRequest(
|
176
|
+
grpc_completion_queue* cq_for_notification, void* tag,
|
177
|
+
grpc_byte_buffer** optional_payload, registered_method* rm);
|
178
|
+
|
179
|
+
// RPCs that come in from the transport must be matched against RPC requests
|
180
|
+
// from the application. An incoming request from the application can be matched
|
181
|
+
// to an RPC that has already arrived or can be queued up for later use.
|
182
|
+
// Likewise, an RPC coming in from the transport can either be matched to a
|
183
|
+
// request that already arrived from the application or can be queued up for
|
184
|
+
// later use (marked pending). If there is a match, the request's tag is posted
|
185
|
+
// on the request's notification CQ.
|
186
|
+
//
|
187
|
+
// RequestMatcherInterface is the base class to provide this functionality.
|
188
|
+
class RequestMatcherInterface {
|
189
|
+
public:
|
190
|
+
virtual ~RequestMatcherInterface() {}
|
191
|
+
|
192
|
+
// Unref the calls associated with any incoming RPCs in the pending queue (not
|
193
|
+
// yet matched to an application-requested RPC).
|
194
|
+
virtual void ZombifyPending() = 0;
|
195
|
+
|
196
|
+
// Mark all application-requested RPCs failed if they have not been matched to
|
197
|
+
// an incoming RPC. The error parameter indicates why the RPCs are being
|
198
|
+
// failed (always server shutdown in all current implementations).
|
199
|
+
virtual void KillRequests(grpc_error* error) = 0;
|
200
|
+
|
201
|
+
// How many request queues are supported by this matcher. This is an abstract
|
202
|
+
// concept that essentially maps to gRPC completion queues.
|
203
|
+
virtual size_t request_queue_count() const = 0;
|
204
|
+
|
205
|
+
// This function is invoked when the application requests a new RPC whose
|
206
|
+
// information is in the call parameter. The request_queue_index marks the
|
207
|
+
// queue onto which to place this RPC, and is typically associated with a gRPC
|
208
|
+
// CQ. If there are pending RPCs waiting to be matched, publish one (match it
|
209
|
+
// and notify the CQ).
|
210
|
+
virtual void RequestCallWithPossiblePublish(size_t request_queue_index,
|
211
|
+
requested_call* call) = 0;
|
212
|
+
|
213
|
+
// This function is invoked on an incoming RPC, represented by the calld
|
214
|
+
// object. The RequestMatcher will try to match it against an
|
215
|
+
// application-requested RPC if possible or will place it in the pending queue
|
216
|
+
// otherwise. To enable some measure of fairness between server CQs, the match
|
217
|
+
// is done starting at the start_request_queue_index parameter in a cyclic
|
218
|
+
// order rather than always starting at 0.
|
219
|
+
virtual void MatchOrQueue(size_t start_request_queue_index,
|
220
|
+
call_data* calld) = 0;
|
221
|
+
|
222
|
+
// Returns the server associated with this request matcher
|
223
|
+
virtual grpc_server* server() const = 0;
|
224
|
+
};
|
138
225
|
|
139
226
|
struct call_data {
|
140
227
|
call_data(grpc_call_element* elem, const grpc_call_element_args& args)
|
141
228
|
: call(grpc_call_from_top_element(elem)),
|
142
229
|
call_combiner(args.call_combiner) {
|
143
|
-
GRPC_CLOSURE_INIT(&
|
144
|
-
|
230
|
+
GRPC_CLOSURE_INIT(&on_recv_initial_metadata,
|
231
|
+
server_on_recv_initial_metadata, elem,
|
145
232
|
grpc_schedule_on_exec_ctx);
|
146
233
|
GRPC_CLOSURE_INIT(&recv_trailing_metadata_ready,
|
147
234
|
server_recv_trailing_metadata_ready, elem,
|
148
235
|
grpc_schedule_on_exec_ctx);
|
149
236
|
}
|
150
237
|
~call_data() {
|
151
|
-
GPR_ASSERT(state !=
|
238
|
+
GPR_ASSERT(state.Load(grpc_core::MemoryOrder::RELAXED) !=
|
239
|
+
CallState::PENDING);
|
152
240
|
GRPC_ERROR_UNREF(recv_initial_metadata_error);
|
153
241
|
if (host_set) {
|
154
242
|
grpc_slice_unref_internal(host);
|
@@ -162,7 +250,7 @@ struct call_data {
|
|
162
250
|
|
163
251
|
grpc_call* call;
|
164
252
|
|
165
|
-
|
253
|
+
Atomic<CallState> state{CallState::NOT_STARTED};
|
166
254
|
|
167
255
|
bool path_set = false;
|
168
256
|
bool host_set = false;
|
@@ -177,11 +265,11 @@ struct call_data {
|
|
177
265
|
grpc_metadata_array initial_metadata =
|
178
266
|
grpc_metadata_array(); // Zero-initialize the C struct.
|
179
267
|
|
180
|
-
|
268
|
+
RequestMatcherInterface* matcher = nullptr;
|
181
269
|
grpc_byte_buffer* payload = nullptr;
|
182
270
|
|
183
271
|
grpc_closure got_initial_metadata;
|
184
|
-
grpc_closure
|
272
|
+
grpc_closure on_recv_initial_metadata;
|
185
273
|
grpc_closure kill_zombie_closure;
|
186
274
|
grpc_closure* on_done_recv_initial_metadata;
|
187
275
|
grpc_closure recv_trailing_metadata_ready;
|
@@ -192,43 +280,72 @@ struct call_data {
|
|
192
280
|
|
193
281
|
grpc_closure publish;
|
194
282
|
|
195
|
-
|
196
|
-
grpc_core::CallCombiner* call_combiner;
|
197
|
-
};
|
198
|
-
|
199
|
-
struct request_matcher {
|
200
|
-
grpc_server* server;
|
201
|
-
call_data* pending_head;
|
202
|
-
call_data* pending_tail;
|
203
|
-
LockedMultiProducerSingleConsumerQueue* requests_per_cq;
|
283
|
+
CallCombiner* call_combiner;
|
204
284
|
};
|
205
285
|
|
206
286
|
struct registered_method {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
287
|
+
registered_method(
|
288
|
+
const char* method_arg, const char* host_arg,
|
289
|
+
grpc_server_register_method_payload_handling payload_handling_arg,
|
290
|
+
uint32_t flags_arg)
|
291
|
+
: method(method_arg == nullptr ? "" : method_arg),
|
292
|
+
host(host_arg == nullptr ? "" : host_arg),
|
293
|
+
payload_handling(payload_handling_arg),
|
294
|
+
flags(flags_arg) {}
|
295
|
+
|
296
|
+
~registered_method() = default;
|
297
|
+
|
298
|
+
const std::string method;
|
299
|
+
const std::string host;
|
300
|
+
const grpc_server_register_method_payload_handling payload_handling;
|
301
|
+
const uint32_t flags;
|
211
302
|
/* one request matcher per method */
|
212
|
-
|
213
|
-
registered_method* next;
|
303
|
+
std::unique_ptr<RequestMatcherInterface> matcher;
|
214
304
|
};
|
215
305
|
|
216
|
-
typedef struct {
|
217
|
-
grpc_channel** channels;
|
218
|
-
size_t num_channels;
|
219
|
-
} channel_broadcaster;
|
220
306
|
} // namespace
|
307
|
+
} // namespace grpc_core
|
221
308
|
|
222
309
|
struct grpc_server {
|
223
|
-
grpc_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
|
+
}
|
224
324
|
|
225
|
-
|
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
|
+
}
|
226
334
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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;
|
232
349
|
|
233
350
|
/* The two following mutexes control access to server-state
|
234
351
|
mu_global controls access to non-call-related state (e.g., channel state)
|
@@ -237,27 +354,28 @@ struct grpc_server {
|
|
237
354
|
If they are ever required to be nested, you must lock mu_global
|
238
355
|
before mu_call. This is currently used in shutdown processing
|
239
356
|
(grpc_server_shutdown_and_notify and maybe_finish_shutdown) */
|
240
|
-
|
241
|
-
|
357
|
+
grpc_core::Mutex mu_global; // mutex for server and channel state
|
358
|
+
grpc_core::Mutex mu_call; // mutex for call-specific state
|
242
359
|
|
243
360
|
/* startup synchronization: flag is protected by mu_global, signals whether
|
244
361
|
we are doing the listener start routine or not */
|
245
|
-
bool starting;
|
246
|
-
|
362
|
+
bool starting = false;
|
363
|
+
grpc_core::CondVar starting_cv;
|
364
|
+
|
365
|
+
std::vector<std::unique_ptr<grpc_core::registered_method>> registered_methods;
|
247
366
|
|
248
|
-
|
249
|
-
|
250
|
-
|
367
|
+
// one request matcher for unregistered methods
|
368
|
+
std::unique_ptr<grpc_core::RequestMatcherInterface>
|
369
|
+
unregistered_request_matcher;
|
251
370
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
shutdown_tag* shutdown_tags;
|
371
|
+
std::atomic_bool shutdown_flag{false};
|
372
|
+
bool shutdown_published = false;
|
373
|
+
std::vector<grpc_core::shutdown_tag> shutdown_tags;
|
256
374
|
|
257
|
-
channel_data
|
375
|
+
std::list<grpc_core::channel_data*> channels;
|
258
376
|
|
259
|
-
|
260
|
-
|
377
|
+
std::list<grpc_core::Listener> listeners;
|
378
|
+
size_t listeners_destroyed = 0;
|
261
379
|
grpc_core::RefCount internal_refcount;
|
262
380
|
|
263
381
|
/** when did we print the last shutdown progress message */
|
@@ -266,53 +384,112 @@ struct grpc_server {
|
|
266
384
|
grpc_core::RefCountedPtr<grpc_core::channelz::ServerNode> channelz_server;
|
267
385
|
};
|
268
386
|
|
269
|
-
|
270
|
-
|
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
|
+
}
|
420
|
+
|
421
|
+
namespace grpc_core {
|
422
|
+
namespace {
|
271
423
|
|
272
|
-
|
273
|
-
|
274
|
-
|
424
|
+
void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
|
425
|
+
requested_call* rc);
|
426
|
+
void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
|
427
|
+
grpc_error* error);
|
275
428
|
/* Before calling maybe_finish_shutdown, we must hold mu_global and not
|
276
429
|
hold mu_call */
|
277
|
-
|
430
|
+
void maybe_finish_shutdown(grpc_server* server);
|
278
431
|
|
279
|
-
/*
|
280
|
-
|
281
|
-
|
432
|
+
void kill_zombie(void* elem, grpc_error* /*error*/) {
|
433
|
+
grpc_call_unref(
|
434
|
+
grpc_call_from_top_element(static_cast<grpc_call_element*>(elem)));
|
435
|
+
}
|
282
436
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
cb->channels = static_cast<grpc_channel**>(
|
292
|
-
gpr_malloc(sizeof(*cb->channels) * cb->num_channels));
|
293
|
-
count = 0;
|
294
|
-
for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
|
295
|
-
cb->channels[count++] = c->channel;
|
296
|
-
GRPC_CHANNEL_INTERNAL_REF(c->channel, "broadcast");
|
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;
|
297
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;
|
298
450
|
}
|
299
451
|
|
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;
|
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;
|
474
|
+
}
|
475
|
+
/*
|
476
|
+
* channel broadcaster
|
477
|
+
*/
|
478
|
+
|
300
479
|
struct shutdown_cleanup_args {
|
301
480
|
grpc_closure closure;
|
302
481
|
grpc_slice slice;
|
303
482
|
};
|
304
483
|
|
305
|
-
|
306
|
-
|
307
|
-
static_cast<struct shutdown_cleanup_args*>(arg);
|
484
|
+
void shutdown_cleanup(void* arg, grpc_error* /*error*/) {
|
485
|
+
shutdown_cleanup_args* a = static_cast<shutdown_cleanup_args*>(arg);
|
308
486
|
grpc_slice_unref_internal(a->slice);
|
309
|
-
|
487
|
+
delete a;
|
310
488
|
}
|
311
489
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
static_cast<struct shutdown_cleanup_args*>(gpr_malloc(sizeof(*sc)));
|
490
|
+
void send_shutdown(grpc_channel* channel, bool send_goaway,
|
491
|
+
grpc_error* send_disconnect) {
|
492
|
+
shutdown_cleanup_args* sc = new shutdown_cleanup_args;
|
316
493
|
GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc,
|
317
494
|
grpc_schedule_on_exec_ctx);
|
318
495
|
grpc_transport_op* op = grpc_make_transport_op(&sc->closure);
|
@@ -331,136 +508,308 @@ static void send_shutdown(grpc_channel* channel, bool send_goaway,
|
|
331
508
|
elem->filter->start_transport_op(elem, op);
|
332
509
|
}
|
333
510
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
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
|
+
}
|
338
525
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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);
|
343
534
|
}
|
344
|
-
|
345
|
-
|
346
|
-
|
535
|
+
|
536
|
+
private:
|
537
|
+
std::vector<grpc_channel*> channels_;
|
538
|
+
};
|
347
539
|
|
348
540
|
/*
|
349
541
|
* request_matcher
|
350
542
|
*/
|
351
543
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
544
|
+
// The RealRequestMatcher is an implementation of RequestMatcherInterface that
|
545
|
+
// actually uses all the features of RequestMatcherInterface: expecting the
|
546
|
+
// application to explicitly request RPCs and then matching those to incoming
|
547
|
+
// RPCs, along with a slow path by which incoming RPCs are put on a locked
|
548
|
+
// pending list if they aren't able to be matched to an application request.
|
549
|
+
class RealRequestMatcher : public RequestMatcherInterface {
|
550
|
+
public:
|
551
|
+
explicit RealRequestMatcher(grpc_server* server)
|
552
|
+
: server_(server), requests_per_cq_(server->cqs.size()) {}
|
553
|
+
|
554
|
+
~RealRequestMatcher() override {
|
555
|
+
for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) {
|
556
|
+
GPR_ASSERT(queue.Pop() == nullptr);
|
557
|
+
}
|
359
558
|
}
|
360
|
-
}
|
361
559
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
560
|
+
void ZombifyPending() override {
|
561
|
+
for (call_data* calld : pending_) {
|
562
|
+
calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
|
563
|
+
GRPC_CLOSURE_INIT(
|
564
|
+
&calld->kill_zombie_closure, kill_zombie,
|
565
|
+
grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
|
566
|
+
grpc_schedule_on_exec_ctx);
|
567
|
+
ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
|
568
|
+
GRPC_ERROR_NONE);
|
569
|
+
}
|
570
|
+
pending_.clear();
|
366
571
|
}
|
367
|
-
gpr_free(rm->requests_per_cq);
|
368
|
-
}
|
369
572
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
573
|
+
void KillRequests(grpc_error* error) override {
|
574
|
+
for (size_t i = 0; i < requests_per_cq_.size(); i++) {
|
575
|
+
requested_call* rc;
|
576
|
+
while ((rc = reinterpret_cast<requested_call*>(
|
577
|
+
requests_per_cq_[i].Pop())) != nullptr) {
|
578
|
+
fail_call(server_, i, rc, GRPC_ERROR_REF(error));
|
579
|
+
}
|
580
|
+
}
|
581
|
+
GRPC_ERROR_UNREF(error);
|
582
|
+
}
|
374
583
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
584
|
+
size_t request_queue_count() const override {
|
585
|
+
return requests_per_cq_.size();
|
586
|
+
}
|
587
|
+
|
588
|
+
void RequestCallWithPossiblePublish(size_t request_queue_index,
|
589
|
+
requested_call* call) override {
|
590
|
+
if (requests_per_cq_[request_queue_index].Push(&call->mpscq_node)) {
|
591
|
+
/* this was the first queued request: we need to lock and start
|
592
|
+
matching calls */
|
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)) {
|
620
|
+
// Zombied Call
|
621
|
+
GRPC_CLOSURE_INIT(
|
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),
|
625
|
+
grpc_schedule_on_exec_ctx);
|
626
|
+
ExecCtx::Run(DEBUG_LOCATION, &next_pending.calld->kill_zombie_closure,
|
627
|
+
GRPC_ERROR_NONE);
|
628
|
+
} else {
|
629
|
+
publish_call(server_, next_pending.calld, request_queue_index,
|
630
|
+
next_pending.rc);
|
631
|
+
}
|
632
|
+
}
|
633
|
+
}
|
386
634
|
}
|
387
|
-
}
|
388
635
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
636
|
+
void MatchOrQueue(size_t start_request_queue_index,
|
637
|
+
call_data* calld) override {
|
638
|
+
for (size_t i = 0; i < requests_per_cq_.size(); i++) {
|
639
|
+
size_t cq_idx = (start_request_queue_index + i) % requests_per_cq_.size();
|
640
|
+
requested_call* rc =
|
641
|
+
reinterpret_cast<requested_call*>(requests_per_cq_[cq_idx].TryPop());
|
642
|
+
if (rc == nullptr) {
|
643
|
+
continue;
|
644
|
+
} else {
|
645
|
+
GRPC_STATS_INC_SERVER_CQS_CHECKED(i);
|
646
|
+
calld->state.Store(CallState::ACTIVATED,
|
647
|
+
grpc_core::MemoryOrder::RELAXED);
|
648
|
+
publish_call(server_, calld, cq_idx, rc);
|
649
|
+
return; /* early out */
|
650
|
+
}
|
397
651
|
}
|
652
|
+
|
653
|
+
/* no cq to take the request found: queue it on the slow list */
|
654
|
+
GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED();
|
655
|
+
|
656
|
+
// We need to ensure that all the queues are empty. We do this under
|
657
|
+
// the server mu_call lock to ensure that if something is added to
|
658
|
+
// an empty request queue, it will block until the call is actually
|
659
|
+
// added to the pending list.
|
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
|
+
}
|
673
|
+
if (rc == nullptr) {
|
674
|
+
calld->state.Store(CallState::PENDING, grpc_core::MemoryOrder::RELAXED);
|
675
|
+
pending_.push_back(calld);
|
676
|
+
return;
|
677
|
+
}
|
678
|
+
}
|
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);
|
398
682
|
}
|
399
|
-
GRPC_ERROR_UNREF(error);
|
400
|
-
}
|
401
683
|
|
402
|
-
|
403
|
-
* server proper
|
404
|
-
*/
|
684
|
+
grpc_server* server() const override { return server_; }
|
405
685
|
|
406
|
-
|
686
|
+
private:
|
687
|
+
grpc_server* const server_;
|
688
|
+
std::list<call_data*> pending_;
|
689
|
+
std::vector<LockedMultiProducerSingleConsumerQueue> requests_per_cq_;
|
690
|
+
};
|
407
691
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
692
|
+
// AllocatingRequestMatchers don't allow the application to request an RPC in
|
693
|
+
// advance or queue up any incoming RPC for later match. Instead, MatchOrQueue
|
694
|
+
// will call out to an allocation function passed in at the construction of the
|
695
|
+
// object. These request matchers are designed for the C++ callback API, so they
|
696
|
+
// only support 1 completion queue (passed in at the constructor).
|
697
|
+
class AllocatingRequestMatcherBase : public RequestMatcherInterface {
|
698
|
+
public:
|
699
|
+
AllocatingRequestMatcherBase(grpc_server* server, grpc_completion_queue* cq)
|
700
|
+
: server_(server), cq_(cq) {
|
701
|
+
size_t idx;
|
702
|
+
for (idx = 0; idx < server->cqs.size(); idx++) {
|
703
|
+
if (server->cqs[idx] == cq) {
|
704
|
+
break;
|
705
|
+
}
|
420
706
|
}
|
421
|
-
|
422
|
-
|
423
|
-
gpr_free(rm);
|
707
|
+
GPR_ASSERT(idx < server->cqs.size());
|
708
|
+
cq_idx_ = idx;
|
424
709
|
}
|
425
|
-
|
426
|
-
|
710
|
+
|
711
|
+
void ZombifyPending() override {}
|
712
|
+
|
713
|
+
void KillRequests(grpc_error* error) override { GRPC_ERROR_UNREF(error); }
|
714
|
+
|
715
|
+
size_t request_queue_count() const override { return 0; }
|
716
|
+
|
717
|
+
void RequestCallWithPossiblePublish(size_t /*request_queue_index*/,
|
718
|
+
requested_call* /*call*/) final {
|
719
|
+
GPR_ASSERT(false);
|
427
720
|
}
|
428
|
-
|
429
|
-
|
721
|
+
|
722
|
+
grpc_server* server() const override { return server_; }
|
723
|
+
|
724
|
+
// Supply the completion queue related to this request matcher
|
725
|
+
grpc_completion_queue* cq() const { return cq_; }
|
726
|
+
|
727
|
+
// Supply the completion queue's index relative to the server.
|
728
|
+
size_t cq_idx() const { return cq_idx_; }
|
729
|
+
|
730
|
+
private:
|
731
|
+
grpc_server* const server_;
|
732
|
+
grpc_completion_queue* const cq_;
|
733
|
+
size_t cq_idx_;
|
734
|
+
};
|
735
|
+
|
736
|
+
// An allocating request matcher for non-registered methods (used for generic
|
737
|
+
// API and unimplemented RPCs).
|
738
|
+
class AllocatingRequestMatcherBatch : public AllocatingRequestMatcherBase {
|
739
|
+
public:
|
740
|
+
AllocatingRequestMatcherBatch(
|
741
|
+
grpc_server* server, grpc_completion_queue* cq,
|
742
|
+
std::function<ServerBatchCallAllocation()> allocator)
|
743
|
+
: AllocatingRequestMatcherBase(server, cq),
|
744
|
+
allocator_(std::move(allocator)) {}
|
745
|
+
void MatchOrQueue(size_t /*start_request_queue_index*/,
|
746
|
+
call_data* calld) override {
|
747
|
+
ServerBatchCallAllocation call_info = allocator_();
|
748
|
+
GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
|
749
|
+
nullptr, nullptr) == GRPC_CALL_OK);
|
750
|
+
requested_call* rc = new requested_call(
|
751
|
+
static_cast<void*>(call_info.tag), cq(), call_info.call,
|
752
|
+
call_info.initial_metadata, call_info.details);
|
753
|
+
calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
|
754
|
+
publish_call(server(), calld, cq_idx(), rc);
|
430
755
|
}
|
431
|
-
gpr_free(server->cqs);
|
432
|
-
gpr_free(server->pollsets);
|
433
|
-
gpr_free(server->shutdown_tags);
|
434
|
-
gpr_free(server);
|
435
|
-
}
|
436
756
|
|
437
|
-
|
438
|
-
|
439
|
-
|
757
|
+
private:
|
758
|
+
std::function<ServerBatchCallAllocation()> allocator_;
|
759
|
+
};
|
760
|
+
|
761
|
+
// An allocating request matcher for registered methods.
|
762
|
+
class AllocatingRequestMatcherRegistered : public AllocatingRequestMatcherBase {
|
763
|
+
public:
|
764
|
+
AllocatingRequestMatcherRegistered(
|
765
|
+
grpc_server* server, grpc_completion_queue* cq, registered_method* rm,
|
766
|
+
std::function<ServerRegisteredCallAllocation()> allocator)
|
767
|
+
: AllocatingRequestMatcherBase(server, cq),
|
768
|
+
registered_method_(rm),
|
769
|
+
allocator_(std::move(allocator)) {}
|
770
|
+
void MatchOrQueue(size_t /*start_request_queue_index*/,
|
771
|
+
call_data* calld) override {
|
772
|
+
ServerRegisteredCallAllocation call_info = allocator_();
|
773
|
+
GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
|
774
|
+
call_info.optional_payload,
|
775
|
+
registered_method_) == GRPC_CALL_OK);
|
776
|
+
requested_call* rc = new requested_call(
|
777
|
+
static_cast<void*>(call_info.tag), cq(), call_info.call,
|
778
|
+
call_info.initial_metadata, registered_method_, call_info.deadline,
|
779
|
+
call_info.optional_payload);
|
780
|
+
calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
|
781
|
+
publish_call(server(), calld, cq_idx(), rc);
|
440
782
|
}
|
441
|
-
}
|
442
783
|
|
443
|
-
|
444
|
-
|
445
|
-
|
784
|
+
private:
|
785
|
+
registered_method* const registered_method_;
|
786
|
+
std::function<ServerRegisteredCallAllocation()> allocator_;
|
787
|
+
};
|
788
|
+
|
789
|
+
/*
|
790
|
+
* server proper
|
791
|
+
*/
|
792
|
+
|
793
|
+
void server_ref(grpc_server* server) { server->internal_refcount.Ref(); }
|
446
794
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
795
|
+
void server_unref(grpc_server* server) {
|
796
|
+
if (GPR_UNLIKELY(server->internal_refcount.Unref())) {
|
797
|
+
delete server;
|
798
|
+
}
|
451
799
|
}
|
452
800
|
|
453
|
-
|
801
|
+
void finish_destroy_channel(void* cd, grpc_error* /*error*/) {
|
454
802
|
channel_data* chand = static_cast<channel_data*>(cd);
|
455
803
|
grpc_server* server = chand->server;
|
456
804
|
GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server");
|
457
805
|
server_unref(server);
|
458
806
|
}
|
459
807
|
|
460
|
-
|
461
|
-
if (
|
808
|
+
void destroy_channel(channel_data* chand) {
|
809
|
+
if (!chand->list_position.has_value()) return;
|
462
810
|
GPR_ASSERT(chand->server != nullptr);
|
463
|
-
|
811
|
+
chand->server->channels.erase(*chand->list_position);
|
812
|
+
chand->list_position.reset();
|
464
813
|
server_ref(chand->server);
|
465
814
|
maybe_finish_shutdown(chand->server);
|
466
815
|
GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure,
|
@@ -478,19 +827,19 @@ static void destroy_channel(channel_data* chand) {
|
|
478
827
|
op);
|
479
828
|
}
|
480
829
|
|
481
|
-
|
482
|
-
|
830
|
+
void done_request_event(void* req, grpc_cq_completion* /*c*/) {
|
831
|
+
delete static_cast<requested_call*>(req);
|
483
832
|
}
|
484
833
|
|
485
|
-
|
486
|
-
|
834
|
+
void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
|
835
|
+
requested_call* rc) {
|
487
836
|
grpc_call_set_completion_queue(calld->call, rc->cq_bound_to_call);
|
488
837
|
grpc_call* call = calld->call;
|
489
838
|
*rc->call = call;
|
490
839
|
calld->cq_new = server->cqs[cq_idx];
|
491
840
|
GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata);
|
492
841
|
switch (rc->type) {
|
493
|
-
case BATCH_CALL:
|
842
|
+
case RequestedCallType::BATCH_CALL:
|
494
843
|
GPR_ASSERT(calld->host_set);
|
495
844
|
GPR_ASSERT(calld->path_set);
|
496
845
|
rc->data.batch.details->host = grpc_slice_ref_internal(calld->host);
|
@@ -499,7 +848,7 @@ static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
|
|
499
848
|
grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
|
500
849
|
rc->data.batch.details->flags = calld->recv_initial_metadata_flags;
|
501
850
|
break;
|
502
|
-
case REGISTERED_CALL:
|
851
|
+
case RequestedCallType::REGISTERED_CALL:
|
503
852
|
*rc->data.registered.deadline =
|
504
853
|
grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
|
505
854
|
if (rc->data.registered.optional_payload) {
|
@@ -515,83 +864,38 @@ static void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
|
|
515
864
|
rc, &rc->completion, true);
|
516
865
|
}
|
517
866
|
|
518
|
-
|
867
|
+
void publish_new_rpc(void* arg, grpc_error* error) {
|
519
868
|
grpc_call_element* call_elem = static_cast<grpc_call_element*>(arg);
|
520
869
|
call_data* calld = static_cast<call_data*>(call_elem->call_data);
|
521
870
|
channel_data* chand = static_cast<channel_data*>(call_elem->channel_data);
|
522
|
-
|
523
|
-
grpc_server* server = rm->server;
|
871
|
+
RequestMatcherInterface* rm = calld->matcher;
|
872
|
+
grpc_server* server = rm->server();
|
524
873
|
|
525
|
-
if (error != GRPC_ERROR_NONE ||
|
526
|
-
|
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);
|
527
877
|
GRPC_CLOSURE_INIT(
|
528
878
|
&calld->kill_zombie_closure, kill_zombie,
|
529
879
|
grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
|
530
880
|
grpc_schedule_on_exec_ctx);
|
531
|
-
|
532
|
-
|
881
|
+
ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
|
882
|
+
GRPC_ERROR_REF(error));
|
533
883
|
return;
|
534
884
|
}
|
535
885
|
|
536
|
-
|
537
|
-
size_t cq_idx = (chand->cq_idx + i) % server->cq_count;
|
538
|
-
requested_call* rc =
|
539
|
-
reinterpret_cast<requested_call*>(rm->requests_per_cq[cq_idx].TryPop());
|
540
|
-
if (rc == nullptr) {
|
541
|
-
continue;
|
542
|
-
} else {
|
543
|
-
GRPC_STATS_INC_SERVER_CQS_CHECKED(i);
|
544
|
-
gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
|
545
|
-
publish_call(server, calld, cq_idx, rc);
|
546
|
-
return; /* early out */
|
547
|
-
}
|
548
|
-
}
|
549
|
-
|
550
|
-
/* no cq to take the request found: queue it on the slow list */
|
551
|
-
GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED();
|
552
|
-
gpr_mu_lock(&server->mu_call);
|
553
|
-
|
554
|
-
// We need to ensure that all the queues are empty. We do this under
|
555
|
-
// the server mu_call lock to ensure that if something is added to
|
556
|
-
// an empty request queue, it will block until the call is actually
|
557
|
-
// added to the pending list.
|
558
|
-
for (size_t i = 0; i < server->cq_count; i++) {
|
559
|
-
size_t cq_idx = (chand->cq_idx + i) % server->cq_count;
|
560
|
-
requested_call* rc =
|
561
|
-
reinterpret_cast<requested_call*>(rm->requests_per_cq[cq_idx].Pop());
|
562
|
-
if (rc == nullptr) {
|
563
|
-
continue;
|
564
|
-
} else {
|
565
|
-
gpr_mu_unlock(&server->mu_call);
|
566
|
-
GRPC_STATS_INC_SERVER_CQS_CHECKED(i + server->cq_count);
|
567
|
-
gpr_atm_no_barrier_store(&calld->state, ACTIVATED);
|
568
|
-
publish_call(server, calld, cq_idx, rc);
|
569
|
-
return; /* early out */
|
570
|
-
}
|
571
|
-
}
|
572
|
-
|
573
|
-
gpr_atm_no_barrier_store(&calld->state, PENDING);
|
574
|
-
if (rm->pending_head == nullptr) {
|
575
|
-
rm->pending_tail = rm->pending_head = calld;
|
576
|
-
} else {
|
577
|
-
rm->pending_tail->pending_next = calld;
|
578
|
-
rm->pending_tail = calld;
|
579
|
-
}
|
580
|
-
calld->pending_next = nullptr;
|
581
|
-
gpr_mu_unlock(&server->mu_call);
|
886
|
+
rm->MatchOrQueue(chand->cq_idx, calld);
|
582
887
|
}
|
583
888
|
|
584
|
-
|
585
|
-
grpc_server* server, grpc_call_element* elem,
|
889
|
+
void finish_start_new_rpc(
|
890
|
+
grpc_server* server, grpc_call_element* elem, RequestMatcherInterface* rm,
|
586
891
|
grpc_server_register_method_payload_handling payload_handling) {
|
587
892
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
588
893
|
|
589
|
-
if (
|
590
|
-
|
894
|
+
if (server->shutdown_flag.load(std::memory_order_acquire)) {
|
895
|
+
calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
|
591
896
|
GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
|
592
897
|
grpc_schedule_on_exec_ctx);
|
593
|
-
|
594
|
-
GRPC_ERROR_NONE);
|
898
|
+
ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure, GRPC_ERROR_NONE);
|
595
899
|
return;
|
596
900
|
}
|
597
901
|
|
@@ -615,7 +919,7 @@ static void finish_start_new_rpc(
|
|
615
919
|
}
|
616
920
|
}
|
617
921
|
|
618
|
-
|
922
|
+
void start_new_rpc(grpc_call_element* elem) {
|
619
923
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
|
620
924
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
621
925
|
grpc_server* server = chand->server;
|
@@ -629,8 +933,8 @@ static void start_new_rpc(grpc_call_element* elem) {
|
|
629
933
|
hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash_internal(calld->host),
|
630
934
|
grpc_slice_hash_internal(calld->path));
|
631
935
|
for (i = 0; i <= chand->registered_method_max_probes; i++) {
|
632
|
-
rm = &chand->registered_methods[(hash + i) %
|
633
|
-
|
936
|
+
rm = &(*chand->registered_methods)[(hash + i) %
|
937
|
+
chand->registered_methods->size()];
|
634
938
|
if (rm->server_registered_method == nullptr) break;
|
635
939
|
if (!rm->has_host) continue;
|
636
940
|
if (rm->host != calld->host) continue;
|
@@ -640,15 +944,16 @@ static void start_new_rpc(grpc_call_element* elem) {
|
|
640
944
|
GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) {
|
641
945
|
continue;
|
642
946
|
}
|
643
|
-
finish_start_new_rpc(server, elem,
|
947
|
+
finish_start_new_rpc(server, elem,
|
948
|
+
rm->server_registered_method->matcher.get(),
|
644
949
|
rm->server_registered_method->payload_handling);
|
645
950
|
return;
|
646
951
|
}
|
647
952
|
/* check for a wildcard method definition (no host set) */
|
648
953
|
hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash_internal(calld->path));
|
649
954
|
for (i = 0; i <= chand->registered_method_max_probes; i++) {
|
650
|
-
rm = &chand->registered_methods[(hash + i) %
|
651
|
-
|
955
|
+
rm = &(*chand->registered_methods)[(hash + i) %
|
956
|
+
chand->registered_methods->size()];
|
652
957
|
if (rm->server_registered_method == nullptr) break;
|
653
958
|
if (rm->has_host) continue;
|
654
959
|
if (rm->method != calld->path) continue;
|
@@ -657,83 +962,64 @@ static void start_new_rpc(grpc_call_element* elem) {
|
|
657
962
|
GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) {
|
658
963
|
continue;
|
659
964
|
}
|
660
|
-
finish_start_new_rpc(server, elem,
|
965
|
+
finish_start_new_rpc(server, elem,
|
966
|
+
rm->server_registered_method->matcher.get(),
|
661
967
|
rm->server_registered_method->payload_handling);
|
662
968
|
return;
|
663
969
|
}
|
664
970
|
}
|
665
|
-
finish_start_new_rpc(server, elem,
|
971
|
+
finish_start_new_rpc(server, elem, server->unregistered_request_matcher.get(),
|
666
972
|
GRPC_SRM_PAYLOAD_NONE);
|
667
973
|
}
|
668
974
|
|
669
|
-
|
670
|
-
listener* l;
|
671
|
-
int n = 0;
|
672
|
-
for (l = server->listeners; l; l = l->next) {
|
673
|
-
n++;
|
674
|
-
}
|
675
|
-
return n;
|
676
|
-
}
|
677
|
-
|
678
|
-
static void done_shutdown_event(void* server,
|
679
|
-
grpc_cq_completion* /*completion*/) {
|
975
|
+
void done_shutdown_event(void* server, grpc_cq_completion* /*completion*/) {
|
680
976
|
server_unref(static_cast<grpc_server*>(server));
|
681
977
|
}
|
682
978
|
|
683
|
-
|
684
|
-
channel_data* chand;
|
685
|
-
int n = 0;
|
686
|
-
for (chand = server->root_channel_data.next;
|
687
|
-
chand != &server->root_channel_data; chand = chand->next) {
|
688
|
-
n++;
|
689
|
-
}
|
690
|
-
return n;
|
691
|
-
}
|
979
|
+
int num_channels(grpc_server* server) { return server->channels.size(); }
|
692
980
|
|
693
|
-
|
981
|
+
void kill_pending_work_locked(grpc_server* server, grpc_error* error) {
|
694
982
|
if (server->started) {
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
rm = rm->next) {
|
701
|
-
request_matcher_kill_requests(server, &rm->matcher,
|
702
|
-
GRPC_ERROR_REF(error));
|
703
|
-
request_matcher_zombify_all_pending_calls(&rm->matcher);
|
983
|
+
server->unregistered_request_matcher->KillRequests(GRPC_ERROR_REF(error));
|
984
|
+
server->unregistered_request_matcher->ZombifyPending();
|
985
|
+
for (std::unique_ptr<registered_method>& rm : server->registered_methods) {
|
986
|
+
rm->matcher->KillRequests(GRPC_ERROR_REF(error));
|
987
|
+
rm->matcher->ZombifyPending();
|
704
988
|
}
|
705
989
|
}
|
706
990
|
GRPC_ERROR_UNREF(error);
|
707
991
|
}
|
708
992
|
|
709
|
-
|
993
|
+
void maybe_finish_shutdown(grpc_server* server) {
|
710
994
|
size_t i;
|
711
|
-
if (!
|
995
|
+
if (!server->shutdown_flag.load(std::memory_order_acquire) ||
|
996
|
+
server->shutdown_published) {
|
712
997
|
return;
|
713
998
|
}
|
714
999
|
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
1000
|
+
{
|
1001
|
+
MutexLock lock(&server->mu_call);
|
1002
|
+
kill_pending_work_locked(
|
1003
|
+
server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
|
1004
|
+
}
|
719
1005
|
|
720
|
-
if (server->
|
721
|
-
server->listeners_destroyed <
|
1006
|
+
if (!server->channels.empty() ||
|
1007
|
+
server->listeners_destroyed < server->listeners.size()) {
|
722
1008
|
if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
|
723
1009
|
server->last_shutdown_message_time),
|
724
1010
|
gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
|
725
1011
|
server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
|
726
1012
|
gpr_log(GPR_DEBUG,
|
727
|
-
"Waiting for %d channels and %
|
728
|
-
" before shutting down server",
|
1013
|
+
"Waiting for %d channels and %" PRIuPTR "/%" PRIuPTR
|
1014
|
+
" listeners to be destroyed before shutting down server",
|
729
1015
|
num_channels(server),
|
730
|
-
|
731
|
-
|
1016
|
+
server->listeners.size() - server->listeners_destroyed,
|
1017
|
+
server->listeners.size());
|
732
1018
|
}
|
733
1019
|
return;
|
734
1020
|
}
|
735
1021
|
server->shutdown_published = 1;
|
736
|
-
for (i = 0; i < server->
|
1022
|
+
for (i = 0; i < server->shutdown_tags.size(); i++) {
|
737
1023
|
server_ref(server);
|
738
1024
|
grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag,
|
739
1025
|
GRPC_ERROR_NONE, done_shutdown_event, server,
|
@@ -741,7 +1027,7 @@ static void maybe_finish_shutdown(grpc_server* server) {
|
|
741
1027
|
}
|
742
1028
|
}
|
743
1029
|
|
744
|
-
|
1030
|
+
void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
|
745
1031
|
grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
|
746
1032
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
747
1033
|
grpc_millis op_deadline;
|
@@ -784,11 +1070,10 @@ static void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
|
|
784
1070
|
calld->recv_trailing_metadata_error,
|
785
1071
|
"continue server_recv_trailing_metadata_ready");
|
786
1072
|
}
|
787
|
-
|
1073
|
+
Closure::Run(DEBUG_LOCATION, closure, error);
|
788
1074
|
}
|
789
1075
|
|
790
|
-
|
791
|
-
grpc_error* error) {
|
1076
|
+
void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error) {
|
792
1077
|
grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
|
793
1078
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
794
1079
|
if (calld->on_done_recv_initial_metadata != nullptr) {
|
@@ -805,12 +1090,12 @@ static void server_recv_trailing_metadata_ready(void* user_data,
|
|
805
1090
|
error =
|
806
1091
|
grpc_error_add_child(GRPC_ERROR_REF(error),
|
807
1092
|
GRPC_ERROR_REF(calld->recv_initial_metadata_error));
|
808
|
-
|
809
|
-
|
1093
|
+
Closure::Run(DEBUG_LOCATION, calld->original_recv_trailing_metadata_ready,
|
1094
|
+
error);
|
810
1095
|
}
|
811
1096
|
|
812
|
-
|
813
|
-
|
1097
|
+
void server_mutate_op(grpc_call_element* elem,
|
1098
|
+
grpc_transport_stream_op_batch* op) {
|
814
1099
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
815
1100
|
|
816
1101
|
if (op->recv_initial_metadata) {
|
@@ -820,7 +1105,7 @@ static void server_mutate_op(grpc_call_element* elem,
|
|
820
1105
|
calld->on_done_recv_initial_metadata =
|
821
1106
|
op->payload->recv_initial_metadata.recv_initial_metadata_ready;
|
822
1107
|
op->payload->recv_initial_metadata.recv_initial_metadata_ready =
|
823
|
-
&calld->
|
1108
|
+
&calld->on_recv_initial_metadata;
|
824
1109
|
op->payload->recv_initial_metadata.recv_flags =
|
825
1110
|
&calld->recv_initial_metadata_flags;
|
826
1111
|
}
|
@@ -832,32 +1117,39 @@ static void server_mutate_op(grpc_call_element* elem,
|
|
832
1117
|
}
|
833
1118
|
}
|
834
1119
|
|
835
|
-
|
1120
|
+
void server_start_transport_stream_op_batch(
|
836
1121
|
grpc_call_element* elem, grpc_transport_stream_op_batch* op) {
|
837
1122
|
server_mutate_op(elem, op);
|
838
1123
|
grpc_call_next_op(elem, op);
|
839
1124
|
}
|
840
1125
|
|
841
|
-
|
1126
|
+
void got_initial_metadata(void* ptr, grpc_error* error) {
|
842
1127
|
grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
|
843
1128
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
844
1129
|
if (error == GRPC_ERROR_NONE) {
|
845
1130
|
start_new_rpc(elem);
|
846
1131
|
} else {
|
847
|
-
|
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)) {
|
848
1137
|
GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
|
849
1138
|
grpc_schedule_on_exec_ctx);
|
850
|
-
|
851
|
-
|
852
|
-
} else if (
|
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)) {
|
853
1145
|
/* zombied call will be destroyed when it's removed from the pending
|
854
1146
|
queue... later */
|
855
1147
|
}
|
856
1148
|
}
|
857
1149
|
}
|
858
1150
|
|
859
|
-
|
860
|
-
|
1151
|
+
void accept_stream(void* cd, grpc_transport* /*transport*/,
|
1152
|
+
const void* transport_server_data) {
|
861
1153
|
channel_data* chand = static_cast<channel_data*>(cd);
|
862
1154
|
/* create a call */
|
863
1155
|
grpc_call_create_args args;
|
@@ -892,99 +1184,183 @@ static void accept_stream(void* cd, grpc_transport* /*transport*/,
|
|
892
1184
|
grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata);
|
893
1185
|
}
|
894
1186
|
|
895
|
-
|
896
|
-
|
1187
|
+
grpc_error* server_init_call_elem(grpc_call_element* elem,
|
1188
|
+
const grpc_call_element_args* args) {
|
897
1189
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
|
898
1190
|
server_ref(chand->server);
|
899
1191
|
new (elem->call_data) call_data(elem, *args);
|
900
1192
|
return GRPC_ERROR_NONE;
|
901
1193
|
}
|
902
1194
|
|
903
|
-
|
904
|
-
|
905
|
-
|
1195
|
+
void server_destroy_call_elem(grpc_call_element* elem,
|
1196
|
+
const grpc_call_final_info* /*final_info*/,
|
1197
|
+
grpc_closure* /*ignored*/) {
|
906
1198
|
call_data* calld = static_cast<call_data*>(elem->call_data);
|
907
1199
|
calld->~call_data();
|
908
1200
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
|
909
1201
|
server_unref(chand->server);
|
910
1202
|
}
|
911
1203
|
|
912
|
-
|
913
|
-
|
914
|
-
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
|
1204
|
+
grpc_error* server_init_channel_elem(grpc_channel_element* elem,
|
1205
|
+
grpc_channel_element_args* args) {
|
915
1206
|
GPR_ASSERT(args->is_first);
|
916
1207
|
GPR_ASSERT(!args->is_last);
|
917
|
-
|
918
|
-
|
919
|
-
chand->next = chand->prev = chand;
|
920
|
-
chand->registered_methods = nullptr;
|
1208
|
+
|
1209
|
+
new (static_cast<channel_data*>(elem->channel_data)) channel_data;
|
921
1210
|
return GRPC_ERROR_NONE;
|
922
1211
|
}
|
923
1212
|
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
grpc_slice_unref_internal(chand->registered_methods[i].host);
|
935
|
-
GPR_DEBUG_ASSERT(chand->registered_methods[i].host.refcount ==
|
936
|
-
&grpc_core::kNoopRefcount ||
|
937
|
-
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);
|
938
1223
|
}
|
939
1224
|
}
|
940
|
-
gpr_free(chand->registered_methods);
|
941
1225
|
}
|
942
|
-
if (
|
943
|
-
if (
|
944
|
-
|
945
|
-
|
946
|
-
|
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);
|
947
1236
|
}
|
948
|
-
|
949
|
-
chand->next->prev = chand->prev;
|
950
|
-
chand->prev->next = chand->next;
|
951
|
-
chand->next = chand->prev = chand;
|
952
|
-
maybe_finish_shutdown(chand->server);
|
953
|
-
gpr_mu_unlock(&chand->server->mu_global);
|
954
|
-
server_unref(chand->server);
|
1237
|
+
server_unref(server);
|
955
1238
|
}
|
956
1239
|
}
|
957
1240
|
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
server_init_call_elem,
|
963
|
-
grpc_call_stack_ignore_set_pollset_or_pollset_set,
|
964
|
-
server_destroy_call_elem,
|
965
|
-
sizeof(channel_data),
|
966
|
-
server_init_channel_elem,
|
967
|
-
server_destroy_channel_elem,
|
968
|
-
grpc_channel_next_get_info,
|
969
|
-
"server",
|
970
|
-
};
|
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
|
+
}
|
971
1245
|
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
size_t i, n;
|
1246
|
+
void register_completion_queue(grpc_server* server, grpc_completion_queue* cq,
|
1247
|
+
void* reserved) {
|
1248
|
+
size_t i;
|
976
1249
|
GPR_ASSERT(!reserved);
|
977
|
-
for (i = 0; i < server->
|
1250
|
+
for (i = 0; i < server->cqs.size(); i++) {
|
978
1251
|
if (server->cqs[i] == cq) return;
|
979
1252
|
}
|
980
1253
|
|
981
1254
|
GRPC_CQ_INTERNAL_REF(cq, "server");
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
1255
|
+
server->cqs.push_back(cq);
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
bool streq(const std::string& a, const char* b) {
|
1259
|
+
return (a.empty() && b == nullptr) ||
|
1260
|
+
((b != nullptr) && !strcmp(a.c_str(), b));
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface {
|
1264
|
+
public:
|
1265
|
+
explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) {
|
1266
|
+
GRPC_CHANNEL_INTERNAL_REF(chand_->channel, "connectivity");
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
~ConnectivityWatcher() {
|
1270
|
+
GRPC_CHANNEL_INTERNAL_UNREF(chand_->channel, "connectivity");
|
1271
|
+
}
|
1272
|
+
|
1273
|
+
private:
|
1274
|
+
void OnConnectivityStateChange(grpc_connectivity_state new_state) override {
|
1275
|
+
// Don't do anything until we are being shut down.
|
1276
|
+
if (new_state != GRPC_CHANNEL_SHUTDOWN) return;
|
1277
|
+
// Shut down channel.
|
1278
|
+
grpc_server* server = chand_->server;
|
1279
|
+
MutexLock lock(&server->mu_global);
|
1280
|
+
destroy_channel(chand_);
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
channel_data* chand_;
|
1284
|
+
};
|
1285
|
+
|
1286
|
+
void done_published_shutdown(void* /*done_arg*/, grpc_cq_completion* storage) {
|
1287
|
+
delete storage;
|
986
1288
|
}
|
987
1289
|
|
1290
|
+
void listener_destroy_done(void* s, grpc_error* /*error*/) {
|
1291
|
+
grpc_server* server = static_cast<grpc_server*>(s);
|
1292
|
+
MutexLock lock(&server->mu_global);
|
1293
|
+
server->listeners_destroyed++;
|
1294
|
+
maybe_finish_shutdown(server);
|
1295
|
+
}
|
1296
|
+
|
1297
|
+
grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx,
|
1298
|
+
requested_call* rc) {
|
1299
|
+
if (server->shutdown_flag.load(std::memory_order_acquire)) {
|
1300
|
+
fail_call(server, cq_idx, rc,
|
1301
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
|
1302
|
+
return GRPC_CALL_OK;
|
1303
|
+
}
|
1304
|
+
RequestMatcherInterface* rm;
|
1305
|
+
switch (rc->type) {
|
1306
|
+
case RequestedCallType::BATCH_CALL:
|
1307
|
+
rm = server->unregistered_request_matcher.get();
|
1308
|
+
break;
|
1309
|
+
case RequestedCallType::REGISTERED_CALL:
|
1310
|
+
rm = rc->data.registered.method->matcher.get();
|
1311
|
+
break;
|
1312
|
+
}
|
1313
|
+
rm->RequestCallWithPossiblePublish(cq_idx, rc);
|
1314
|
+
return GRPC_CALL_OK;
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
|
1318
|
+
grpc_error* error) {
|
1319
|
+
*rc->call = nullptr;
|
1320
|
+
rc->initial_metadata->count = 0;
|
1321
|
+
GPR_ASSERT(error != GRPC_ERROR_NONE);
|
1322
|
+
|
1323
|
+
grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc,
|
1324
|
+
&rc->completion);
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
} // namespace
|
1328
|
+
|
1329
|
+
void SetServerRegisteredMethodAllocator(
|
1330
|
+
grpc_server* server, grpc_completion_queue* cq, void* method_tag,
|
1331
|
+
std::function<ServerRegisteredCallAllocation()> allocator) {
|
1332
|
+
registered_method* rm = static_cast<registered_method*>(method_tag);
|
1333
|
+
rm->matcher = absl::make_unique<AllocatingRequestMatcherRegistered>(
|
1334
|
+
server, cq, rm, std::move(allocator));
|
1335
|
+
}
|
1336
|
+
|
1337
|
+
void SetServerBatchMethodAllocator(
|
1338
|
+
grpc_server* server, grpc_completion_queue* cq,
|
1339
|
+
std::function<ServerBatchCallAllocation()> allocator) {
|
1340
|
+
GPR_DEBUG_ASSERT(server->unregistered_request_matcher == nullptr);
|
1341
|
+
server->unregistered_request_matcher =
|
1342
|
+
absl::make_unique<AllocatingRequestMatcherBatch>(server, cq,
|
1343
|
+
std::move(allocator));
|
1344
|
+
}
|
1345
|
+
|
1346
|
+
} // namespace grpc_core
|
1347
|
+
|
1348
|
+
const grpc_channel_filter grpc_server_top_filter = {
|
1349
|
+
grpc_core::server_start_transport_stream_op_batch,
|
1350
|
+
grpc_channel_next_op,
|
1351
|
+
sizeof(grpc_core::call_data),
|
1352
|
+
grpc_core::server_init_call_elem,
|
1353
|
+
grpc_call_stack_ignore_set_pollset_or_pollset_set,
|
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,
|
1358
|
+
grpc_channel_next_get_info,
|
1359
|
+
"server",
|
1360
|
+
};
|
1361
|
+
|
1362
|
+
// The following are core surface API functions.
|
1363
|
+
|
988
1364
|
void grpc_server_register_completion_queue(grpc_server* server,
|
989
1365
|
grpc_completion_queue* cq,
|
990
1366
|
void* reserved) {
|
@@ -1002,66 +1378,20 @@ void grpc_server_register_completion_queue(grpc_server* server,
|
|
1002
1378
|
calls grpc_completion_queue_pluck() on server completion queues */
|
1003
1379
|
}
|
1004
1380
|
|
1005
|
-
register_completion_queue(server, cq, reserved);
|
1381
|
+
grpc_core::register_completion_queue(server, cq, reserved);
|
1006
1382
|
}
|
1007
1383
|
|
1008
1384
|
grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
|
1009
1385
|
grpc_core::ExecCtx exec_ctx;
|
1010
1386
|
GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
|
1011
1387
|
|
1012
|
-
|
1013
|
-
static_cast<grpc_server*>(gpr_zalloc(sizeof(grpc_server)));
|
1014
|
-
|
1015
|
-
gpr_mu_init(&server->mu_global);
|
1016
|
-
gpr_mu_init(&server->mu_call);
|
1017
|
-
gpr_cv_init(&server->starting_cv);
|
1018
|
-
|
1019
|
-
/* decremented by grpc_server_destroy */
|
1020
|
-
new (&server->internal_refcount) grpc_core::RefCount();
|
1021
|
-
server->root_channel_data.next = server->root_channel_data.prev =
|
1022
|
-
&server->root_channel_data;
|
1023
|
-
|
1024
|
-
server->channel_args = grpc_channel_args_copy(args);
|
1025
|
-
|
1026
|
-
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_ENABLE_CHANNELZ);
|
1027
|
-
if (grpc_channel_arg_get_bool(arg, GRPC_ENABLE_CHANNELZ_DEFAULT)) {
|
1028
|
-
arg = grpc_channel_args_find(
|
1029
|
-
args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE);
|
1030
|
-
size_t channel_tracer_max_memory = grpc_channel_arg_get_integer(
|
1031
|
-
arg,
|
1032
|
-
{GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
|
1033
|
-
server->channelz_server =
|
1034
|
-
grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
|
1035
|
-
server, channel_tracer_max_memory);
|
1036
|
-
server->channelz_server->AddTraceEvent(
|
1037
|
-
grpc_core::channelz::ChannelTrace::Severity::Info,
|
1038
|
-
grpc_slice_from_static_string("Server created"));
|
1039
|
-
}
|
1040
|
-
|
1041
|
-
if (args != nullptr) {
|
1042
|
-
grpc_resource_quota* resource_quota =
|
1043
|
-
grpc_resource_quota_from_channel_args(args, false /* create */);
|
1044
|
-
if (resource_quota != nullptr) {
|
1045
|
-
server->default_resource_user =
|
1046
|
-
grpc_resource_user_create(resource_quota, "default");
|
1047
|
-
}
|
1048
|
-
}
|
1049
|
-
|
1050
|
-
return server;
|
1051
|
-
}
|
1052
|
-
|
1053
|
-
static int streq(const char* a, const char* b) {
|
1054
|
-
if (a == nullptr && b == nullptr) return 1;
|
1055
|
-
if (a == nullptr) return 0;
|
1056
|
-
if (b == nullptr) return 0;
|
1057
|
-
return 0 == strcmp(a, b);
|
1388
|
+
return new grpc_server(args);
|
1058
1389
|
}
|
1059
1390
|
|
1060
1391
|
void* grpc_server_register_method(
|
1061
1392
|
grpc_server* server, const char* method, const char* host,
|
1062
1393
|
grpc_server_register_method_payload_handling payload_handling,
|
1063
1394
|
uint32_t flags) {
|
1064
|
-
registered_method* m;
|
1065
1395
|
GRPC_API_TRACE(
|
1066
1396
|
"grpc_server_register_method(server=%p, method=%s, host=%s, "
|
1067
1397
|
"flags=0x%08x)",
|
@@ -1071,8 +1401,10 @@ void* grpc_server_register_method(
|
|
1071
1401
|
"grpc_server_register_method method string cannot be NULL");
|
1072
1402
|
return nullptr;
|
1073
1403
|
}
|
1074
|
-
for (
|
1075
|
-
|
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)) {
|
1076
1408
|
gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method,
|
1077
1409
|
host ? host : "*");
|
1078
1410
|
return nullptr;
|
@@ -1083,14 +1415,9 @@ void* grpc_server_register_method(
|
|
1083
1415
|
flags);
|
1084
1416
|
return nullptr;
|
1085
1417
|
}
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
m->next = server->registered_methods;
|
1090
|
-
m->payload_handling = payload_handling;
|
1091
|
-
m->flags = flags;
|
1092
|
-
server->registered_methods = m;
|
1093
|
-
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());
|
1094
1421
|
}
|
1095
1422
|
|
1096
1423
|
void grpc_server_start(grpc_server* server) {
|
@@ -1100,64 +1427,157 @@ void grpc_server_start(grpc_server* server) {
|
|
1100
1427
|
GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server));
|
1101
1428
|
|
1102
1429
|
server->started = true;
|
1103
|
-
|
1104
|
-
server->pollsets = static_cast<grpc_pollset**>(
|
1105
|
-
gpr_malloc(sizeof(grpc_pollset*) * server->cq_count));
|
1106
|
-
for (i = 0; i < server->cq_count; i++) {
|
1430
|
+
for (i = 0; i < server->cqs.size(); i++) {
|
1107
1431
|
if (grpc_cq_can_listen(server->cqs[i])) {
|
1108
|
-
server->pollsets
|
1109
|
-
grpc_cq_pollset(server->cqs[i]);
|
1432
|
+
server->pollsets.push_back(grpc_cq_pollset(server->cqs[i]));
|
1110
1433
|
}
|
1111
1434
|
}
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1435
|
+
if (server->unregistered_request_matcher == nullptr) {
|
1436
|
+
server->unregistered_request_matcher =
|
1437
|
+
absl::make_unique<grpc_core::RealRequestMatcher>(server);
|
1438
|
+
}
|
1439
|
+
for (std::unique_ptr<grpc_core::registered_method>& rm :
|
1440
|
+
server->registered_methods) {
|
1441
|
+
if (rm->matcher == nullptr) {
|
1442
|
+
rm->matcher = absl::make_unique<grpc_core::RealRequestMatcher>(server);
|
1443
|
+
}
|
1115
1444
|
}
|
1116
1445
|
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1446
|
+
{
|
1447
|
+
grpc_core::MutexLock lock(&server->mu_global);
|
1448
|
+
server->starting = true;
|
1449
|
+
}
|
1120
1450
|
|
1121
|
-
for (listener
|
1122
|
-
|
1451
|
+
for (auto& listener : server->listeners) {
|
1452
|
+
listener.listener->Start(server, &server->pollsets);
|
1123
1453
|
}
|
1124
1454
|
|
1125
|
-
|
1455
|
+
grpc_core::MutexLock lock(&server->mu_global);
|
1126
1456
|
server->starting = false;
|
1127
|
-
|
1128
|
-
gpr_mu_unlock(&server->mu_global);
|
1457
|
+
server->starting_cv.Signal();
|
1129
1458
|
}
|
1130
1459
|
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
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);
|
1135
1536
|
}
|
1136
1537
|
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
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);
|
1142
1548
|
}
|
1143
1549
|
|
1144
|
-
|
1145
|
-
|
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());
|
1146
1566
|
}
|
1147
1567
|
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
grpc_server* server = chand_->server;
|
1154
|
-
gpr_mu_lock(&server->mu_global);
|
1155
|
-
destroy_channel(chand_);
|
1156
|
-
gpr_mu_unlock(&server->mu_global);
|
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);
|
1157
1573
|
}
|
1574
|
+
grpc_core::server_unref(server);
|
1575
|
+
}
|
1158
1576
|
|
1159
|
-
|
1160
|
-
|
1577
|
+
const std::vector<grpc_pollset*>& grpc_server_get_pollsets(
|
1578
|
+
grpc_server* server) {
|
1579
|
+
return server->pollsets;
|
1580
|
+
}
|
1161
1581
|
|
1162
1582
|
void grpc_server_setup_transport(
|
1163
1583
|
grpc_server* s, grpc_transport* transport, grpc_pollset* accepting_pollset,
|
@@ -1166,11 +1586,9 @@ void grpc_server_setup_transport(
|
|
1166
1586
|
socket_node,
|
1167
1587
|
grpc_resource_user* resource_user) {
|
1168
1588
|
size_t num_registered_methods;
|
1169
|
-
|
1170
|
-
registered_method* rm;
|
1171
|
-
channel_registered_method* crm;
|
1589
|
+
grpc_core::channel_registered_method* crm;
|
1172
1590
|
grpc_channel* channel;
|
1173
|
-
channel_data* chand;
|
1591
|
+
grpc_core::channel_data* chand;
|
1174
1592
|
uint32_t hash;
|
1175
1593
|
size_t slots;
|
1176
1594
|
uint32_t probes;
|
@@ -1179,11 +1597,11 @@ void grpc_server_setup_transport(
|
|
1179
1597
|
|
1180
1598
|
channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport,
|
1181
1599
|
resource_user);
|
1182
|
-
chand = static_cast<channel_data*>(
|
1600
|
+
chand = static_cast<grpc_core::channel_data*>(
|
1183
1601
|
grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0)
|
1184
1602
|
->channel_data);
|
1185
1603
|
chand->server = s;
|
1186
|
-
server_ref(s);
|
1604
|
+
grpc_core::server_ref(s);
|
1187
1605
|
chand->channel = channel;
|
1188
1606
|
if (socket_node != nullptr) {
|
1189
1607
|
chand->channelz_socket_uuid = socket_node->uuid();
|
@@ -1193,41 +1611,38 @@ void grpc_server_setup_transport(
|
|
1193
1611
|
}
|
1194
1612
|
|
1195
1613
|
size_t cq_idx;
|
1196
|
-
for (cq_idx = 0; cq_idx < s->
|
1614
|
+
for (cq_idx = 0; cq_idx < s->cqs.size(); cq_idx++) {
|
1197
1615
|
if (grpc_cq_pollset(s->cqs[cq_idx]) == accepting_pollset) break;
|
1198
1616
|
}
|
1199
|
-
if (cq_idx == s->
|
1617
|
+
if (cq_idx == s->cqs.size()) {
|
1200
1618
|
/* completion queue not found: pick a random one to publish new calls to */
|
1201
|
-
cq_idx = static_cast<size_t>(rand()) % s->
|
1619
|
+
cq_idx = static_cast<size_t>(rand()) % s->cqs.size();
|
1202
1620
|
}
|
1203
1621
|
chand->cq_idx = cq_idx;
|
1204
1622
|
|
1205
|
-
num_registered_methods =
|
1206
|
-
for (rm = s->registered_methods; rm; rm = rm->next) {
|
1207
|
-
num_registered_methods++;
|
1208
|
-
}
|
1623
|
+
num_registered_methods = s->registered_methods.size();
|
1209
1624
|
/* build a lookup table phrased in terms of mdstr's in this channels context
|
1210
1625
|
to quickly find registered methods */
|
1211
1626
|
if (num_registered_methods > 0) {
|
1212
1627
|
slots = 2 * num_registered_methods;
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
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) {
|
1217
1632
|
grpc_core::ExternallyManagedSlice host;
|
1218
|
-
grpc_core::ExternallyManagedSlice method(rm->method);
|
1219
|
-
const bool has_host = rm->host
|
1633
|
+
grpc_core::ExternallyManagedSlice method(rm->method.c_str());
|
1634
|
+
const bool has_host = !rm->host.empty();
|
1220
1635
|
if (has_host) {
|
1221
|
-
host = grpc_core::ExternallyManagedSlice(rm->host);
|
1636
|
+
host = grpc_core::ExternallyManagedSlice(rm->host.c_str());
|
1222
1637
|
}
|
1223
1638
|
hash = GRPC_MDSTR_KV_HASH(has_host ? host.Hash() : 0, method.Hash());
|
1224
|
-
for (probes = 0; chand->registered_methods[(hash + probes) % slots]
|
1639
|
+
for (probes = 0; (*chand->registered_methods)[(hash + probes) % slots]
|
1225
1640
|
.server_registered_method != nullptr;
|
1226
|
-
probes++)
|
1227
|
-
|
1641
|
+
probes++) {
|
1642
|
+
}
|
1228
1643
|
if (probes > max_probes) max_probes = probes;
|
1229
|
-
crm = &chand->registered_methods[(hash + probes) % slots];
|
1230
|
-
crm->server_registered_method = rm;
|
1644
|
+
crm = &(*chand->registered_methods)[(hash + probes) % slots];
|
1645
|
+
crm->server_registered_method = rm.get();
|
1231
1646
|
crm->flags = rm->flags;
|
1232
1647
|
crm->has_host = has_host;
|
1233
1648
|
if (has_host) {
|
@@ -1236,243 +1651,34 @@ void grpc_server_setup_transport(
|
|
1236
1651
|
crm->method = method;
|
1237
1652
|
}
|
1238
1653
|
GPR_ASSERT(slots <= UINT32_MAX);
|
1239
|
-
chand->registered_method_slots = static_cast<uint32_t>(slots);
|
1240
1654
|
chand->registered_method_max_probes = max_probes;
|
1241
1655
|
}
|
1242
1656
|
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1657
|
+
{
|
1658
|
+
grpc_core::MutexLock lock(&s->mu_global);
|
1659
|
+
s->channels.push_front(chand);
|
1660
|
+
chand->list_position = s->channels.begin();
|
1661
|
+
}
|
1248
1662
|
|
1249
1663
|
op = grpc_make_transport_op(nullptr);
|
1250
1664
|
op->set_accept_stream = true;
|
1251
|
-
op->set_accept_stream_fn = accept_stream;
|
1665
|
+
op->set_accept_stream_fn = grpc_core::accept_stream;
|
1252
1666
|
op->set_accept_stream_user_data = chand;
|
1253
|
-
op->start_connectivity_watch.reset(new ConnectivityWatcher(chand));
|
1254
|
-
if (
|
1667
|
+
op->start_connectivity_watch.reset(new grpc_core::ConnectivityWatcher(chand));
|
1668
|
+
if (s->shutdown_flag.load(std::memory_order_acquire)) {
|
1255
1669
|
op->disconnect_with_error =
|
1256
1670
|
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown");
|
1257
1671
|
}
|
1258
1672
|
grpc_transport_perform_op(transport, op);
|
1259
1673
|
}
|
1260
1674
|
|
1261
|
-
void done_published_shutdown(void* done_arg, grpc_cq_completion* storage) {
|
1262
|
-
(void)done_arg;
|
1263
|
-
gpr_free(storage);
|
1264
|
-
}
|
1265
|
-
|
1266
|
-
static void listener_destroy_done(void* s, grpc_error* /*error*/) {
|
1267
|
-
grpc_server* server = static_cast<grpc_server*>(s);
|
1268
|
-
gpr_mu_lock(&server->mu_global);
|
1269
|
-
server->listeners_destroyed++;
|
1270
|
-
maybe_finish_shutdown(server);
|
1271
|
-
gpr_mu_unlock(&server->mu_global);
|
1272
|
-
}
|
1273
|
-
|
1274
|
-
/*
|
1275
|
-
- Kills all pending requests-for-incoming-RPC-calls (i.e the requests made via
|
1276
|
-
grpc_server_request_call and grpc_server_request_registered call will now be
|
1277
|
-
cancelled). See 'kill_pending_work_locked()'
|
1278
|
-
|
1279
|
-
- Shuts down the listeners (i.e the server will no longer listen on the port
|
1280
|
-
for new incoming channels).
|
1281
|
-
|
1282
|
-
- Iterates through all channels on the server and sends shutdown msg (see
|
1283
|
-
'channel_broadcaster_shutdown()' for details) to the clients via the
|
1284
|
-
transport layer. The transport layer then guarantees the following:
|
1285
|
-
-- Sends shutdown to the client (for eg: HTTP2 transport sends GOAWAY)
|
1286
|
-
-- If the server has outstanding calls that are in the process, the
|
1287
|
-
connection is NOT closed until the server is done with all those calls
|
1288
|
-
-- Once, there are no more calls in progress, the channel is closed
|
1289
|
-
*/
|
1290
|
-
void grpc_server_shutdown_and_notify(grpc_server* server,
|
1291
|
-
grpc_completion_queue* cq, void* tag) {
|
1292
|
-
listener* l;
|
1293
|
-
shutdown_tag* sdt;
|
1294
|
-
channel_broadcaster broadcaster;
|
1295
|
-
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
1296
|
-
grpc_core::ExecCtx exec_ctx;
|
1297
|
-
|
1298
|
-
GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
|
1299
|
-
(server, cq, tag));
|
1300
|
-
|
1301
|
-
/* wait for startup to be finished: locks mu_global */
|
1302
|
-
gpr_mu_lock(&server->mu_global);
|
1303
|
-
while (server->starting) {
|
1304
|
-
gpr_cv_wait(&server->starting_cv, &server->mu_global,
|
1305
|
-
gpr_inf_future(GPR_CLOCK_MONOTONIC));
|
1306
|
-
}
|
1307
|
-
|
1308
|
-
/* stay locked, and gather up some stuff to do */
|
1309
|
-
GPR_ASSERT(grpc_cq_begin_op(cq, tag));
|
1310
|
-
if (server->shutdown_published) {
|
1311
|
-
grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, done_published_shutdown, nullptr,
|
1312
|
-
static_cast<grpc_cq_completion*>(
|
1313
|
-
gpr_malloc(sizeof(grpc_cq_completion))));
|
1314
|
-
gpr_mu_unlock(&server->mu_global);
|
1315
|
-
return;
|
1316
|
-
}
|
1317
|
-
server->shutdown_tags = static_cast<shutdown_tag*>(
|
1318
|
-
gpr_realloc(server->shutdown_tags,
|
1319
|
-
sizeof(shutdown_tag) * (server->num_shutdown_tags + 1)));
|
1320
|
-
sdt = &server->shutdown_tags[server->num_shutdown_tags++];
|
1321
|
-
sdt->tag = tag;
|
1322
|
-
sdt->cq = cq;
|
1323
|
-
if (gpr_atm_acq_load(&server->shutdown_flag)) {
|
1324
|
-
gpr_mu_unlock(&server->mu_global);
|
1325
|
-
return;
|
1326
|
-
}
|
1327
|
-
|
1328
|
-
server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
|
1329
|
-
|
1330
|
-
channel_broadcaster_init(server, &broadcaster);
|
1331
|
-
|
1332
|
-
gpr_atm_rel_store(&server->shutdown_flag, 1);
|
1333
|
-
|
1334
|
-
/* collect all unregistered then registered calls */
|
1335
|
-
gpr_mu_lock(&server->mu_call);
|
1336
|
-
kill_pending_work_locked(
|
1337
|
-
server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
|
1338
|
-
gpr_mu_unlock(&server->mu_call);
|
1339
|
-
|
1340
|
-
maybe_finish_shutdown(server);
|
1341
|
-
gpr_mu_unlock(&server->mu_global);
|
1342
|
-
|
1343
|
-
/* Shutdown listeners */
|
1344
|
-
for (l = server->listeners; l; l = l->next) {
|
1345
|
-
GRPC_CLOSURE_INIT(&l->destroy_done, listener_destroy_done, server,
|
1346
|
-
grpc_schedule_on_exec_ctx);
|
1347
|
-
l->destroy(server, l->arg, &l->destroy_done);
|
1348
|
-
if (server->channelz_server != nullptr && l->socket_uuid != 0) {
|
1349
|
-
server->channelz_server->RemoveChildListenSocket(l->socket_uuid);
|
1350
|
-
}
|
1351
|
-
}
|
1352
|
-
|
1353
|
-
channel_broadcaster_shutdown(&broadcaster, true /* send_goaway */,
|
1354
|
-
GRPC_ERROR_NONE);
|
1355
|
-
|
1356
|
-
if (server->default_resource_user != nullptr) {
|
1357
|
-
grpc_resource_quota_unref(
|
1358
|
-
grpc_resource_user_quota(server->default_resource_user));
|
1359
|
-
grpc_resource_user_shutdown(server->default_resource_user);
|
1360
|
-
grpc_resource_user_unref(server->default_resource_user);
|
1361
|
-
}
|
1362
|
-
}
|
1363
|
-
|
1364
|
-
void grpc_server_cancel_all_calls(grpc_server* server) {
|
1365
|
-
channel_broadcaster broadcaster;
|
1366
|
-
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
1367
|
-
grpc_core::ExecCtx exec_ctx;
|
1368
|
-
|
1369
|
-
GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server));
|
1370
|
-
|
1371
|
-
gpr_mu_lock(&server->mu_global);
|
1372
|
-
channel_broadcaster_init(server, &broadcaster);
|
1373
|
-
gpr_mu_unlock(&server->mu_global);
|
1374
|
-
|
1375
|
-
channel_broadcaster_shutdown(
|
1376
|
-
&broadcaster, false /* send_goaway */,
|
1377
|
-
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
|
1378
|
-
}
|
1379
|
-
|
1380
|
-
void grpc_server_destroy(grpc_server* server) {
|
1381
|
-
listener* l;
|
1382
|
-
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
1383
|
-
grpc_core::ExecCtx exec_ctx;
|
1384
|
-
|
1385
|
-
GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server));
|
1386
|
-
|
1387
|
-
gpr_mu_lock(&server->mu_global);
|
1388
|
-
GPR_ASSERT(gpr_atm_acq_load(&server->shutdown_flag) || !server->listeners);
|
1389
|
-
GPR_ASSERT(server->listeners_destroyed == num_listeners(server));
|
1390
|
-
|
1391
|
-
while (server->listeners) {
|
1392
|
-
l = server->listeners;
|
1393
|
-
server->listeners = l->next;
|
1394
|
-
gpr_free(l);
|
1395
|
-
}
|
1396
|
-
|
1397
|
-
gpr_mu_unlock(&server->mu_global);
|
1398
|
-
|
1399
|
-
server_unref(server);
|
1400
|
-
}
|
1401
|
-
|
1402
|
-
void grpc_server_add_listener(
|
1403
|
-
grpc_server* server, void* listener_arg,
|
1404
|
-
void (*start)(grpc_server* server, void* arg, grpc_pollset** pollsets,
|
1405
|
-
size_t pollset_count),
|
1406
|
-
void (*destroy)(grpc_server* server, void* arg, grpc_closure* on_done),
|
1407
|
-
grpc_core::RefCountedPtr<grpc_core::channelz::ListenSocketNode> node) {
|
1408
|
-
listener* l = static_cast<listener*>(gpr_malloc(sizeof(listener)));
|
1409
|
-
l->arg = listener_arg;
|
1410
|
-
l->start = start;
|
1411
|
-
l->destroy = destroy;
|
1412
|
-
l->socket_uuid = 0;
|
1413
|
-
if (node != nullptr) {
|
1414
|
-
l->socket_uuid = node->uuid();
|
1415
|
-
if (server->channelz_server != nullptr) {
|
1416
|
-
server->channelz_server->AddChildListenSocket(std::move(node));
|
1417
|
-
}
|
1418
|
-
}
|
1419
|
-
l->next = server->listeners;
|
1420
|
-
server->listeners = l;
|
1421
|
-
}
|
1422
|
-
|
1423
|
-
static grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx,
|
1424
|
-
requested_call* rc) {
|
1425
|
-
call_data* calld = nullptr;
|
1426
|
-
request_matcher* rm = nullptr;
|
1427
|
-
if (gpr_atm_acq_load(&server->shutdown_flag)) {
|
1428
|
-
fail_call(server, cq_idx, rc,
|
1429
|
-
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
|
1430
|
-
return GRPC_CALL_OK;
|
1431
|
-
}
|
1432
|
-
switch (rc->type) {
|
1433
|
-
case BATCH_CALL:
|
1434
|
-
rm = &server->unregistered_request_matcher;
|
1435
|
-
break;
|
1436
|
-
case REGISTERED_CALL:
|
1437
|
-
rm = &rc->data.registered.method->matcher;
|
1438
|
-
break;
|
1439
|
-
}
|
1440
|
-
if (rm->requests_per_cq[cq_idx].Push(rc->mpscq_node.get())) {
|
1441
|
-
/* this was the first queued request: we need to lock and start
|
1442
|
-
matching calls */
|
1443
|
-
gpr_mu_lock(&server->mu_call);
|
1444
|
-
while ((calld = rm->pending_head) != nullptr) {
|
1445
|
-
rc = reinterpret_cast<requested_call*>(rm->requests_per_cq[cq_idx].Pop());
|
1446
|
-
if (rc == nullptr) break;
|
1447
|
-
rm->pending_head = calld->pending_next;
|
1448
|
-
gpr_mu_unlock(&server->mu_call);
|
1449
|
-
if (!gpr_atm_full_cas(&calld->state, PENDING, ACTIVATED)) {
|
1450
|
-
// Zombied Call
|
1451
|
-
GRPC_CLOSURE_INIT(
|
1452
|
-
&calld->kill_zombie_closure, kill_zombie,
|
1453
|
-
grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
|
1454
|
-
grpc_schedule_on_exec_ctx);
|
1455
|
-
grpc_core::ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
|
1456
|
-
GRPC_ERROR_NONE);
|
1457
|
-
} else {
|
1458
|
-
publish_call(server, calld, cq_idx, rc);
|
1459
|
-
}
|
1460
|
-
gpr_mu_lock(&server->mu_call);
|
1461
|
-
}
|
1462
|
-
gpr_mu_unlock(&server->mu_call);
|
1463
|
-
}
|
1464
|
-
return GRPC_CALL_OK;
|
1465
|
-
}
|
1466
|
-
|
1467
1675
|
grpc_call_error grpc_server_request_call(
|
1468
1676
|
grpc_server* server, grpc_call** call, grpc_call_details* details,
|
1469
1677
|
grpc_metadata_array* initial_metadata,
|
1470
1678
|
grpc_completion_queue* cq_bound_to_call,
|
1471
1679
|
grpc_completion_queue* cq_for_notification, void* tag) {
|
1472
|
-
grpc_call_error error;
|
1473
1680
|
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
1474
1681
|
grpc_core::ExecCtx exec_ctx;
|
1475
|
-
requested_call* rc = static_cast<requested_call*>(gpr_malloc(sizeof(*rc)));
|
1476
1682
|
GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
|
1477
1683
|
GRPC_API_TRACE(
|
1478
1684
|
"grpc_server_request_call("
|
@@ -1481,47 +1687,29 @@ grpc_call_error grpc_server_request_call(
|
|
1481
1687
|
7,
|
1482
1688
|
(server, call, details, initial_metadata, cq_bound_to_call,
|
1483
1689
|
cq_for_notification, tag));
|
1690
|
+
|
1484
1691
|
size_t cq_idx;
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1692
|
+
grpc_call_error error = grpc_core::ValidateServerRequestAndCq(
|
1693
|
+
&cq_idx, server, cq_for_notification, tag, nullptr, nullptr);
|
1694
|
+
if (error != GRPC_CALL_OK) {
|
1695
|
+
return error;
|
1489
1696
|
}
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
}
|
1495
|
-
if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
|
1496
|
-
gpr_free(rc);
|
1497
|
-
error = GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
|
1498
|
-
goto done;
|
1499
|
-
}
|
1500
|
-
details->reserved = nullptr;
|
1501
|
-
rc->cq_idx = cq_idx;
|
1502
|
-
rc->type = BATCH_CALL;
|
1503
|
-
rc->server = server;
|
1504
|
-
rc->tag = tag;
|
1505
|
-
rc->cq_bound_to_call = cq_bound_to_call;
|
1506
|
-
rc->call = call;
|
1507
|
-
rc->data.batch.details = details;
|
1508
|
-
rc->initial_metadata = initial_metadata;
|
1509
|
-
error = queue_call_request(server, cq_idx, rc);
|
1510
|
-
done:
|
1511
|
-
|
1512
|
-
return error;
|
1697
|
+
|
1698
|
+
grpc_core::requested_call* rc = new grpc_core::requested_call(
|
1699
|
+
tag, cq_bound_to_call, call, initial_metadata, details);
|
1700
|
+
return queue_call_request(server, cq_idx, rc);
|
1513
1701
|
}
|
1514
1702
|
|
1515
1703
|
grpc_call_error grpc_server_request_registered_call(
|
1516
1704
|
grpc_server* server, void* rmp, grpc_call** call, gpr_timespec* deadline,
|
1517
1705
|
grpc_metadata_array* initial_metadata, grpc_byte_buffer** optional_payload,
|
1518
1706
|
grpc_completion_queue* cq_bound_to_call,
|
1519
|
-
grpc_completion_queue* cq_for_notification, void*
|
1707
|
+
grpc_completion_queue* cq_for_notification, void* tag_new) {
|
1520
1708
|
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
1521
1709
|
grpc_core::ExecCtx exec_ctx;
|
1522
1710
|
GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
|
1523
|
-
|
1524
|
-
|
1711
|
+
grpc_core::registered_method* rm =
|
1712
|
+
static_cast<grpc_core::registered_method*>(rmp);
|
1525
1713
|
GRPC_API_TRACE(
|
1526
1714
|
"grpc_server_request_registered_call("
|
1527
1715
|
"server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, "
|
@@ -1529,71 +1717,17 @@ grpc_call_error grpc_server_request_registered_call(
|
|
1529
1717
|
"tag=%p)",
|
1530
1718
|
9,
|
1531
1719
|
(server, rmp, call, deadline, initial_metadata, optional_payload,
|
1532
|
-
cq_bound_to_call, cq_for_notification,
|
1720
|
+
cq_bound_to_call, cq_for_notification, tag_new));
|
1533
1721
|
|
1534
1722
|
size_t cq_idx;
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
}
|
1540
|
-
if (cq_idx == server->cq_count) {
|
1541
|
-
gpr_free(rc);
|
1542
|
-
return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
|
1543
|
-
}
|
1544
|
-
if ((optional_payload == nullptr) !=
|
1545
|
-
(rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)) {
|
1546
|
-
gpr_free(rc);
|
1547
|
-
return GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
|
1723
|
+
grpc_call_error error = ValidateServerRequestAndCq(
|
1724
|
+
&cq_idx, server, cq_for_notification, tag_new, optional_payload, rm);
|
1725
|
+
if (error != GRPC_CALL_OK) {
|
1726
|
+
return error;
|
1548
1727
|
}
|
1549
1728
|
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
}
|
1554
|
-
rc->cq_idx = cq_idx;
|
1555
|
-
rc->type = REGISTERED_CALL;
|
1556
|
-
rc->server = server;
|
1557
|
-
rc->tag = tag;
|
1558
|
-
rc->cq_bound_to_call = cq_bound_to_call;
|
1559
|
-
rc->call = call;
|
1560
|
-
rc->data.registered.method = rm;
|
1561
|
-
rc->data.registered.deadline = deadline;
|
1562
|
-
rc->initial_metadata = initial_metadata;
|
1563
|
-
rc->data.registered.optional_payload = 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);
|
1564
1732
|
return queue_call_request(server, cq_idx, rc);
|
1565
1733
|
}
|
1566
|
-
|
1567
|
-
static void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
|
1568
|
-
grpc_error* error) {
|
1569
|
-
*rc->call = nullptr;
|
1570
|
-
rc->initial_metadata->count = 0;
|
1571
|
-
GPR_ASSERT(error != GRPC_ERROR_NONE);
|
1572
|
-
|
1573
|
-
grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc,
|
1574
|
-
&rc->completion);
|
1575
|
-
}
|
1576
|
-
|
1577
|
-
const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) {
|
1578
|
-
return server->channel_args;
|
1579
|
-
}
|
1580
|
-
|
1581
|
-
grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server) {
|
1582
|
-
return server->default_resource_user;
|
1583
|
-
}
|
1584
|
-
|
1585
|
-
int grpc_server_has_open_connections(grpc_server* server) {
|
1586
|
-
int r;
|
1587
|
-
gpr_mu_lock(&server->mu_global);
|
1588
|
-
r = server->root_channel_data.next != &server->root_channel_data;
|
1589
|
-
gpr_mu_unlock(&server->mu_global);
|
1590
|
-
return r;
|
1591
|
-
}
|
1592
|
-
|
1593
|
-
grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
|
1594
|
-
grpc_server* server) {
|
1595
|
-
if (server == nullptr) {
|
1596
|
-
return nullptr;
|
1597
|
-
}
|
1598
|
-
return server->channelz_server.get();
|
1599
|
-
}
|