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
data/src/core/lib/gpr/string.cc
CHANGED
@@ -126,7 +126,8 @@ static void asciidump(dump_out* out, const char* buf, size_t len) {
|
|
126
126
|
}
|
127
127
|
}
|
128
128
|
|
129
|
-
char*
|
129
|
+
char* gpr_dump_return_len(const char* buf, size_t len, uint32_t flags,
|
130
|
+
size_t* out_len) {
|
130
131
|
dump_out out = dump_out_create();
|
131
132
|
if (flags & GPR_DUMP_HEX) {
|
132
133
|
hexdump(&out, buf, len);
|
@@ -135,9 +136,15 @@ char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
|
|
135
136
|
asciidump(&out, buf, len);
|
136
137
|
}
|
137
138
|
dump_out_append(&out, 0);
|
139
|
+
*out_len = out.length;
|
138
140
|
return out.data;
|
139
141
|
}
|
140
142
|
|
143
|
+
char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
|
144
|
+
size_t unused;
|
145
|
+
return gpr_dump_return_len(buf, len, flags, &unused);
|
146
|
+
}
|
147
|
+
|
141
148
|
int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) {
|
142
149
|
uint32_t out = 0;
|
143
150
|
uint32_t new_val;
|
@@ -332,16 +339,22 @@ void* gpr_memrchr(const void* s, int c, size_t n) {
|
|
332
339
|
return nullptr;
|
333
340
|
}
|
334
341
|
|
335
|
-
bool
|
336
|
-
|
342
|
+
bool gpr_parse_bool_value(const char* s, bool* dst) {
|
343
|
+
const char* kTrue[] = {"1", "t", "true", "y", "yes"};
|
344
|
+
const char* kFalse[] = {"0", "f", "false", "n", "no"};
|
345
|
+
static_assert(sizeof(kTrue) == sizeof(kFalse), "true_false_equal");
|
346
|
+
|
337
347
|
if (s == nullptr) {
|
338
348
|
return false;
|
339
349
|
}
|
340
|
-
|
341
|
-
|
342
|
-
|
350
|
+
for (size_t i = 0; i < GPR_ARRAY_SIZE(kTrue); ++i) {
|
351
|
+
if (gpr_stricmp(s, kTrue[i]) == 0) {
|
352
|
+
*dst = true;
|
353
|
+
return true;
|
354
|
+
} else if (gpr_stricmp(s, kFalse[i]) == 0) {
|
355
|
+
*dst = false;
|
343
356
|
return true;
|
344
357
|
}
|
345
358
|
}
|
346
|
-
return false;
|
359
|
+
return false; // didn't match a legal input
|
347
360
|
}
|
data/src/core/lib/gpr/string.h
CHANGED
@@ -32,9 +32,14 @@
|
|
32
32
|
#define GPR_DUMP_HEX 0x00000001
|
33
33
|
#define GPR_DUMP_ASCII 0x00000002
|
34
34
|
|
35
|
-
/* Converts array buf, of length len, into a C string
|
35
|
+
/* Converts array buf, of length len, into a C string according to the flags.
|
36
36
|
Result should be freed with gpr_free() */
|
37
37
|
char* gpr_dump(const char* buf, size_t len, uint32_t flags);
|
38
|
+
/* Converts array buf, of length len, into a C string according to the flags.
|
39
|
+
The length of the returned buffer is stored in out_len.
|
40
|
+
Result should be freed with gpr_free() */
|
41
|
+
char* gpr_dump_return_len(const char* buf, size_t len, uint32_t flags,
|
42
|
+
size_t* out_len);
|
38
43
|
|
39
44
|
/* Parses an array of bytes into an integer (base 10). Returns 1 on success,
|
40
45
|
0 on failure. */
|
@@ -113,7 +118,9 @@ int gpr_stricmp(const char* a, const char* b);
|
|
113
118
|
|
114
119
|
void* gpr_memrchr(const void* s, int c, size_t n);
|
115
120
|
|
116
|
-
|
117
|
-
|
121
|
+
/* Try to parse given string into a boolean value.
|
122
|
+
When parsed successfully, dst will have the value and returns true.
|
123
|
+
Otherwise, it returns false. */
|
124
|
+
bool gpr_parse_bool_value(const char* value, bool* dst);
|
118
125
|
|
119
126
|
#endif /* GRPC_CORE_LIB_GPR_STRING_H */
|
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
#include <grpc/support/port_platform.h>
|
20
20
|
|
21
|
+
#include <grpc/support/alloc.h>
|
22
|
+
|
21
23
|
#ifdef GPR_POSIX_SYNC
|
22
24
|
|
23
25
|
#include <errno.h>
|
@@ -72,27 +74,53 @@ gpr_atm gpr_counter_atm_add = 0;
|
|
72
74
|
#endif
|
73
75
|
|
74
76
|
void gpr_mu_init(gpr_mu* mu) {
|
77
|
+
#ifdef GRPC_ASAN_ENABLED
|
78
|
+
GPR_ASSERT(pthread_mutex_init(&mu->mutex, nullptr) == 0);
|
79
|
+
mu->leak_checker = static_cast<int*>(malloc(sizeof(*mu->leak_checker)));
|
80
|
+
GPR_ASSERT(mu->leak_checker != nullptr);
|
81
|
+
#else
|
75
82
|
GPR_ASSERT(pthread_mutex_init(mu, nullptr) == 0);
|
83
|
+
#endif
|
76
84
|
}
|
77
85
|
|
78
|
-
void gpr_mu_destroy(gpr_mu* mu) {
|
86
|
+
void gpr_mu_destroy(gpr_mu* mu) {
|
87
|
+
#ifdef GRPC_ASAN_ENABLED
|
88
|
+
GPR_ASSERT(pthread_mutex_destroy(&mu->mutex) == 0);
|
89
|
+
free(mu->leak_checker);
|
90
|
+
#else
|
91
|
+
GPR_ASSERT(pthread_mutex_destroy(mu) == 0);
|
92
|
+
#endif
|
93
|
+
}
|
79
94
|
|
80
95
|
void gpr_mu_lock(gpr_mu* mu) {
|
81
96
|
#ifdef GPR_LOW_LEVEL_COUNTERS
|
82
97
|
GPR_ATM_INC_COUNTER(gpr_mu_locks);
|
83
98
|
#endif
|
84
99
|
GPR_TIMER_SCOPE("gpr_mu_lock", 0);
|
100
|
+
#ifdef GRPC_ASAN_ENABLED
|
101
|
+
GPR_ASSERT(pthread_mutex_lock(&mu->mutex) == 0);
|
102
|
+
#else
|
85
103
|
GPR_ASSERT(pthread_mutex_lock(mu) == 0);
|
104
|
+
#endif
|
86
105
|
}
|
87
106
|
|
88
107
|
void gpr_mu_unlock(gpr_mu* mu) {
|
89
108
|
GPR_TIMER_SCOPE("gpr_mu_unlock", 0);
|
109
|
+
#ifdef GRPC_ASAN_ENABLED
|
110
|
+
GPR_ASSERT(pthread_mutex_unlock(&mu->mutex) == 0);
|
111
|
+
#else
|
90
112
|
GPR_ASSERT(pthread_mutex_unlock(mu) == 0);
|
113
|
+
#endif
|
91
114
|
}
|
92
115
|
|
93
116
|
int gpr_mu_trylock(gpr_mu* mu) {
|
94
117
|
GPR_TIMER_SCOPE("gpr_mu_trylock", 0);
|
95
|
-
int err =
|
118
|
+
int err = 0;
|
119
|
+
#ifdef GRPC_ASAN_ENABLED
|
120
|
+
err = pthread_mutex_trylock(&mu->mutex);
|
121
|
+
#else
|
122
|
+
err = pthread_mutex_trylock(mu);
|
123
|
+
#endif
|
96
124
|
GPR_ASSERT(err == 0 || err == EBUSY);
|
97
125
|
return err == 0;
|
98
126
|
}
|
@@ -105,10 +133,24 @@ void gpr_cv_init(gpr_cv* cv) {
|
|
105
133
|
#if GPR_LINUX
|
106
134
|
GPR_ASSERT(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0);
|
107
135
|
#endif // GPR_LINUX
|
136
|
+
|
137
|
+
#ifdef GRPC_ASAN_ENABLED
|
138
|
+
GPR_ASSERT(pthread_cond_init(&cv->cond_var, &attr) == 0);
|
139
|
+
cv->leak_checker = static_cast<int*>(malloc(sizeof(*cv->leak_checker)));
|
140
|
+
GPR_ASSERT(cv->leak_checker != nullptr);
|
141
|
+
#else
|
108
142
|
GPR_ASSERT(pthread_cond_init(cv, &attr) == 0);
|
143
|
+
#endif
|
109
144
|
}
|
110
145
|
|
111
|
-
void gpr_cv_destroy(gpr_cv* cv) {
|
146
|
+
void gpr_cv_destroy(gpr_cv* cv) {
|
147
|
+
#ifdef GRPC_ASAN_ENABLED
|
148
|
+
GPR_ASSERT(pthread_cond_destroy(&cv->cond_var) == 0);
|
149
|
+
free(cv->leak_checker);
|
150
|
+
#else
|
151
|
+
GPR_ASSERT(pthread_cond_destroy(cv) == 0);
|
152
|
+
#endif
|
153
|
+
}
|
112
154
|
|
113
155
|
// For debug of the timer manager crash only.
|
114
156
|
// TODO (mxyan): remove after bug is fixed.
|
@@ -169,7 +211,11 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
|
|
169
211
|
#endif
|
170
212
|
if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) ==
|
171
213
|
0) {
|
214
|
+
#ifdef GRPC_ASAN_ENABLED
|
215
|
+
err = pthread_cond_wait(&cv->cond_var, &mu->mutex);
|
216
|
+
#else
|
172
217
|
err = pthread_cond_wait(cv, mu);
|
218
|
+
#endif
|
173
219
|
} else {
|
174
220
|
struct timespec abs_deadline_ts;
|
175
221
|
#if GPR_LINUX
|
@@ -181,7 +227,12 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
|
|
181
227
|
#endif // GPR_LINUX
|
182
228
|
abs_deadline_ts.tv_sec = static_cast<time_t>(abs_deadline.tv_sec);
|
183
229
|
abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
|
230
|
+
#ifdef GRPC_ASAN_ENABLED
|
231
|
+
err = pthread_cond_timedwait(&cv->cond_var, &mu->mutex, &abs_deadline_ts);
|
232
|
+
#else
|
184
233
|
err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
|
234
|
+
#endif
|
235
|
+
|
185
236
|
#ifdef GRPC_DEBUG_TIMER_MANAGER
|
186
237
|
// For debug of the timer manager crash only.
|
187
238
|
// TODO (mxyan): remove after bug is fixed.
|
@@ -226,10 +277,20 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
|
|
226
277
|
return err == ETIMEDOUT;
|
227
278
|
}
|
228
279
|
|
229
|
-
void gpr_cv_signal(gpr_cv* cv) {
|
280
|
+
void gpr_cv_signal(gpr_cv* cv) {
|
281
|
+
#ifdef GRPC_ASAN_ENABLED
|
282
|
+
GPR_ASSERT(pthread_cond_signal(&cv->cond_var) == 0);
|
283
|
+
#else
|
284
|
+
GPR_ASSERT(pthread_cond_signal(cv) == 0);
|
285
|
+
#endif
|
286
|
+
}
|
230
287
|
|
231
288
|
void gpr_cv_broadcast(gpr_cv* cv) {
|
289
|
+
#ifdef GRPC_ASAN_ENABLED
|
290
|
+
GPR_ASSERT(pthread_cond_broadcast(&cv->cond_var) == 0);
|
291
|
+
#else
|
232
292
|
GPR_ASSERT(pthread_cond_broadcast(cv) == 0);
|
293
|
+
#endif
|
233
294
|
}
|
234
295
|
|
235
296
|
/*----------------------------------------*/
|
data/src/core/lib/gpr/time.cc
CHANGED
@@ -135,6 +135,10 @@ gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) {
|
|
135
135
|
gpr_timespec sum;
|
136
136
|
int64_t inc = 0;
|
137
137
|
GPR_ASSERT(b.clock_type == GPR_TIMESPAN);
|
138
|
+
// tv_nsec in a timespan is always +ve. -ve timespan is represented as (-ve
|
139
|
+
// tv_sec, +ve tv_nsec). For example, timespan = -2.5 seconds is represented
|
140
|
+
// as {-3, 5e8, GPR_TIMESPAN}
|
141
|
+
GPR_ASSERT(b.tv_nsec >= 0);
|
138
142
|
sum.clock_type = a.clock_type;
|
139
143
|
sum.tv_nsec = a.tv_nsec + b.tv_nsec;
|
140
144
|
if (sum.tv_nsec >= GPR_NS_PER_SEC) {
|
@@ -165,6 +169,10 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) {
|
|
165
169
|
int64_t dec = 0;
|
166
170
|
if (b.clock_type == GPR_TIMESPAN) {
|
167
171
|
diff.clock_type = a.clock_type;
|
172
|
+
// tv_nsec in a timespan is always +ve. -ve timespan is represented as (-ve
|
173
|
+
// tv_sec, +ve tv_nsec). For example, timespan = -2.5 seconds is represented
|
174
|
+
// as {-3, 5e8, GPR_TIMESPAN}
|
175
|
+
GPR_ASSERT(b.tv_nsec >= 0);
|
168
176
|
} else {
|
169
177
|
GPR_ASSERT(a.clock_type == b.clock_type);
|
170
178
|
diff.clock_type = GPR_TIMESPAN;
|
@@ -108,6 +108,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
|
|
108
108
|
now.clock_type = clock;
|
109
109
|
switch (clock) {
|
110
110
|
case GPR_CLOCK_REALTIME:
|
111
|
+
// gettimeofday(...) function may return with a value whose tv_usec is
|
112
|
+
// greater than 1e6 on iOS The case is resolved with the guard at end of
|
113
|
+
// this function.
|
111
114
|
gettimeofday(&now_tv, nullptr);
|
112
115
|
now.tv_sec = now_tv.tv_sec;
|
113
116
|
now.tv_nsec = now_tv.tv_usec * 1000;
|
@@ -124,6 +127,16 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
|
|
124
127
|
abort();
|
125
128
|
}
|
126
129
|
|
130
|
+
// Guard the tv_nsec field in valid range for all clock types
|
131
|
+
while (GPR_UNLIKELY(now.tv_nsec >= 1e9)) {
|
132
|
+
now.tv_sec++;
|
133
|
+
now.tv_nsec -= 1e9;
|
134
|
+
}
|
135
|
+
while (GPR_UNLIKELY(now.tv_nsec < 0)) {
|
136
|
+
now.tv_sec--;
|
137
|
+
now.tv_nsec += 1e9;
|
138
|
+
}
|
139
|
+
|
127
140
|
return now;
|
128
141
|
}
|
129
142
|
#endif
|
@@ -133,12 +146,18 @@ gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
|
|
133
146
|
#ifdef GPR_LOW_LEVEL_COUNTERS
|
134
147
|
gpr_atm gpr_now_call_count;
|
135
148
|
#endif
|
136
|
-
|
137
149
|
gpr_timespec gpr_now(gpr_clock_type clock_type) {
|
138
150
|
#ifdef GPR_LOW_LEVEL_COUNTERS
|
139
151
|
__atomic_fetch_add(&gpr_now_call_count, 1, __ATOMIC_RELAXED);
|
140
152
|
#endif
|
141
|
-
|
153
|
+
// validate clock type
|
154
|
+
GPR_ASSERT(clock_type == GPR_CLOCK_MONOTONIC ||
|
155
|
+
clock_type == GPR_CLOCK_REALTIME ||
|
156
|
+
clock_type == GPR_CLOCK_PRECISE);
|
157
|
+
gpr_timespec ts = gpr_now_impl(clock_type);
|
158
|
+
// tv_nsecs must be in the range [0, 1e9).
|
159
|
+
GPR_ASSERT(ts.tv_nsec >= 0 && ts.tv_nsec < 1e9);
|
160
|
+
return ts;
|
142
161
|
}
|
143
162
|
|
144
163
|
void gpr_sleep_until(gpr_timespec until) {
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2017 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
21
|
+
#include "src/core/lib/gprpp/arena.h"
|
22
|
+
|
23
|
+
#include <string.h>
|
24
|
+
#include <new>
|
25
|
+
|
26
|
+
#include <grpc/support/alloc.h>
|
27
|
+
#include <grpc/support/atm.h>
|
28
|
+
#include <grpc/support/log.h>
|
29
|
+
#include <grpc/support/sync.h>
|
30
|
+
|
31
|
+
#include "src/core/lib/gpr/alloc.h"
|
32
|
+
#include "src/core/lib/gprpp/memory.h"
|
33
|
+
|
34
|
+
namespace {
|
35
|
+
|
36
|
+
void* ArenaStorage(size_t initial_size) {
|
37
|
+
static constexpr size_t base_size =
|
38
|
+
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_core::Arena));
|
39
|
+
initial_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(initial_size);
|
40
|
+
size_t alloc_size = base_size + initial_size;
|
41
|
+
static constexpr size_t alignment =
|
42
|
+
(GPR_CACHELINE_SIZE > GPR_MAX_ALIGNMENT &&
|
43
|
+
GPR_CACHELINE_SIZE % GPR_MAX_ALIGNMENT == 0)
|
44
|
+
? GPR_CACHELINE_SIZE
|
45
|
+
: GPR_MAX_ALIGNMENT;
|
46
|
+
return gpr_malloc_aligned(alloc_size, alignment);
|
47
|
+
}
|
48
|
+
|
49
|
+
} // namespace
|
50
|
+
|
51
|
+
namespace grpc_core {
|
52
|
+
|
53
|
+
Arena::~Arena() {
|
54
|
+
Zone* z = last_zone_;
|
55
|
+
while (z) {
|
56
|
+
Zone* prev_z = z->prev;
|
57
|
+
z->~Zone();
|
58
|
+
gpr_free_aligned(z);
|
59
|
+
z = prev_z;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
Arena* Arena::Create(size_t initial_size) {
|
64
|
+
return new (ArenaStorage(initial_size)) Arena(initial_size);
|
65
|
+
}
|
66
|
+
|
67
|
+
Pair<Arena*, void*> Arena::CreateWithAlloc(size_t initial_size,
|
68
|
+
size_t alloc_size) {
|
69
|
+
static constexpr size_t base_size =
|
70
|
+
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena));
|
71
|
+
auto* new_arena =
|
72
|
+
new (ArenaStorage(initial_size)) Arena(initial_size, alloc_size);
|
73
|
+
void* first_alloc = reinterpret_cast<char*>(new_arena) + base_size;
|
74
|
+
return MakePair(new_arena, first_alloc);
|
75
|
+
}
|
76
|
+
|
77
|
+
size_t Arena::Destroy() {
|
78
|
+
size_t size = total_used_.Load(MemoryOrder::RELAXED);
|
79
|
+
this->~Arena();
|
80
|
+
gpr_free_aligned(this);
|
81
|
+
return size;
|
82
|
+
}
|
83
|
+
|
84
|
+
void* Arena::AllocZone(size_t size) {
|
85
|
+
// If the allocation isn't able to end in the initial zone, create a new
|
86
|
+
// zone for this allocation, and any unused space in the initial zone is
|
87
|
+
// wasted. This overflowing and wasting is uncommon because of our arena
|
88
|
+
// sizing hysteresis (that is, most calls should have a large enough initial
|
89
|
+
// zone and will not need to grow the arena).
|
90
|
+
static constexpr size_t zone_base_size =
|
91
|
+
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Zone));
|
92
|
+
size_t alloc_size = zone_base_size + size;
|
93
|
+
Zone* z = new (gpr_malloc_aligned(alloc_size, GPR_MAX_ALIGNMENT)) Zone();
|
94
|
+
{
|
95
|
+
gpr_spinlock_lock(&arena_growth_spinlock_);
|
96
|
+
z->prev = last_zone_;
|
97
|
+
last_zone_ = z;
|
98
|
+
gpr_spinlock_unlock(&arena_growth_spinlock_);
|
99
|
+
}
|
100
|
+
return reinterpret_cast<char*>(z) + zone_base_size;
|
101
|
+
}
|
102
|
+
|
103
|
+
} // namespace grpc_core
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2017 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
// \file Arena based allocator
|
20
|
+
// Allows very fast allocation of memory, but that memory cannot be freed until
|
21
|
+
// the arena as a whole is freed
|
22
|
+
// Tracks the total memory allocated against it, so that future arenas can
|
23
|
+
// pre-allocate the right amount of memory
|
24
|
+
|
25
|
+
#ifndef GRPC_CORE_LIB_GPRPP_ARENA_H
|
26
|
+
#define GRPC_CORE_LIB_GPRPP_ARENA_H
|
27
|
+
|
28
|
+
#include <grpc/support/port_platform.h>
|
29
|
+
|
30
|
+
#include <new>
|
31
|
+
#include <utility>
|
32
|
+
|
33
|
+
#include <grpc/support/alloc.h>
|
34
|
+
#include <grpc/support/sync.h>
|
35
|
+
|
36
|
+
#include "src/core/lib/gpr/alloc.h"
|
37
|
+
#include "src/core/lib/gpr/spinlock.h"
|
38
|
+
#include "src/core/lib/gprpp/atomic.h"
|
39
|
+
#include "src/core/lib/gprpp/pair.h"
|
40
|
+
|
41
|
+
#include <stddef.h>
|
42
|
+
|
43
|
+
namespace grpc_core {
|
44
|
+
|
45
|
+
class Arena {
|
46
|
+
public:
|
47
|
+
// Create an arena, with \a initial_size bytes in the first allocated buffer.
|
48
|
+
static Arena* Create(size_t initial_size);
|
49
|
+
|
50
|
+
// Create an arena, with \a initial_size bytes in the first allocated buffer,
|
51
|
+
// and return both a void pointer to the returned arena and a void* with the
|
52
|
+
// first allocation.
|
53
|
+
static Pair<Arena*, void*> CreateWithAlloc(size_t initial_size,
|
54
|
+
size_t alloc_size);
|
55
|
+
|
56
|
+
// Destroy an arena, returning the total number of bytes allocated.
|
57
|
+
size_t Destroy();
|
58
|
+
// Allocate \a size bytes from the arena.
|
59
|
+
void* Alloc(size_t size) {
|
60
|
+
static constexpr size_t base_size =
|
61
|
+
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena));
|
62
|
+
size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(size);
|
63
|
+
size_t begin = total_used_.FetchAdd(size, MemoryOrder::RELAXED);
|
64
|
+
if (begin + size <= initial_zone_size_) {
|
65
|
+
return reinterpret_cast<char*>(this) + base_size + begin;
|
66
|
+
} else {
|
67
|
+
return AllocZone(size);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
// TODO(roth): We currently assume that all callers need alignment of 16
|
72
|
+
// bytes, which may be wrong in some cases. When we have time, we should
|
73
|
+
// change this to instead use the alignment of the type being allocated by
|
74
|
+
// this method.
|
75
|
+
template <typename T, typename... Args>
|
76
|
+
T* New(Args&&... args) {
|
77
|
+
T* t = static_cast<T*>(Alloc(sizeof(T)));
|
78
|
+
new (t) T(std::forward<Args>(args)...);
|
79
|
+
return t;
|
80
|
+
}
|
81
|
+
|
82
|
+
private:
|
83
|
+
struct Zone {
|
84
|
+
Zone* prev;
|
85
|
+
};
|
86
|
+
|
87
|
+
// Initialize an arena.
|
88
|
+
// Parameters:
|
89
|
+
// initial_size: The initial size of the whole arena in bytes. These bytes
|
90
|
+
// are contained within 'zone 0'. If the arena user ends up requiring more
|
91
|
+
// memory than the arena contains in zone 0, subsequent zones are allocated
|
92
|
+
// on demand and maintained in a tail-linked list.
|
93
|
+
//
|
94
|
+
// initial_alloc: Optionally, construct the arena as though a call to
|
95
|
+
// Alloc() had already been made for initial_alloc bytes. This provides a
|
96
|
+
// quick optimization (avoiding an atomic fetch-add) for the common case
|
97
|
+
// where we wish to create an arena and then perform an immediate
|
98
|
+
// allocation.
|
99
|
+
explicit Arena(size_t initial_size, size_t initial_alloc = 0)
|
100
|
+
: total_used_(initial_alloc), initial_zone_size_(initial_size) {}
|
101
|
+
|
102
|
+
~Arena();
|
103
|
+
|
104
|
+
void* AllocZone(size_t size);
|
105
|
+
|
106
|
+
// Keep track of the total used size. We use this in our call sizing
|
107
|
+
// hysteresis.
|
108
|
+
Atomic<size_t> total_used_;
|
109
|
+
size_t initial_zone_size_;
|
110
|
+
gpr_spinlock arena_growth_spinlock_ = GPR_SPINLOCK_STATIC_INITIALIZER;
|
111
|
+
// If the initial arena allocation wasn't enough, we allocate additional zones
|
112
|
+
// in a reverse linked list. Each additional zone consists of (1) a pointer to
|
113
|
+
// the zone added before this zone (null if this is the first additional zone)
|
114
|
+
// and (2) the allocated memory. The arena itself maintains a pointer to the
|
115
|
+
// last zone; the zone list is reverse-walked during arena destruction only.
|
116
|
+
Zone* last_zone_ = nullptr;
|
117
|
+
};
|
118
|
+
|
119
|
+
} // namespace grpc_core
|
120
|
+
|
121
|
+
#endif /* GRPC_CORE_LIB_GPRPP_ARENA_H */
|
data/src/core/lib/gprpp/atomic.h
CHANGED
@@ -21,10 +21,80 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
27
|
-
|
28
|
-
|
24
|
+
#include <atomic>
|
25
|
+
|
26
|
+
#include <grpc/support/atm.h>
|
27
|
+
|
28
|
+
namespace grpc_core {
|
29
|
+
|
30
|
+
enum class MemoryOrder {
|
31
|
+
RELAXED = std::memory_order_relaxed,
|
32
|
+
CONSUME = std::memory_order_consume,
|
33
|
+
ACQUIRE = std::memory_order_acquire,
|
34
|
+
RELEASE = std::memory_order_release,
|
35
|
+
ACQ_REL = std::memory_order_acq_rel,
|
36
|
+
SEQ_CST = std::memory_order_seq_cst
|
37
|
+
};
|
38
|
+
|
39
|
+
template <typename T>
|
40
|
+
class Atomic {
|
41
|
+
public:
|
42
|
+
explicit Atomic(T val = T()) : storage_(val) {}
|
43
|
+
|
44
|
+
T Load(MemoryOrder order) const {
|
45
|
+
return storage_.load(static_cast<std::memory_order>(order));
|
46
|
+
}
|
47
|
+
|
48
|
+
void Store(T val, MemoryOrder order) {
|
49
|
+
storage_.store(val, static_cast<std::memory_order>(order));
|
50
|
+
}
|
51
|
+
|
52
|
+
bool CompareExchangeWeak(T* expected, T desired, MemoryOrder success,
|
53
|
+
MemoryOrder failure) {
|
54
|
+
return GPR_ATM_INC_CAS_THEN(storage_.compare_exchange_weak(
|
55
|
+
*expected, desired, static_cast<std::memory_order>(success),
|
56
|
+
static_cast<std::memory_order>(failure)));
|
57
|
+
}
|
58
|
+
|
59
|
+
bool CompareExchangeStrong(T* expected, T desired, MemoryOrder success,
|
60
|
+
MemoryOrder failure) {
|
61
|
+
return GPR_ATM_INC_CAS_THEN(storage_.compare_exchange_strong(
|
62
|
+
*expected, desired, static_cast<std::memory_order>(success),
|
63
|
+
static_cast<std::memory_order>(failure)));
|
64
|
+
}
|
65
|
+
|
66
|
+
template <typename Arg>
|
67
|
+
T FetchAdd(Arg arg, MemoryOrder order = MemoryOrder::SEQ_CST) {
|
68
|
+
return GPR_ATM_INC_ADD_THEN(storage_.fetch_add(
|
69
|
+
static_cast<Arg>(arg), static_cast<std::memory_order>(order)));
|
70
|
+
}
|
71
|
+
|
72
|
+
template <typename Arg>
|
73
|
+
T FetchSub(Arg arg, MemoryOrder order = MemoryOrder::SEQ_CST) {
|
74
|
+
return GPR_ATM_INC_ADD_THEN(storage_.fetch_sub(
|
75
|
+
static_cast<Arg>(arg), static_cast<std::memory_order>(order)));
|
76
|
+
}
|
77
|
+
|
78
|
+
// Atomically increment a counter only if the counter value is not zero.
|
79
|
+
// Returns true if increment took place; false if counter is zero.
|
80
|
+
bool IncrementIfNonzero(MemoryOrder load_order = MemoryOrder::ACQUIRE) {
|
81
|
+
T count = storage_.load(static_cast<std::memory_order>(load_order));
|
82
|
+
do {
|
83
|
+
// If zero, we are done (without an increment). If not, we must do a CAS
|
84
|
+
// to maintain the contract: do not increment the counter if it is already
|
85
|
+
// zero
|
86
|
+
if (count == 0) {
|
87
|
+
return false;
|
88
|
+
}
|
89
|
+
} while (!CompareExchangeWeak(&count, count + 1, MemoryOrder::ACQ_REL,
|
90
|
+
load_order));
|
91
|
+
return true;
|
92
|
+
}
|
93
|
+
|
94
|
+
private:
|
95
|
+
std::atomic<T> storage_;
|
96
|
+
};
|
97
|
+
|
98
|
+
} // namespace grpc_core
|
29
99
|
|
30
100
|
#endif /* GRPC_CORE_LIB_GPRPP_ATOMIC_H */
|
data/src/core/lib/gprpp/fork.cc
CHANGED
@@ -26,8 +26,8 @@
|
|
26
26
|
#include <grpc/support/sync.h>
|
27
27
|
#include <grpc/support/time.h>
|
28
28
|
|
29
|
-
#include "src/core/lib/gpr/env.h"
|
30
29
|
#include "src/core/lib/gpr/useful.h"
|
30
|
+
#include "src/core/lib/gprpp/global_config.h"
|
31
31
|
#include "src/core/lib/gprpp/memory.h"
|
32
32
|
|
33
33
|
/*
|
@@ -35,6 +35,16 @@
|
|
35
35
|
* AROUND VERY SPECIFIC USE CASES.
|
36
36
|
*/
|
37
37
|
|
38
|
+
#ifdef GRPC_ENABLE_FORK_SUPPORT
|
39
|
+
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT true
|
40
|
+
#else
|
41
|
+
#define GRPC_ENABLE_FORK_SUPPORT_DEFAULT false
|
42
|
+
#endif // GRPC_ENABLE_FORK_SUPPORT
|
43
|
+
|
44
|
+
GPR_GLOBAL_CONFIG_DEFINE_BOOL(grpc_enable_fork_support,
|
45
|
+
GRPC_ENABLE_FORK_SUPPORT_DEFAULT,
|
46
|
+
"Enable folk support");
|
47
|
+
|
38
48
|
namespace grpc_core {
|
39
49
|
namespace internal {
|
40
50
|
// The exec_ctx_count has 2 modes, blocked and unblocked.
|
@@ -158,36 +168,7 @@ class ThreadState {
|
|
158
168
|
|
159
169
|
void Fork::GlobalInit() {
|
160
170
|
if (!override_enabled_) {
|
161
|
-
|
162
|
-
support_enabled_ = true;
|
163
|
-
#else
|
164
|
-
support_enabled_ = false;
|
165
|
-
#endif
|
166
|
-
bool env_var_set = false;
|
167
|
-
char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
|
168
|
-
if (env != nullptr) {
|
169
|
-
static const char* truthy[] = {"yes", "Yes", "YES", "true",
|
170
|
-
"True", "TRUE", "1"};
|
171
|
-
static const char* falsey[] = {"no", "No", "NO", "false",
|
172
|
-
"False", "FALSE", "0"};
|
173
|
-
for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
|
174
|
-
if (0 == strcmp(env, truthy[i])) {
|
175
|
-
support_enabled_ = true;
|
176
|
-
env_var_set = true;
|
177
|
-
break;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
if (!env_var_set) {
|
181
|
-
for (size_t i = 0; i < GPR_ARRAY_SIZE(falsey); i++) {
|
182
|
-
if (0 == strcmp(env, falsey[i])) {
|
183
|
-
support_enabled_ = false;
|
184
|
-
env_var_set = true;
|
185
|
-
break;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
}
|
189
|
-
gpr_free(env);
|
190
|
-
}
|
171
|
+
support_enabled_ = GPR_GLOBAL_CONFIG_GET(grpc_enable_fork_support);
|
191
172
|
}
|
192
173
|
if (support_enabled_) {
|
193
174
|
exec_ctx_state_ = grpc_core::New<internal::ExecCtxState>();
|
@@ -262,7 +243,7 @@ void Fork::AwaitThreads() {
|
|
262
243
|
|
263
244
|
internal::ExecCtxState* Fork::exec_ctx_state_ = nullptr;
|
264
245
|
internal::ThreadState* Fork::thread_state_ = nullptr;
|
265
|
-
bool Fork::support_enabled_
|
246
|
+
std::atomic<bool> Fork::support_enabled_;
|
266
247
|
bool Fork::override_enabled_ = false;
|
267
248
|
Fork::child_postfork_func Fork::reset_child_polling_engine_ = nullptr;
|
268
249
|
} // namespace grpc_core
|
data/src/core/lib/gprpp/fork.h
CHANGED
@@ -19,6 +19,10 @@
|
|
19
19
|
#ifndef GRPC_CORE_LIB_GPRPP_FORK_H
|
20
20
|
#define GRPC_CORE_LIB_GPRPP_FORK_H
|
21
21
|
|
22
|
+
#include <grpc/support/port_platform.h>
|
23
|
+
|
24
|
+
#include <atomic>
|
25
|
+
|
22
26
|
/*
|
23
27
|
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
|
24
28
|
* AROUND VERY SPECIFIC USE CASES.
|
@@ -78,7 +82,7 @@ class Fork {
|
|
78
82
|
private:
|
79
83
|
static internal::ExecCtxState* exec_ctx_state_;
|
80
84
|
static internal::ThreadState* thread_state_;
|
81
|
-
static bool support_enabled_;
|
85
|
+
static std::atomic<bool> support_enabled_;
|
82
86
|
static bool override_enabled_;
|
83
87
|
static child_postfork_func reset_child_polling_engine_;
|
84
88
|
};
|