grpc 1.18.0 → 1.22.0
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 +4731 -7404
- data/etc/roots.pem +146 -0
- data/include/grpc/grpc.h +11 -6
- data/include/grpc/grpc_security.h +297 -4
- data/include/grpc/grpc_security_constants.h +1 -1
- data/include/grpc/impl/codegen/byte_buffer.h +13 -0
- data/include/grpc/impl/codegen/gpr_types.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +30 -7
- data/include/grpc/impl/codegen/port_platform.h +88 -7
- data/include/grpc/impl/codegen/slice.h +2 -22
- data/include/grpc/impl/codegen/status.h +2 -1
- data/include/grpc/impl/codegen/sync_posix.h +18 -0
- data/include/grpc/slice.h +3 -3
- data/src/core/ext/filters/client_channel/backup_poller.cc +21 -16
- data/src/core/ext/filters/client_channel/backup_poller.h +8 -2
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +3 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +2435 -1557
- data/src/core/ext/filters/client_channel/client_channel.h +2 -10
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +6 -89
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +8 -33
- data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
- data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -11
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +179 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +59 -55
- data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -157
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +844 -859
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +14 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +16 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +185 -312
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +143 -375
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +192 -245
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1554 -955
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +14 -10
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
- data/src/core/ext/filters/client_channel/lb_policy.cc +115 -22
- data/src/core/ext/filters/client_channel/lb_policy.h +260 -129
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +5 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +107 -4
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +10 -3
- data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
- data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
- data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +121 -122
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +24 -10
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +111 -47
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
- data/src/core/{lib/iomgr/network_status_tracker.cc → ext/filters/client_channel/resolver/dns/dns_resolver_selection.h} +8 -15
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +36 -82
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +111 -72
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
- data/src/core/ext/filters/client_channel/resolver.cc +54 -1
- data/src/core/ext/filters/client_channel/resolver.h +52 -23
- data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
- data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
- data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +368 -241
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +58 -76
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +543 -0
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +139 -0
- data/src/core/ext/filters/client_channel/server_address.cc +4 -54
- data/src/core/ext/filters/client_channel/server_address.h +1 -13
- data/src/core/ext/filters/client_channel/service_config.cc +329 -0
- data/src/core/ext/filters/client_channel/service_config.h +205 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +803 -838
- data/src/core/ext/filters/client_channel/subchannel.h +295 -128
- data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
- data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
- data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
- data/src/core/ext/filters/http/client_authority_filter.cc +6 -3
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
- data/src/core/ext/filters/max_age/max_age_filter.cc +5 -2
- data/src/core/ext/filters/message_size/message_size_filter.cc +119 -77
- data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -47
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +134 -143
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +68 -21
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +156 -94
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +33 -37
- data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -6
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -4
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +7 -6
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +74 -55
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +33 -11
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -14
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +9 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +43 -30
- data/src/core/ext/transport/chttp2/transport/parsing.cc +52 -70
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +70 -33
- data/src/core/ext/transport/inproc/inproc_transport.cc +26 -18
- data/src/core/lib/channel/channel_args.cc +2 -101
- data/src/core/lib/channel/channel_args.h +3 -37
- data/src/core/lib/channel/channel_stack.h +10 -6
- data/src/core/lib/channel/channel_trace.cc +4 -4
- data/src/core/lib/channel/channel_trace.h +4 -4
- data/src/core/lib/channel/channelz.cc +168 -38
- data/src/core/lib/channel/channelz.h +40 -44
- data/src/core/lib/channel/channelz_registry.cc +75 -107
- data/src/core/lib/channel/channelz_registry.h +10 -28
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/context.h +2 -2
- data/src/core/lib/channel/handshaker.cc +151 -218
- data/src/core/lib/channel/handshaker.h +110 -101
- data/src/core/lib/channel/handshaker_factory.h +11 -19
- data/src/core/lib/channel/handshaker_registry.cc +67 -51
- data/src/core/lib/channel/handshaker_registry.h +21 -16
- data/src/core/lib/compression/algorithm_metadata.h +3 -3
- data/src/core/lib/compression/compression.cc +14 -9
- data/src/core/lib/compression/compression_args.cc +127 -0
- data/src/core/lib/compression/compression_args.h +55 -0
- data/src/core/lib/compression/compression_internal.cc +16 -12
- data/src/core/lib/compression/compression_internal.h +1 -1
- data/src/core/lib/compression/stream_compression.cc +3 -2
- data/src/core/lib/compression/stream_compression.h +2 -2
- data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
- data/src/core/lib/debug/trace.cc +13 -7
- data/src/core/lib/debug/trace.h +14 -1
- data/src/core/lib/gpr/arena.h +13 -9
- data/src/core/lib/gpr/cpu_posix.cc +5 -3
- data/src/core/lib/gpr/env.h +3 -6
- data/src/core/lib/gpr/env_linux.cc +6 -1
- data/src/core/lib/gpr/env_posix.cc +5 -0
- data/src/core/lib/gpr/env_windows.cc +7 -5
- data/src/core/lib/gpr/log.cc +9 -13
- data/src/core/lib/gpr/log_posix.cc +2 -1
- data/src/core/lib/gpr/string.cc +20 -7
- data/src/core/lib/gpr/string.h +10 -3
- data/src/core/lib/gpr/sync_posix.cc +65 -4
- data/src/core/lib/gpr/time.cc +8 -0
- data/src/core/lib/gpr/time_posix.cc +21 -2
- data/src/core/lib/gprpp/arena.cc +103 -0
- data/src/core/lib/gprpp/arena.h +121 -0
- data/src/core/lib/gprpp/atomic.h +75 -5
- data/src/core/lib/gprpp/fork.cc +13 -32
- data/src/core/lib/gprpp/fork.h +5 -1
- data/src/core/lib/gprpp/global_config.h +96 -0
- data/src/core/lib/gprpp/global_config_custom.h +29 -0
- data/src/core/lib/gprpp/global_config_env.cc +135 -0
- data/src/core/lib/gprpp/global_config_env.h +131 -0
- data/src/core/lib/gprpp/global_config_generic.h +44 -0
- data/src/core/lib/gprpp/inlined_vector.h +8 -0
- data/src/core/lib/gprpp/map.h +436 -0
- data/src/core/lib/gprpp/memory.h +2 -2
- data/src/core/lib/gprpp/optional.h +48 -0
- data/src/core/lib/gprpp/orphanable.h +6 -5
- data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
- data/src/core/lib/gprpp/ref_counted.h +36 -17
- data/src/core/lib/gprpp/sync.h +126 -0
- data/src/core/lib/gprpp/thd.h +42 -7
- data/src/core/lib/gprpp/thd_posix.cc +31 -13
- data/src/core/lib/gprpp/thd_windows.cc +47 -34
- data/src/core/lib/http/httpcli.cc +6 -5
- data/src/core/lib/http/httpcli_security_connector.cc +13 -15
- data/src/core/lib/http/parser.cc +3 -2
- data/src/core/lib/http/parser.h +2 -1
- data/src/core/lib/iomgr/buffer_list.cc +182 -24
- data/src/core/lib/iomgr/buffer_list.h +72 -10
- data/src/core/lib/iomgr/call_combiner.cc +84 -90
- data/src/core/lib/iomgr/call_combiner.h +75 -82
- data/src/core/lib/iomgr/cfstream_handle.cc +203 -0
- data/src/core/lib/iomgr/cfstream_handle.h +86 -0
- data/src/core/lib/iomgr/combiner.cc +11 -3
- data/src/core/lib/iomgr/combiner.h +1 -1
- data/src/core/lib/iomgr/endpoint.cc +2 -2
- data/src/core/lib/iomgr/endpoint.h +3 -2
- data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
- data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
- data/src/core/lib/iomgr/error.cc +21 -17
- data/src/core/lib/iomgr/error.h +36 -6
- data/src/core/lib/iomgr/error_cfstream.cc +52 -0
- data/src/core/lib/iomgr/error_cfstream.h +31 -0
- data/src/core/lib/iomgr/error_internal.h +1 -1
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +44 -28
- data/src/core/lib/iomgr/ev_epollex_linux.cc +173 -194
- data/src/core/lib/iomgr/ev_poll_posix.cc +16 -487
- data/src/core/lib/iomgr/ev_posix.cc +29 -19
- data/src/core/lib/iomgr/ev_posix.h +19 -3
- data/src/core/lib/iomgr/ev_windows.cc +2 -2
- data/src/core/lib/iomgr/exec_ctx.cc +1 -0
- data/src/core/lib/iomgr/exec_ctx.h +137 -8
- data/src/core/lib/iomgr/executor.cc +147 -95
- data/src/core/lib/iomgr/executor.h +55 -49
- data/src/core/lib/iomgr/fork_posix.cc +6 -5
- data/src/core/lib/{gprpp/atomic_with_std.h → iomgr/grpc_if_nametoindex.h} +8 -13
- data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
- data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
- data/src/core/lib/iomgr/internal_errqueue.cc +3 -5
- data/src/core/lib/iomgr/internal_errqueue.h +105 -3
- data/src/core/lib/iomgr/iomgr.cc +20 -13
- data/src/core/lib/iomgr/iomgr.h +15 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +17 -3
- data/src/core/lib/iomgr/iomgr_custom.h +2 -0
- data/src/core/lib/iomgr/iomgr_internal.cc +10 -0
- data/src/core/lib/iomgr/iomgr_internal.h +12 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +19 -2
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
- data/src/core/lib/iomgr/iomgr_windows.cc +18 -2
- data/src/core/lib/iomgr/lockfree_event.cc +4 -4
- data/src/core/lib/iomgr/port.h +35 -0
- data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
- data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
- data/src/core/lib/iomgr/resource_quota.cc +40 -37
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
- data/src/core/lib/iomgr/socket_windows.cc +19 -0
- data/src/core/lib/iomgr/socket_windows.h +8 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
- data/src/core/lib/iomgr/tcp_custom.cc +10 -14
- data/src/core/lib/iomgr/tcp_posix.cc +256 -140
- data/src/core/lib/iomgr/tcp_server.cc +5 -0
- data/src/core/lib/iomgr/tcp_server.h +24 -0
- data/src/core/lib/iomgr/tcp_server_custom.cc +14 -12
- data/src/core/lib/iomgr/tcp_server_posix.cc +86 -12
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
- data/src/core/lib/iomgr/tcp_server_windows.cc +13 -11
- data/src/core/lib/iomgr/tcp_uv.cc +5 -7
- data/src/core/lib/iomgr/tcp_windows.cc +8 -14
- data/src/core/lib/iomgr/timer.h +2 -1
- data/src/core/lib/iomgr/timer_generic.cc +16 -16
- data/src/core/lib/iomgr/timer_manager.cc +20 -11
- data/src/core/lib/iomgr/udp_server.cc +8 -6
- data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
- data/src/core/lib/json/json.cc +1 -4
- data/src/core/lib/profiling/basic_timers.cc +10 -4
- data/src/core/lib/security/context/security_context.cc +6 -7
- data/src/core/lib/security/context/security_context.h +3 -4
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
- data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
- data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
- data/src/core/lib/security/credentials/credentials.h +9 -1
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -3
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +2 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +3 -3
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +9 -8
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +210 -0
- data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
- data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -12
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
- data/src/core/lib/security/security_connector/security_connector.cc +0 -1
- data/src/core/lib/security/security_connector/security_connector.h +3 -3
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +39 -38
- data/src/core/lib/security/security_connector/ssl_utils.cc +164 -26
- data/src/core/lib/security/security_connector/ssl_utils.h +70 -1
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
- data/src/core/lib/security/transport/auth_filters.h +5 -2
- data/src/core/lib/security/transport/client_auth_filter.cc +55 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +6 -6
- data/src/core/lib/security/transport/security_handshaker.cc +271 -303
- data/src/core/lib/security/transport/security_handshaker.h +11 -2
- data/src/core/lib/security/transport/server_auth_filter.cc +3 -3
- data/src/core/lib/slice/b64.h +2 -2
- data/src/core/lib/slice/percent_encoding.cc +3 -3
- data/src/core/lib/slice/percent_encoding.h +3 -3
- data/src/core/lib/slice/slice.cc +174 -122
- data/src/core/lib/slice/slice_buffer.cc +54 -21
- data/src/core/lib/slice/slice_hash_table.h +4 -4
- data/src/core/lib/slice/slice_intern.cc +49 -107
- data/src/core/lib/slice/slice_internal.h +264 -3
- data/src/core/lib/slice/slice_string_helpers.cc +10 -1
- data/src/core/lib/slice/slice_string_helpers.h +3 -1
- data/src/core/lib/slice/slice_utils.h +50 -0
- data/src/core/lib/slice/slice_weak_hash_table.h +6 -6
- data/src/core/lib/surface/api_trace.h +1 -1
- data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
- data/src/core/lib/surface/call.cc +67 -46
- data/src/core/lib/surface/call.h +7 -2
- data/src/core/lib/surface/call_details.cc +0 -1
- data/src/core/lib/surface/channel.cc +89 -97
- data/src/core/lib/surface/channel.h +60 -6
- data/src/core/lib/surface/channel_init.h +5 -0
- data/src/core/lib/surface/completion_queue.cc +221 -216
- data/src/core/lib/surface/completion_queue.h +2 -1
- data/src/core/lib/surface/init.cc +82 -33
- data/src/core/lib/surface/init.h +1 -0
- data/src/core/lib/surface/init_secure.cc +1 -1
- data/src/core/lib/surface/lame_client.cc +5 -7
- data/src/core/lib/surface/server.cc +42 -47
- data/src/core/lib/surface/validate_metadata.cc +14 -8
- data/src/core/lib/surface/validate_metadata.h +13 -2
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/bdp_estimator.cc +3 -3
- data/src/core/lib/transport/bdp_estimator.h +2 -2
- data/src/core/lib/transport/connectivity_state.cc +10 -40
- data/src/core/lib/transport/connectivity_state.h +0 -8
- data/src/core/lib/transport/error_utils.cc +12 -0
- data/src/core/lib/transport/metadata.cc +258 -267
- data/src/core/lib/transport/metadata.h +227 -16
- data/src/core/lib/transport/metadata_batch.cc +1 -1
- data/src/core/lib/transport/metadata_batch.h +1 -1
- data/src/core/lib/transport/static_metadata.cc +477 -399
- data/src/core/lib/transport/static_metadata.h +273 -182
- data/src/core/lib/transport/status_metadata.cc +3 -3
- data/src/core/lib/transport/timeout_encoding.cc +1 -1
- data/src/core/lib/transport/timeout_encoding.h +1 -1
- data/src/core/lib/transport/transport.cc +39 -72
- data/src/core/lib/transport/transport.h +59 -24
- data/src/core/lib/transport/transport_impl.h +1 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
- data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +12 -10
- data/src/core/tsi/ssl_transport_security.h +24 -4
- data/src/ruby/bin/math_pb.rb +18 -16
- data/src/ruby/ext/grpc/extconf.rb +12 -4
- data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
- data/src/ruby/ext/grpc/rb_channel.c +14 -10
- data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
- data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
- data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc.c +23 -24
- data/src/ruby/ext/grpc/rb_grpc.h +4 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +24 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -0
- data/src/ruby/ext/grpc/rb_server.c +8 -4
- data/src/ruby/lib/grpc/errors.rb +22 -3
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/README.md +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
- data/src/ruby/spec/errors_spec.rb +141 -0
- data/third_party/cares/cares/ares.h +12 -0
- data/third_party/cares/cares/ares_create_query.c +5 -1
- data/third_party/cares/cares/ares_data.c +74 -73
- data/third_party/cares/cares/ares_destroy.c +6 -1
- data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
- data/third_party/cares/cares/ares_gethostbyname.c +15 -4
- data/third_party/cares/cares/ares_getnameinfo.c +11 -0
- data/third_party/cares/cares/ares_init.c +274 -173
- data/third_party/cares/cares/ares_library_init.c +21 -3
- data/third_party/cares/cares/ares_options.c +6 -2
- data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
- data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
- data/third_party/cares/cares/ares_platform.c +7 -0
- data/third_party/cares/cares/ares_private.h +19 -11
- data/third_party/cares/cares/ares_process.c +27 -2
- data/third_party/cares/cares/ares_rules.h +1 -1
- data/third_party/cares/cares/ares_search.c +7 -0
- data/third_party/cares/cares/ares_send.c +6 -0
- data/third_party/cares/cares/ares_strsplit.c +174 -0
- data/third_party/cares/cares/ares_strsplit.h +43 -0
- data/third_party/cares/cares/ares_version.h +4 -4
- data/third_party/cares/cares/config-win32.h +1 -1
- data/third_party/cares/cares/inet_ntop.c +2 -3
- data/third_party/cares/config_darwin/ares_config.h +3 -0
- data/third_party/cares/config_freebsd/ares_config.h +3 -0
- data/third_party/cares/config_linux/ares_config.h +3 -0
- data/third_party/cares/config_openbsd/ares_config.h +3 -0
- metadata +83 -48
- data/src/core/ext/filters/client_channel/request_routing.cc +0 -936
- data/src/core/ext/filters/client_channel/request_routing.h +0 -177
- data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
- data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
- data/src/core/lib/channel/handshaker_factory.cc +0 -42
- data/src/core/lib/gpr/arena.cc +0 -192
- data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
- data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
- data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
- data/src/core/lib/transport/service_config.cc +0 -106
- data/src/core/lib/transport/service_config.h +0 -249
@@ -45,8 +45,9 @@
|
|
45
45
|
#include "src/core/lib/gpr/spinlock.h"
|
46
46
|
#include "src/core/lib/gpr/tls.h"
|
47
47
|
#include "src/core/lib/gpr/useful.h"
|
48
|
+
#include "src/core/lib/gprpp/inlined_vector.h"
|
48
49
|
#include "src/core/lib/gprpp/manual_constructor.h"
|
49
|
-
#include "src/core/lib/gprpp/
|
50
|
+
#include "src/core/lib/gprpp/sync.h"
|
50
51
|
#include "src/core/lib/iomgr/block_annotate.h"
|
51
52
|
#include "src/core/lib/iomgr/iomgr_internal.h"
|
52
53
|
#include "src/core/lib/iomgr/is_epollexclusive_available.h"
|
@@ -78,18 +79,6 @@ typedef enum { PO_MULTI, PO_FD, PO_EMPTY } pollable_type;
|
|
78
79
|
|
79
80
|
typedef struct pollable pollable;
|
80
81
|
|
81
|
-
typedef struct cached_fd {
|
82
|
-
// Set to the grpc_fd's salt value. See 'salt' variable' in grpc_fd for more
|
83
|
-
// details
|
84
|
-
intptr_t salt;
|
85
|
-
|
86
|
-
// The underlying fd
|
87
|
-
int fd;
|
88
|
-
|
89
|
-
// A recency time counter that helps to determine the LRU fd in the cache
|
90
|
-
uint64_t last_used;
|
91
|
-
} cached_fd;
|
92
|
-
|
93
82
|
/// A pollable is something that can be polled: it has an epoll set to poll on,
|
94
83
|
/// and a wakeup fd for kicks
|
95
84
|
/// There are three broad types:
|
@@ -120,33 +109,6 @@ struct pollable {
|
|
120
109
|
int event_cursor;
|
121
110
|
int event_count;
|
122
111
|
struct epoll_event events[MAX_EPOLL_EVENTS];
|
123
|
-
|
124
|
-
// We may be calling pollable_add_fd() on the same (pollable, fd) multiple
|
125
|
-
// times. To prevent pollable_add_fd() from making multiple sys calls to
|
126
|
-
// epoll_ctl() to add the fd, we maintain a cache of what fds are already
|
127
|
-
// present in the underlying epoll-set.
|
128
|
-
//
|
129
|
-
// Since this is not a correctness issue, we do not need to maintain all the
|
130
|
-
// fds in the cache. Hence we just use an LRU cache of size 'MAX_FDS_IN_CACHE'
|
131
|
-
//
|
132
|
-
// NOTE: An ideal implementation of this should do the following:
|
133
|
-
// 1) Add fds to the cache in pollable_add_fd() function (i.e whenever the fd
|
134
|
-
// is added to the pollable's epoll set)
|
135
|
-
// 2) Remove the fd from the cache whenever the fd is removed from the
|
136
|
-
// underlying epoll set (i.e whenever fd_orphan() is called).
|
137
|
-
//
|
138
|
-
// Implementing (2) above (i.e removing fds from cache on fd_orphan) adds a
|
139
|
-
// lot of complexity since an fd can be present in multiple pollables. So our
|
140
|
-
// implementation ONLY DOES (1) and NOT (2).
|
141
|
-
//
|
142
|
-
// The cache_fd.salt variable helps here to maintain correctness (it serves as
|
143
|
-
// an epoch that differentiates one grpc_fd from the other even though both of
|
144
|
-
// them may have the same fd number)
|
145
|
-
//
|
146
|
-
// The following implements LRU-eviction cache of fds in this pollable
|
147
|
-
cached_fd fd_cache[MAX_FDS_IN_CACHE];
|
148
|
-
int fd_cache_size;
|
149
|
-
uint64_t fd_cache_counter; // Recency timer tick counter
|
150
112
|
};
|
151
113
|
|
152
114
|
static const char* pollable_type_string(pollable_type t) {
|
@@ -189,37 +151,86 @@ static void pollable_unref(pollable* p, int line, const char* reason);
|
|
189
151
|
* Fd Declarations
|
190
152
|
*/
|
191
153
|
|
192
|
-
// Monotonically increasing Epoch counter that is assinged to each grpc_fd. See
|
193
|
-
// the description of 'salt' variable in 'grpc_fd' for more details
|
194
|
-
// TODO: (sreek/kpayson) gpr_atm is intptr_t which may not be wide-enough on
|
195
|
-
// 32-bit systems. Change this to int_64 - atleast on 32-bit systems
|
196
|
-
static gpr_atm g_fd_salt;
|
197
|
-
|
198
154
|
struct grpc_fd {
|
199
|
-
int fd
|
155
|
+
grpc_fd(int fd, const char* name, bool track_err)
|
156
|
+
: fd(fd), track_err(track_err) {
|
157
|
+
gpr_mu_init(&orphan_mu);
|
158
|
+
gpr_mu_init(&pollable_mu);
|
159
|
+
read_closure.InitEvent();
|
160
|
+
write_closure.InitEvent();
|
161
|
+
error_closure.InitEvent();
|
162
|
+
|
163
|
+
char* fd_name;
|
164
|
+
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
|
165
|
+
grpc_iomgr_register_object(&iomgr_object, fd_name);
|
166
|
+
#ifndef NDEBUG
|
167
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
|
168
|
+
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, this, fd_name);
|
169
|
+
}
|
170
|
+
#endif
|
171
|
+
gpr_free(fd_name);
|
172
|
+
}
|
173
|
+
|
174
|
+
// This is really the dtor, but the poller threads waking up from
|
175
|
+
// epoll_wait() may access the (read|write|error)_closure after destruction.
|
176
|
+
// Since the object will be added to the free pool, this behavior is
|
177
|
+
// not going to cause issues, except spurious events if the FD is reused
|
178
|
+
// while the race happens.
|
179
|
+
void destroy() {
|
180
|
+
grpc_iomgr_unregister_object(&iomgr_object);
|
181
|
+
|
182
|
+
POLLABLE_UNREF(pollable_obj, "fd_pollable");
|
183
|
+
pollset_fds.clear();
|
184
|
+
gpr_mu_destroy(&pollable_mu);
|
185
|
+
gpr_mu_destroy(&orphan_mu);
|
186
|
+
|
187
|
+
read_closure.DestroyEvent();
|
188
|
+
write_closure.DestroyEvent();
|
189
|
+
error_closure.DestroyEvent();
|
190
|
+
|
191
|
+
invalidate();
|
192
|
+
}
|
200
193
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
194
|
+
#ifndef NDEBUG
|
195
|
+
/* Since an fd is never really destroyed (i.e gpr_free() is not called), it is
|
196
|
+
* hard-to-debug cases where fd fields are accessed even after calling
|
197
|
+
* fd_destroy(). The following invalidates fd fields to make catching such
|
198
|
+
* errors easier */
|
199
|
+
void invalidate() {
|
200
|
+
fd = -1;
|
201
|
+
gpr_atm_no_barrier_store(&refst, -1);
|
202
|
+
memset(&orphan_mu, -1, sizeof(orphan_mu));
|
203
|
+
memset(&pollable_mu, -1, sizeof(pollable_mu));
|
204
|
+
pollable_obj = nullptr;
|
205
|
+
on_done_closure = nullptr;
|
206
|
+
memset(&iomgr_object, -1, sizeof(iomgr_object));
|
207
|
+
track_err = false;
|
208
|
+
}
|
209
|
+
#else
|
210
|
+
void invalidate() {}
|
211
|
+
#endif
|
212
|
+
|
213
|
+
int fd;
|
205
214
|
|
206
215
|
// refst format:
|
207
216
|
// bit 0 : 1=Active / 0=Orphaned
|
208
217
|
// bits 1-n : refcount
|
209
218
|
// Ref/Unref by two to avoid altering the orphaned bit
|
210
|
-
gpr_atm refst;
|
219
|
+
gpr_atm refst = 1;
|
211
220
|
|
212
221
|
gpr_mu orphan_mu;
|
213
222
|
|
223
|
+
// Protects pollable_obj and pollset_fds.
|
214
224
|
gpr_mu pollable_mu;
|
215
|
-
|
225
|
+
grpc_core::InlinedVector<int, 1> pollset_fds; // Used in PO_MULTI.
|
226
|
+
pollable* pollable_obj = nullptr; // Used in PO_FD.
|
216
227
|
|
217
|
-
grpc_core::
|
218
|
-
grpc_core::
|
219
|
-
grpc_core::
|
228
|
+
grpc_core::LockfreeEvent read_closure;
|
229
|
+
grpc_core::LockfreeEvent write_closure;
|
230
|
+
grpc_core::LockfreeEvent error_closure;
|
220
231
|
|
221
|
-
struct grpc_fd* freelist_next;
|
222
|
-
grpc_closure* on_done_closure;
|
232
|
+
struct grpc_fd* freelist_next = nullptr;
|
233
|
+
grpc_closure* on_done_closure = nullptr;
|
223
234
|
|
224
235
|
grpc_iomgr_object iomgr_object;
|
225
236
|
|
@@ -258,6 +269,7 @@ struct grpc_pollset_worker {
|
|
258
269
|
struct grpc_pollset {
|
259
270
|
gpr_mu mu;
|
260
271
|
gpr_atm worker_count;
|
272
|
+
gpr_atm active_pollable_type;
|
261
273
|
pollable* active_pollable;
|
262
274
|
bool kicked_without_poller;
|
263
275
|
grpc_closure* shutdown_closure;
|
@@ -323,7 +335,7 @@ static gpr_mu fd_freelist_mu;
|
|
323
335
|
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
|
324
336
|
static void ref_by(grpc_fd* fd, int n, const char* reason, const char* file,
|
325
337
|
int line) {
|
326
|
-
if (grpc_trace_fd_refcount
|
338
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
|
327
339
|
gpr_log(GPR_DEBUG,
|
328
340
|
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
329
341
|
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
@@ -337,39 +349,10 @@ static void ref_by(grpc_fd* fd, int n) {
|
|
337
349
|
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
|
338
350
|
}
|
339
351
|
|
340
|
-
#ifndef NDEBUG
|
341
|
-
#define INVALIDATE_FD(fd) invalidate_fd(fd)
|
342
|
-
/* Since an fd is never really destroyed (i.e gpr_free() is not called), it is
|
343
|
-
* hard to cases where fd fields are accessed even after calling fd_destroy().
|
344
|
-
* The following invalidates fd fields to make catching such errors easier */
|
345
|
-
static void invalidate_fd(grpc_fd* fd) {
|
346
|
-
fd->fd = -1;
|
347
|
-
fd->salt = -1;
|
348
|
-
gpr_atm_no_barrier_store(&fd->refst, -1);
|
349
|
-
memset(&fd->orphan_mu, -1, sizeof(fd->orphan_mu));
|
350
|
-
memset(&fd->pollable_mu, -1, sizeof(fd->pollable_mu));
|
351
|
-
fd->pollable_obj = nullptr;
|
352
|
-
fd->on_done_closure = nullptr;
|
353
|
-
memset(&fd->iomgr_object, -1, sizeof(fd->iomgr_object));
|
354
|
-
fd->track_err = false;
|
355
|
-
}
|
356
|
-
#else
|
357
|
-
#define INVALIDATE_FD(fd)
|
358
|
-
#endif
|
359
|
-
|
360
352
|
/* Uninitialize and add to the freelist */
|
361
353
|
static void fd_destroy(void* arg, grpc_error* error) {
|
362
354
|
grpc_fd* fd = static_cast<grpc_fd*>(arg);
|
363
|
-
|
364
|
-
POLLABLE_UNREF(fd->pollable_obj, "fd_pollable");
|
365
|
-
gpr_mu_destroy(&fd->pollable_mu);
|
366
|
-
gpr_mu_destroy(&fd->orphan_mu);
|
367
|
-
|
368
|
-
fd->read_closure->DestroyEvent();
|
369
|
-
fd->write_closure->DestroyEvent();
|
370
|
-
fd->error_closure->DestroyEvent();
|
371
|
-
|
372
|
-
INVALIDATE_FD(fd);
|
355
|
+
fd->destroy();
|
373
356
|
|
374
357
|
/* Add the fd to the freelist */
|
375
358
|
gpr_mu_lock(&fd_freelist_mu);
|
@@ -381,7 +364,7 @@ static void fd_destroy(void* arg, grpc_error* error) {
|
|
381
364
|
#ifndef NDEBUG
|
382
365
|
static void unref_by(grpc_fd* fd, int n, const char* reason, const char* file,
|
383
366
|
int line) {
|
384
|
-
if (grpc_trace_fd_refcount
|
367
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_fd_refcount)) {
|
385
368
|
gpr_log(GPR_DEBUG,
|
386
369
|
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
|
387
370
|
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
@@ -429,35 +412,9 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) {
|
|
429
412
|
|
430
413
|
if (new_fd == nullptr) {
|
431
414
|
new_fd = static_cast<grpc_fd*>(gpr_malloc(sizeof(grpc_fd)));
|
432
|
-
new_fd->read_closure.Init();
|
433
|
-
new_fd->write_closure.Init();
|
434
|
-
new_fd->error_closure.Init();
|
435
|
-
}
|
436
|
-
|
437
|
-
new_fd->fd = fd;
|
438
|
-
new_fd->salt = gpr_atm_no_barrier_fetch_add(&g_fd_salt, 1);
|
439
|
-
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
|
440
|
-
gpr_mu_init(&new_fd->orphan_mu);
|
441
|
-
gpr_mu_init(&new_fd->pollable_mu);
|
442
|
-
new_fd->pollable_obj = nullptr;
|
443
|
-
new_fd->read_closure->InitEvent();
|
444
|
-
new_fd->write_closure->InitEvent();
|
445
|
-
new_fd->error_closure->InitEvent();
|
446
|
-
new_fd->freelist_next = nullptr;
|
447
|
-
new_fd->on_done_closure = nullptr;
|
448
|
-
|
449
|
-
char* fd_name;
|
450
|
-
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
|
451
|
-
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
|
452
|
-
#ifndef NDEBUG
|
453
|
-
if (grpc_trace_fd_refcount.enabled()) {
|
454
|
-
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name);
|
455
415
|
}
|
456
|
-
#endif
|
457
|
-
gpr_free(fd_name);
|
458
416
|
|
459
|
-
new_fd
|
460
|
-
return new_fd;
|
417
|
+
return new (new_fd) grpc_fd(fd, name, track_err);
|
461
418
|
}
|
462
419
|
|
463
420
|
static int fd_wrapped_fd(grpc_fd* fd) {
|
@@ -475,7 +432,6 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
|
|
475
432
|
// true so that the pollable will no longer access its owner_fd field.
|
476
433
|
gpr_mu_lock(&fd->pollable_mu);
|
477
434
|
pollable* pollable_obj = fd->pollable_obj;
|
478
|
-
gpr_mu_unlock(&fd->pollable_mu);
|
479
435
|
|
480
436
|
if (pollable_obj) {
|
481
437
|
gpr_mu_lock(&pollable_obj->owner_orphan_mu);
|
@@ -487,6 +443,17 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
|
|
487
443
|
/* If release_fd is not NULL, we should be relinquishing control of the file
|
488
444
|
descriptor fd->fd (but we still own the grpc_fd structure). */
|
489
445
|
if (release_fd != nullptr) {
|
446
|
+
// Remove the FD from all epolls sets, before releasing it.
|
447
|
+
// Otherwise, we will receive epoll events after we release the FD.
|
448
|
+
epoll_event ev_fd;
|
449
|
+
memset(&ev_fd, 0, sizeof(ev_fd));
|
450
|
+
if (pollable_obj != nullptr) { // For PO_FD.
|
451
|
+
epoll_ctl(pollable_obj->epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
|
452
|
+
}
|
453
|
+
for (size_t i = 0; i < fd->pollset_fds.size(); ++i) { // For PO_MULTI.
|
454
|
+
const int epfd = fd->pollset_fds[i];
|
455
|
+
epoll_ctl(epfd, EPOLL_CTL_DEL, fd->fd, &ev_fd);
|
456
|
+
}
|
490
457
|
*release_fd = fd->fd;
|
491
458
|
} else {
|
492
459
|
close(fd->fd);
|
@@ -508,40 +475,58 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
|
|
508
475
|
gpr_mu_unlock(&pollable_obj->owner_orphan_mu);
|
509
476
|
}
|
510
477
|
|
478
|
+
gpr_mu_unlock(&fd->pollable_mu);
|
511
479
|
gpr_mu_unlock(&fd->orphan_mu);
|
512
480
|
|
513
481
|
UNREF_BY(fd, 2, reason); /* Drop the reference */
|
514
482
|
}
|
515
483
|
|
516
484
|
static bool fd_is_shutdown(grpc_fd* fd) {
|
517
|
-
return fd->read_closure
|
485
|
+
return fd->read_closure.IsShutdown();
|
518
486
|
}
|
519
487
|
|
520
488
|
/* Might be called multiple times */
|
521
489
|
static void fd_shutdown(grpc_fd* fd, grpc_error* why) {
|
522
|
-
if (fd->read_closure
|
490
|
+
if (fd->read_closure.SetShutdown(GRPC_ERROR_REF(why))) {
|
523
491
|
if (shutdown(fd->fd, SHUT_RDWR)) {
|
524
492
|
if (errno != ENOTCONN) {
|
525
493
|
gpr_log(GPR_ERROR, "Error shutting down fd %d. errno: %d",
|
526
494
|
grpc_fd_wrapped_fd(fd), errno);
|
527
495
|
}
|
528
496
|
}
|
529
|
-
fd->write_closure
|
530
|
-
fd->error_closure
|
497
|
+
fd->write_closure.SetShutdown(GRPC_ERROR_REF(why));
|
498
|
+
fd->error_closure.SetShutdown(GRPC_ERROR_REF(why));
|
531
499
|
}
|
532
500
|
GRPC_ERROR_UNREF(why);
|
533
501
|
}
|
534
502
|
|
535
503
|
static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) {
|
536
|
-
fd->read_closure
|
504
|
+
fd->read_closure.NotifyOn(closure);
|
537
505
|
}
|
538
506
|
|
539
507
|
static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) {
|
540
|
-
fd->write_closure
|
508
|
+
fd->write_closure.NotifyOn(closure);
|
541
509
|
}
|
542
510
|
|
543
511
|
static void fd_notify_on_error(grpc_fd* fd, grpc_closure* closure) {
|
544
|
-
fd->error_closure
|
512
|
+
fd->error_closure.NotifyOn(closure);
|
513
|
+
}
|
514
|
+
|
515
|
+
static bool fd_has_pollset(grpc_fd* fd, grpc_pollset* pollset) {
|
516
|
+
const int epfd = pollset->active_pollable->epfd;
|
517
|
+
grpc_core::MutexLock lock(&fd->pollable_mu);
|
518
|
+
for (size_t i = 0; i < fd->pollset_fds.size(); ++i) {
|
519
|
+
if (fd->pollset_fds[i] == epfd) {
|
520
|
+
return true;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
return false;
|
524
|
+
}
|
525
|
+
|
526
|
+
static void fd_add_pollset(grpc_fd* fd, grpc_pollset* pollset) {
|
527
|
+
const int epfd = pollset->active_pollable->epfd;
|
528
|
+
grpc_core::MutexLock lock(&fd->pollable_mu);
|
529
|
+
fd->pollset_fds.push_back(epfd);
|
545
530
|
}
|
546
531
|
|
547
532
|
/*******************************************************************************
|
@@ -594,8 +579,6 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
|
|
594
579
|
(*p)->root_worker = nullptr;
|
595
580
|
(*p)->event_cursor = 0;
|
596
581
|
(*p)->event_count = 0;
|
597
|
-
(*p)->fd_cache_size = 0;
|
598
|
-
(*p)->fd_cache_counter = 0;
|
599
582
|
return GRPC_ERROR_NONE;
|
600
583
|
}
|
601
584
|
|
@@ -603,7 +586,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
|
|
603
586
|
static pollable* pollable_ref(pollable* p) {
|
604
587
|
#else
|
605
588
|
static pollable* pollable_ref(pollable* p, int line, const char* reason) {
|
606
|
-
if (grpc_trace_pollable_refcount
|
589
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_pollable_refcount)) {
|
607
590
|
int r = static_cast<int> gpr_atm_no_barrier_load(&p->refs.count);
|
608
591
|
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
|
609
592
|
"POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason);
|
@@ -618,7 +601,7 @@ static void pollable_unref(pollable* p) {
|
|
618
601
|
#else
|
619
602
|
static void pollable_unref(pollable* p, int line, const char* reason) {
|
620
603
|
if (p == nullptr) return;
|
621
|
-
if (grpc_trace_pollable_refcount
|
604
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_pollable_refcount)) {
|
622
605
|
int r = static_cast<int> gpr_atm_no_barrier_load(&p->refs.count);
|
623
606
|
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
|
624
607
|
"POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason);
|
@@ -629,6 +612,7 @@ static void pollable_unref(pollable* p, int line, const char* reason) {
|
|
629
612
|
close(p->epfd);
|
630
613
|
grpc_wakeup_fd_destroy(&p->wakeup);
|
631
614
|
gpr_mu_destroy(&p->owner_orphan_mu);
|
615
|
+
gpr_mu_destroy(&p->mu);
|
632
616
|
gpr_free(p);
|
633
617
|
}
|
634
618
|
}
|
@@ -637,40 +621,7 @@ static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) {
|
|
637
621
|
grpc_error* error = GRPC_ERROR_NONE;
|
638
622
|
static const char* err_desc = "pollable_add_fd";
|
639
623
|
const int epfd = p->epfd;
|
640
|
-
|
641
|
-
p->fd_cache_counter++;
|
642
|
-
|
643
|
-
// Handle the case of overflow for our cache counter by
|
644
|
-
// reseting the recency-counter on all cache objects
|
645
|
-
if (p->fd_cache_counter == 0) {
|
646
|
-
for (int i = 0; i < p->fd_cache_size; i++) {
|
647
|
-
p->fd_cache[i].last_used = 0;
|
648
|
-
}
|
649
|
-
}
|
650
|
-
|
651
|
-
int lru_idx = 0;
|
652
|
-
for (int i = 0; i < p->fd_cache_size; i++) {
|
653
|
-
if (p->fd_cache[i].fd == fd->fd && p->fd_cache[i].salt == fd->salt) {
|
654
|
-
GRPC_STATS_INC_POLLSET_FD_CACHE_HITS();
|
655
|
-
p->fd_cache[i].last_used = p->fd_cache_counter;
|
656
|
-
gpr_mu_unlock(&p->mu);
|
657
|
-
return GRPC_ERROR_NONE;
|
658
|
-
} else if (p->fd_cache[i].last_used < p->fd_cache[lru_idx].last_used) {
|
659
|
-
lru_idx = i;
|
660
|
-
}
|
661
|
-
}
|
662
|
-
|
663
|
-
// Add to cache
|
664
|
-
if (p->fd_cache_size < MAX_FDS_IN_CACHE) {
|
665
|
-
lru_idx = p->fd_cache_size;
|
666
|
-
p->fd_cache_size++;
|
667
|
-
}
|
668
|
-
p->fd_cache[lru_idx].fd = fd->fd;
|
669
|
-
p->fd_cache[lru_idx].salt = fd->salt;
|
670
|
-
p->fd_cache[lru_idx].last_used = p->fd_cache_counter;
|
671
|
-
gpr_mu_unlock(&p->mu);
|
672
|
-
|
673
|
-
if (grpc_polling_trace.enabled()) {
|
624
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
674
625
|
gpr_log(GPR_INFO, "add fd %p (%d) to pollable %p", fd, fd->fd, p);
|
675
626
|
}
|
676
627
|
|
@@ -718,7 +669,7 @@ static void pollset_global_shutdown(void) {
|
|
718
669
|
|
719
670
|
/* pollset->mu must be held while calling this function */
|
720
671
|
static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) {
|
721
|
-
if (grpc_polling_trace
|
672
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
722
673
|
gpr_log(GPR_INFO,
|
723
674
|
"PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) "
|
724
675
|
"rw=%p (target:NULL) cpsc=%d (target:0)",
|
@@ -743,14 +694,14 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) {
|
|
743
694
|
grpc_core::MutexLock lock(&p->mu);
|
744
695
|
GPR_ASSERT(specific_worker != nullptr);
|
745
696
|
if (specific_worker->kicked) {
|
746
|
-
if (grpc_polling_trace
|
697
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
747
698
|
gpr_log(GPR_INFO, "PS:%p kicked_specific_but_already_kicked", p);
|
748
699
|
}
|
749
700
|
GRPC_STATS_INC_POLLSET_KICKED_AGAIN();
|
750
701
|
return GRPC_ERROR_NONE;
|
751
702
|
}
|
752
703
|
if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) {
|
753
|
-
if (grpc_polling_trace
|
704
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
754
705
|
gpr_log(GPR_INFO, "PS:%p kicked_specific_but_awake", p);
|
755
706
|
}
|
756
707
|
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
|
@@ -759,7 +710,7 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) {
|
|
759
710
|
}
|
760
711
|
if (specific_worker == p->root_worker) {
|
761
712
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD();
|
762
|
-
if (grpc_polling_trace
|
713
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
763
714
|
gpr_log(GPR_INFO, "PS:%p kicked_specific_via_wakeup_fd", p);
|
764
715
|
}
|
765
716
|
specific_worker->kicked = true;
|
@@ -768,7 +719,7 @@ static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) {
|
|
768
719
|
}
|
769
720
|
if (specific_worker->initialized_cv) {
|
770
721
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV();
|
771
|
-
if (grpc_polling_trace
|
722
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
772
723
|
gpr_log(GPR_INFO, "PS:%p kicked_specific_via_cv", p);
|
773
724
|
}
|
774
725
|
specific_worker->kicked = true;
|
@@ -784,7 +735,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset,
|
|
784
735
|
grpc_pollset_worker* specific_worker) {
|
785
736
|
GPR_TIMER_SCOPE("pollset_kick", 0);
|
786
737
|
GRPC_STATS_INC_POLLSET_KICK();
|
787
|
-
if (grpc_polling_trace
|
738
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
788
739
|
gpr_log(GPR_INFO,
|
789
740
|
"PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p",
|
790
741
|
pollset, specific_worker,
|
@@ -794,7 +745,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset,
|
|
794
745
|
if (specific_worker == nullptr) {
|
795
746
|
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
|
796
747
|
if (pollset->root_worker == nullptr) {
|
797
|
-
if (grpc_polling_trace
|
748
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
798
749
|
gpr_log(GPR_INFO, "PS:%p kicked_any_without_poller", pollset);
|
799
750
|
}
|
800
751
|
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER();
|
@@ -820,7 +771,7 @@ static grpc_error* pollset_kick(grpc_pollset* pollset,
|
|
820
771
|
pollset->root_worker->links[PWLINK_POLLSET].next);
|
821
772
|
}
|
822
773
|
} else {
|
823
|
-
if (grpc_polling_trace
|
774
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
824
775
|
gpr_log(GPR_INFO, "PS:%p kicked_any_but_awake", pollset);
|
825
776
|
}
|
826
777
|
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD();
|
@@ -849,6 +800,7 @@ static grpc_error* pollset_kick_all(grpc_pollset* pollset) {
|
|
849
800
|
static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
|
850
801
|
gpr_mu_init(&pollset->mu);
|
851
802
|
gpr_atm_no_barrier_store(&pollset->worker_count, 0);
|
803
|
+
gpr_atm_no_barrier_store(&pollset->active_pollable_type, PO_EMPTY);
|
852
804
|
pollset->active_pollable = POLLABLE_REF(g_empty_pollable, "pollset");
|
853
805
|
pollset->kicked_without_poller = false;
|
854
806
|
pollset->shutdown_closure = nullptr;
|
@@ -869,11 +821,11 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) {
|
|
869
821
|
return static_cast<int>(delta);
|
870
822
|
}
|
871
823
|
|
872
|
-
static void fd_become_readable(grpc_fd* fd) { fd->read_closure
|
824
|
+
static void fd_become_readable(grpc_fd* fd) { fd->read_closure.SetReady(); }
|
873
825
|
|
874
|
-
static void fd_become_writable(grpc_fd* fd) { fd->write_closure
|
826
|
+
static void fd_become_writable(grpc_fd* fd) { fd->write_closure.SetReady(); }
|
875
827
|
|
876
|
-
static void fd_has_errors(grpc_fd* fd) { fd->error_closure
|
828
|
+
static void fd_has_errors(grpc_fd* fd) { fd->error_closure.SetReady(); }
|
877
829
|
|
878
830
|
/* Get the pollable_obj attached to this fd. If none is attached, create a new
|
879
831
|
* pollable object (of type PO_FD), attach it to the fd and return it
|
@@ -939,7 +891,7 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset,
|
|
939
891
|
struct epoll_event* ev = &pollable_obj->events[n];
|
940
892
|
void* data_ptr = ev->data.ptr;
|
941
893
|
if (1 & (intptr_t)data_ptr) {
|
942
|
-
if (grpc_polling_trace
|
894
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
943
895
|
gpr_log(GPR_INFO, "PS:%p got pollset_wakeup %p", pollset, data_ptr);
|
944
896
|
}
|
945
897
|
append_error(&error,
|
@@ -957,7 +909,7 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset,
|
|
957
909
|
bool write_ev = (ev->events & EPOLLOUT) != 0;
|
958
910
|
bool err_fallback = error && !track_err;
|
959
911
|
|
960
|
-
if (grpc_polling_trace
|
912
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
961
913
|
gpr_log(GPR_INFO,
|
962
914
|
"PS:%p got fd %p: cancel=%d read=%d "
|
963
915
|
"write=%d",
|
@@ -989,7 +941,7 @@ static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) {
|
|
989
941
|
GPR_TIMER_SCOPE("pollable_epoll", 0);
|
990
942
|
int timeout = poll_deadline_to_millis_timeout(deadline);
|
991
943
|
|
992
|
-
if (grpc_polling_trace
|
944
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
993
945
|
char* desc = pollable_desc(p);
|
994
946
|
gpr_log(GPR_INFO, "POLLABLE:%p[%s] poll for %dms", p, desc, timeout);
|
995
947
|
gpr_free(desc);
|
@@ -1009,7 +961,7 @@ static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) {
|
|
1009
961
|
|
1010
962
|
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
|
1011
963
|
|
1012
|
-
if (grpc_polling_trace
|
964
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1013
965
|
gpr_log(GPR_INFO, "POLLABLE:%p got %d events", p, r);
|
1014
966
|
}
|
1015
967
|
|
@@ -1079,7 +1031,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
|
|
1079
1031
|
worker->initialized_cv = true;
|
1080
1032
|
gpr_cv_init(&worker->cv);
|
1081
1033
|
gpr_mu_unlock(&pollset->mu);
|
1082
|
-
if (grpc_polling_trace
|
1034
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace) &&
|
1083
1035
|
worker->pollable_obj->root_worker != worker) {
|
1084
1036
|
gpr_log(GPR_INFO, "PS:%p wait %p w=%p for %dms", pollset,
|
1085
1037
|
worker->pollable_obj, worker,
|
@@ -1088,18 +1040,18 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
|
|
1088
1040
|
while (do_poll && worker->pollable_obj->root_worker != worker) {
|
1089
1041
|
if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu,
|
1090
1042
|
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) {
|
1091
|
-
if (grpc_polling_trace
|
1043
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1092
1044
|
gpr_log(GPR_INFO, "PS:%p timeout_wait %p w=%p", pollset,
|
1093
1045
|
worker->pollable_obj, worker);
|
1094
1046
|
}
|
1095
1047
|
do_poll = false;
|
1096
1048
|
} else if (worker->kicked) {
|
1097
|
-
if (grpc_polling_trace
|
1049
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1098
1050
|
gpr_log(GPR_INFO, "PS:%p wakeup %p w=%p", pollset,
|
1099
1051
|
worker->pollable_obj, worker);
|
1100
1052
|
}
|
1101
1053
|
do_poll = false;
|
1102
|
-
} else if (grpc_polling_trace
|
1054
|
+
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace) &&
|
1103
1055
|
worker->pollable_obj->root_worker != worker) {
|
1104
1056
|
gpr_log(GPR_INFO, "PS:%p spurious_wakeup %p w=%p", pollset,
|
1105
1057
|
worker->pollable_obj, worker);
|
@@ -1172,7 +1124,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
|
|
1172
1124
|
#ifndef NDEBUG
|
1173
1125
|
WORKER_PTR->originator = gettid();
|
1174
1126
|
#endif
|
1175
|
-
if (grpc_polling_trace
|
1127
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1176
1128
|
gpr_log(GPR_INFO,
|
1177
1129
|
"PS:%p work hdl=%p worker=%p now=%" PRId64 " deadline=%" PRId64
|
1178
1130
|
" kwp=%d pollable=%p",
|
@@ -1213,7 +1165,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked(
|
|
1213
1165
|
grpc_pollset* pollset, grpc_fd* fd) {
|
1214
1166
|
static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd";
|
1215
1167
|
grpc_error* error = GRPC_ERROR_NONE;
|
1216
|
-
if (grpc_polling_trace
|
1168
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1217
1169
|
gpr_log(GPR_INFO,
|
1218
1170
|
"PS:%p add fd %p (%d); transition pollable from empty to fd",
|
1219
1171
|
pollset, fd, fd->fd);
|
@@ -1229,7 +1181,7 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked(
|
|
1229
1181
|
grpc_pollset* pollset, grpc_fd* and_add_fd) {
|
1230
1182
|
static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi";
|
1231
1183
|
grpc_error* error = GRPC_ERROR_NONE;
|
1232
|
-
if (grpc_polling_trace
|
1184
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1233
1185
|
gpr_log(
|
1234
1186
|
GPR_INFO,
|
1235
1187
|
"PS:%p add fd %p (%d); transition pollable from fd %p to multipoller",
|
@@ -1283,6 +1235,8 @@ static grpc_error* pollset_add_fd_locked(grpc_pollset* pollset, grpc_fd* fd) {
|
|
1283
1235
|
POLLABLE_UNREF(pollset->active_pollable, "pollset");
|
1284
1236
|
pollset->active_pollable = po_at_start;
|
1285
1237
|
} else {
|
1238
|
+
gpr_atm_rel_store(&pollset->active_pollable_type,
|
1239
|
+
pollset->active_pollable->type);
|
1286
1240
|
POLLABLE_UNREF(po_at_start, "pollset_add_fd");
|
1287
1241
|
}
|
1288
1242
|
return error;
|
@@ -1299,7 +1253,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
|
|
1299
1253
|
error = pollable_create(PO_MULTI, &pollset->active_pollable);
|
1300
1254
|
/* Any workers currently polling on this pollset must now be woked up so
|
1301
1255
|
* that they can pick up the new active_pollable */
|
1302
|
-
if (grpc_polling_trace
|
1256
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1303
1257
|
gpr_log(GPR_INFO,
|
1304
1258
|
"PS:%p active pollable transition from empty to multi",
|
1305
1259
|
pollset);
|
@@ -1329,6 +1283,8 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
|
|
1329
1283
|
pollset->active_pollable = po_at_start;
|
1330
1284
|
*pollable_obj = nullptr;
|
1331
1285
|
} else {
|
1286
|
+
gpr_atm_rel_store(&pollset->active_pollable_type,
|
1287
|
+
pollset->active_pollable->type);
|
1332
1288
|
*pollable_obj = POLLABLE_REF(pollset->active_pollable, "pollset_set");
|
1333
1289
|
POLLABLE_UNREF(po_at_start, "pollset_as_multipollable");
|
1334
1290
|
}
|
@@ -1337,9 +1293,23 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
|
|
1337
1293
|
|
1338
1294
|
static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
|
1339
1295
|
GPR_TIMER_SCOPE("pollset_add_fd", 0);
|
1340
|
-
|
1296
|
+
|
1297
|
+
// We never transition from PO_MULTI to other modes (i.e., PO_FD or PO_EMPTY)
|
1298
|
+
// and, thus, it is safe to simply store and check whether the FD has already
|
1299
|
+
// been added to the active pollable previously.
|
1300
|
+
if (gpr_atm_acq_load(&pollset->active_pollable_type) == PO_MULTI &&
|
1301
|
+
fd_has_pollset(fd, pollset)) {
|
1302
|
+
return;
|
1303
|
+
}
|
1304
|
+
|
1305
|
+
grpc_core::MutexLock lock(&pollset->mu);
|
1341
1306
|
grpc_error* error = pollset_add_fd_locked(pollset, fd);
|
1342
|
-
|
1307
|
+
|
1308
|
+
// If we are in PO_MULTI mode, we should update the pollsets of the FD.
|
1309
|
+
if (gpr_atm_no_barrier_load(&pollset->active_pollable_type) == PO_MULTI) {
|
1310
|
+
fd_add_pollset(fd, pollset);
|
1311
|
+
}
|
1312
|
+
|
1343
1313
|
GRPC_LOG_IF_ERROR("pollset_add_fd", error);
|
1344
1314
|
}
|
1345
1315
|
|
@@ -1387,7 +1357,7 @@ static void pollset_set_unref(grpc_pollset_set* pss) {
|
|
1387
1357
|
|
1388
1358
|
static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
|
1389
1359
|
GPR_TIMER_SCOPE("pollset_set_add_fd", 0);
|
1390
|
-
if (grpc_polling_trace
|
1360
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1391
1361
|
gpr_log(GPR_INFO, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd);
|
1392
1362
|
}
|
1393
1363
|
grpc_error* error = GRPC_ERROR_NONE;
|
@@ -1411,7 +1381,7 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
|
|
1411
1381
|
|
1412
1382
|
static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {
|
1413
1383
|
GPR_TIMER_SCOPE("pollset_set_del_fd", 0);
|
1414
|
-
if (grpc_polling_trace
|
1384
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1415
1385
|
gpr_log(GPR_INFO, "PSS:%p: del fd %p", pss, fd);
|
1416
1386
|
}
|
1417
1387
|
pss = pss_lock_adam(pss);
|
@@ -1432,7 +1402,7 @@ static void pollset_set_del_fd(grpc_pollset_set* pss, grpc_fd* fd) {
|
|
1432
1402
|
|
1433
1403
|
static void pollset_set_del_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
|
1434
1404
|
GPR_TIMER_SCOPE("pollset_set_del_pollset", 0);
|
1435
|
-
if (grpc_polling_trace
|
1405
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1436
1406
|
gpr_log(GPR_INFO, "PSS:%p: del pollset %p", pss, ps);
|
1437
1407
|
}
|
1438
1408
|
pss = pss_lock_adam(pss);
|
@@ -1484,7 +1454,7 @@ static grpc_error* add_fds_to_pollsets(grpc_fd** fds, size_t fd_count,
|
|
1484
1454
|
|
1485
1455
|
static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
|
1486
1456
|
GPR_TIMER_SCOPE("pollset_set_add_pollset", 0);
|
1487
|
-
if (grpc_polling_trace
|
1457
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1488
1458
|
gpr_log(GPR_INFO, "PSS:%p: add pollset %p", pss, ps);
|
1489
1459
|
}
|
1490
1460
|
grpc_error* error = GRPC_ERROR_NONE;
|
@@ -1521,7 +1491,7 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
|
|
1521
1491
|
static void pollset_set_add_pollset_set(grpc_pollset_set* a,
|
1522
1492
|
grpc_pollset_set* b) {
|
1523
1493
|
GPR_TIMER_SCOPE("pollset_set_add_pollset_set", 0);
|
1524
|
-
if (grpc_polling_trace
|
1494
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1525
1495
|
gpr_log(GPR_INFO, "PSS: merge (%p, %p)", a, b);
|
1526
1496
|
}
|
1527
1497
|
grpc_error* error = GRPC_ERROR_NONE;
|
@@ -1555,7 +1525,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
|
|
1555
1525
|
if (b_size > a_size) {
|
1556
1526
|
GPR_SWAP(grpc_pollset_set*, a, b);
|
1557
1527
|
}
|
1558
|
-
if (grpc_polling_trace
|
1528
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
|
1559
1529
|
gpr_log(GPR_INFO, "PSS: parent %p to %p", b, a);
|
1560
1530
|
}
|
1561
1531
|
gpr_ref(&a->refs);
|
@@ -1604,8 +1574,15 @@ static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
|
|
1604
1574
|
* Event engine binding
|
1605
1575
|
*/
|
1606
1576
|
|
1577
|
+
static bool is_any_background_poller_thread(void) { return false; }
|
1578
|
+
|
1607
1579
|
static void shutdown_background_closure(void) {}
|
1608
1580
|
|
1581
|
+
static bool add_closure_to_background_poller(grpc_closure* closure,
|
1582
|
+
grpc_error* error) {
|
1583
|
+
return false;
|
1584
|
+
}
|
1585
|
+
|
1609
1586
|
static void shutdown_engine(void) {
|
1610
1587
|
fd_global_shutdown();
|
1611
1588
|
pollset_global_shutdown();
|
@@ -1644,8 +1621,10 @@ static const grpc_event_engine_vtable vtable = {
|
|
1644
1621
|
pollset_set_add_fd,
|
1645
1622
|
pollset_set_del_fd,
|
1646
1623
|
|
1624
|
+
is_any_background_poller_thread,
|
1647
1625
|
shutdown_background_closure,
|
1648
1626
|
shutdown_engine,
|
1627
|
+
add_closure_to_background_poller,
|
1649
1628
|
};
|
1650
1629
|
|
1651
1630
|
const grpc_event_engine_vtable* grpc_init_epollex_linux(
|