wearefair-grpc 1.3.1.pre.a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/Makefile +19484 -0
- data/etc/roots.pem +5288 -0
- data/include/grpc/byte_buffer.h +102 -0
- data/include/grpc/byte_buffer_reader.h +39 -0
- data/include/grpc/census.h +484 -0
- data/include/grpc/compression.h +85 -0
- data/include/grpc/grpc.h +509 -0
- data/include/grpc/grpc_cronet.h +51 -0
- data/include/grpc/grpc_posix.h +81 -0
- data/include/grpc/grpc_security.h +390 -0
- data/include/grpc/grpc_security_constants.h +114 -0
- data/include/grpc/impl/codegen/atm.h +100 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +97 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +97 -0
- data/include/grpc/impl/codegen/atm_windows.h +140 -0
- data/include/grpc/impl/codegen/byte_buffer_reader.h +57 -0
- data/include/grpc/impl/codegen/compression_types.h +122 -0
- data/include/grpc/impl/codegen/connectivity_state.h +61 -0
- data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
- data/include/grpc/impl/codegen/gpr_slice.h +84 -0
- data/include/grpc/impl/codegen/gpr_types.h +75 -0
- data/include/grpc/impl/codegen/grpc_types.h +550 -0
- data/include/grpc/impl/codegen/port_platform.h +421 -0
- data/include/grpc/impl/codegen/propagation_bits.h +67 -0
- data/include/grpc/impl/codegen/slice.h +157 -0
- data/include/grpc/impl/codegen/status.h +163 -0
- data/include/grpc/impl/codegen/sync.h +75 -0
- data/include/grpc/impl/codegen/sync_generic.h +55 -0
- data/include/grpc/impl/codegen/sync_posix.h +47 -0
- data/include/grpc/impl/codegen/sync_windows.h +49 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/module.modulemap +13 -0
- data/include/grpc/slice.h +168 -0
- data/include/grpc/slice_buffer.h +94 -0
- data/include/grpc/status.h +39 -0
- data/include/grpc/support/alloc.h +82 -0
- data/include/grpc/support/atm.h +39 -0
- data/include/grpc/support/atm_gcc_atomic.h +39 -0
- data/include/grpc/support/atm_gcc_sync.h +39 -0
- data/include/grpc/support/atm_windows.h +39 -0
- data/include/grpc/support/avl.h +97 -0
- data/include/grpc/support/cmdline.h +103 -0
- data/include/grpc/support/cpu.h +59 -0
- data/include/grpc/support/histogram.h +79 -0
- data/include/grpc/support/host_port.h +66 -0
- data/include/grpc/support/log.h +118 -0
- data/include/grpc/support/log_windows.h +53 -0
- data/include/grpc/support/port_platform.h +39 -0
- data/include/grpc/support/string_util.h +64 -0
- data/include/grpc/support/subprocess.h +59 -0
- data/include/grpc/support/sync.h +295 -0
- data/include/grpc/support/sync_generic.h +39 -0
- data/include/grpc/support/sync_posix.h +39 -0
- data/include/grpc/support/sync_windows.h +39 -0
- data/include/grpc/support/thd.h +91 -0
- data/include/grpc/support/time.h +105 -0
- data/include/grpc/support/tls.h +77 -0
- data/include/grpc/support/tls_gcc.h +100 -0
- data/include/grpc/support/tls_msvc.h +56 -0
- data/include/grpc/support/tls_pthread.h +60 -0
- data/include/grpc/support/useful.h +80 -0
- data/src/boringssl/err_data.c +1270 -0
- data/src/core/ext/census/aggregation.h +66 -0
- data/src/core/ext/census/base_resources.c +71 -0
- data/src/core/ext/census/base_resources.h +39 -0
- data/src/core/ext/census/census_interface.h +76 -0
- data/src/core/ext/census/census_rpc_stats.h +101 -0
- data/src/core/ext/census/context.c +509 -0
- data/src/core/ext/census/gen/census.pb.c +176 -0
- data/src/core/ext/census/gen/census.pb.h +295 -0
- data/src/core/ext/census/gen/trace_context.pb.c +54 -0
- data/src/core/ext/census/gen/trace_context.pb.h +93 -0
- data/src/core/ext/census/grpc_context.c +53 -0
- data/src/core/ext/census/grpc_filter.c +213 -0
- data/src/core/ext/census/grpc_filter.h +44 -0
- data/src/core/ext/census/grpc_plugin.c +85 -0
- data/src/core/ext/census/initialize.c +66 -0
- data/src/core/ext/census/mlog.c +600 -0
- data/src/core/ext/census/mlog.h +95 -0
- data/src/core/ext/census/operation.c +63 -0
- data/src/core/ext/census/placeholders.c +64 -0
- data/src/core/ext/census/resource.c +312 -0
- data/src/core/ext/census/resource.h +63 -0
- data/src/core/ext/census/rpc_metric_id.h +51 -0
- data/src/core/ext/census/trace_context.c +86 -0
- data/src/core/ext/census/trace_context.h +71 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +71 -0
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.c +226 -0
- data/src/core/ext/filters/client_channel/client_channel.c +1410 -0
- data/src/core/ext/filters/client_channel/client_channel.h +64 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.c +87 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.h +92 -0
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +106 -0
- data/src/core/ext/filters/client_channel/connector.c +55 -0
- data/src/core/ext/filters/client_channel/connector.h +88 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +389 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +49 -0
- data/src/core/ext/filters/client_channel/http_proxy.c +125 -0
- data/src/core/ext/filters/client_channel/http_proxy.h +39 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +1419 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +44 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +57 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +249 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +105 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +88 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +158 -0
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +476 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +795 -0
- data/src/core/ext/filters/client_channel/lb_policy.c +167 -0
- data/src/core/ext/filters/client_channel/lb_policy.h +209 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +163 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +134 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.c +85 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +55 -0
- data/src/core/ext/filters/client_channel/parse_address.c +170 -0
- data/src/core/ext/filters/client_channel/parse_address.h +54 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +139 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c +325 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +234 -0
- data/src/core/ext/filters/client_channel/resolver.c +88 -0
- data/src/core/ext/filters/client_channel/resolver.h +101 -0
- data/src/core/ext/filters/client_channel/resolver_factory.c +56 -0
- data/src/core/ext/filters/client_channel/resolver_factory.h +85 -0
- data/src/core/ext/filters/client_channel/resolver_registry.c +174 -0
- data/src/core/ext/filters/client_channel/resolver_registry.h +84 -0
- data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
- data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
- data/src/core/ext/filters/client_channel/subchannel.c +835 -0
- data/src/core/ext/filters/client_channel/subchannel.h +203 -0
- data/src/core/ext/filters/client_channel/subchannel_index.c +262 -0
- data/src/core/ext/filters/client_channel/subchannel_index.h +77 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +315 -0
- data/src/core/ext/filters/client_channel/uri_parser.h +65 -0
- data/src/core/ext/filters/load_reporting/load_reporting.c +106 -0
- data/src/core/ext/filters/load_reporting/load_reporting.h +73 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +218 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.h +42 -0
- data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.c +56 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +49 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +221 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +41 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +121 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +239 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +304 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +59 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +90 -0
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +101 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +236 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +67 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +241 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +54 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +43 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +2847 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +53 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +61 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.c +287 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.h +104 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +198 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +78 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +145 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +59 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +125 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +58 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +239 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +76 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +134 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +57 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +661 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +107 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +1734 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +129 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +383 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +112 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.c +105 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +48 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +88 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +63 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +852 -0
- data/src/core/ext/transport/chttp2/transport/parsing.c +825 -0
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +194 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.c +176 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.h +83 -0
- data/src/core/ext/transport/chttp2/transport/varint.c +65 -0
- data/src/core/ext/transport/chttp2/transport/varint.h +75 -0
- data/src/core/ext/transport/chttp2/transport/writing.c +429 -0
- data/src/core/lib/channel/channel_args.c +355 -0
- data/src/core/lib/channel/channel_args.h +126 -0
- data/src/core/lib/channel/channel_stack.c +291 -0
- data/src/core/lib/channel/channel_stack.h +319 -0
- data/src/core/lib/channel/channel_stack_builder.c +284 -0
- data/src/core/lib/channel/channel_stack_builder.h +170 -0
- data/src/core/lib/channel/compress_filter.c +353 -0
- data/src/core/lib/channel/compress_filter.h +67 -0
- data/src/core/lib/channel/connected_channel.c +188 -0
- data/src/core/lib/channel/connected_channel.h +48 -0
- data/src/core/lib/channel/context.h +64 -0
- data/src/core/lib/channel/deadline_filter.c +348 -0
- data/src/core/lib/channel/deadline_filter.h +102 -0
- data/src/core/lib/channel/handshaker.c +281 -0
- data/src/core/lib/channel/handshaker.h +182 -0
- data/src/core/lib/channel/handshaker_factory.c +54 -0
- data/src/core/lib/channel/handshaker_factory.h +66 -0
- data/src/core/lib/channel/handshaker_registry.c +113 -0
- data/src/core/lib/channel/handshaker_registry.h +63 -0
- data/src/core/lib/channel/http_client_filter.c +601 -0
- data/src/core/lib/channel/http_client_filter.h +47 -0
- data/src/core/lib/channel/http_server_filter.c +445 -0
- data/src/core/lib/channel/http_server_filter.h +42 -0
- data/src/core/lib/channel/message_size_filter.c +270 -0
- data/src/core/lib/channel/message_size_filter.h +39 -0
- data/src/core/lib/compression/algorithm_metadata.h +53 -0
- data/src/core/lib/compression/compression.c +198 -0
- data/src/core/lib/compression/message_compress.c +204 -0
- data/src/core/lib/compression/message_compress.h +54 -0
- data/src/core/lib/debug/trace.c +140 -0
- data/src/core/lib/debug/trace.h +43 -0
- data/src/core/lib/http/format_request.c +135 -0
- data/src/core/lib/http/format_request.h +47 -0
- data/src/core/lib/http/httpcli.c +336 -0
- data/src/core/lib/http/httpcli.h +141 -0
- data/src/core/lib/http/httpcli_security_connector.c +199 -0
- data/src/core/lib/http/parser.c +379 -0
- data/src/core/lib/http/parser.h +126 -0
- data/src/core/lib/iomgr/closure.c +168 -0
- data/src/core/lib/iomgr/closure.h +153 -0
- data/src/core/lib/iomgr/combiner.c +460 -0
- data/src/core/lib/iomgr/combiner.h +83 -0
- data/src/core/lib/iomgr/endpoint.c +78 -0
- data/src/core/lib/iomgr/endpoint.h +117 -0
- data/src/core/lib/iomgr/endpoint_pair.h +47 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.c +87 -0
- data/src/core/lib/iomgr/endpoint_pair_uv.c +53 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.c +101 -0
- data/src/core/lib/iomgr/error.c +793 -0
- data/src/core/lib/iomgr/error.h +218 -0
- data/src/core/lib/iomgr/error_internal.h +75 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +1965 -0
- data/src/core/lib/iomgr/ev_epoll_linux.h +48 -0
- data/src/core/lib/iomgr/ev_poll_posix.c +1593 -0
- data/src/core/lib/iomgr/ev_poll_posix.h +42 -0
- data/src/core/lib/iomgr/ev_posix.c +287 -0
- data/src/core/lib/iomgr/ev_posix.h +189 -0
- data/src/core/lib/iomgr/exec_ctx.c +117 -0
- data/src/core/lib/iomgr/exec_ctx.h +117 -0
- data/src/core/lib/iomgr/executor.c +170 -0
- data/src/core/lib/iomgr/executor.h +51 -0
- data/src/core/lib/iomgr/iocp_windows.c +168 -0
- data/src/core/lib/iomgr/iocp_windows.h +55 -0
- data/src/core/lib/iomgr/iomgr.c +183 -0
- data/src/core/lib/iomgr/iomgr.h +47 -0
- data/src/core/lib/iomgr/iomgr_internal.h +58 -0
- data/src/core/lib/iomgr/iomgr_posix.c +56 -0
- data/src/core/lib/iomgr/iomgr_posix.h +39 -0
- data/src/core/lib/iomgr/iomgr_uv.c +49 -0
- data/src/core/lib/iomgr/iomgr_windows.c +76 -0
- data/src/core/lib/iomgr/load_file.c +92 -0
- data/src/core/lib/iomgr/load_file.h +56 -0
- data/src/core/lib/iomgr/lockfree_event.c +238 -0
- data/src/core/lib/iomgr/lockfree_event.h +54 -0
- data/src/core/lib/iomgr/network_status_tracker.c +48 -0
- data/src/core/lib/iomgr/network_status_tracker.h +45 -0
- data/src/core/lib/iomgr/polling_entity.c +104 -0
- data/src/core/lib/iomgr/polling_entity.h +81 -0
- data/src/core/lib/iomgr/pollset.h +97 -0
- data/src/core/lib/iomgr/pollset_set.h +62 -0
- data/src/core/lib/iomgr/pollset_set_uv.c +63 -0
- data/src/core/lib/iomgr/pollset_set_windows.c +64 -0
- data/src/core/lib/iomgr/pollset_set_windows.h +39 -0
- data/src/core/lib/iomgr/pollset_uv.c +156 -0
- data/src/core/lib/iomgr/pollset_uv.h +42 -0
- data/src/core/lib/iomgr/pollset_windows.c +232 -0
- data/src/core/lib/iomgr/pollset_windows.h +78 -0
- data/src/core/lib/iomgr/port.h +138 -0
- data/src/core/lib/iomgr/resolve_address.h +70 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +207 -0
- data/src/core/lib/iomgr/resolve_address_uv.c +284 -0
- data/src/core/lib/iomgr/resolve_address_windows.c +190 -0
- data/src/core/lib/iomgr/resource_quota.c +877 -0
- data/src/core/lib/iomgr/resource_quota.h +167 -0
- data/src/core/lib/iomgr/sockaddr.h +55 -0
- data/src/core/lib/iomgr/sockaddr_posix.h +44 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +272 -0
- data/src/core/lib/iomgr/sockaddr_utils.h +93 -0
- data/src/core/lib/iomgr/sockaddr_windows.h +43 -0
- data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
- data/src/core/lib/iomgr/socket_mutator.c +98 -0
- data/src/core/lib/iomgr/socket_mutator.h +80 -0
- data/src/core/lib/iomgr/socket_utils.h +42 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +330 -0
- data/src/core/lib/iomgr/socket_utils_linux.c +57 -0
- data/src/core/lib/iomgr/socket_utils_posix.c +73 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +147 -0
- data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
- data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
- data/src/core/lib/iomgr/socket_windows.c +167 -0
- data/src/core/lib/iomgr/socket_windows.h +125 -0
- data/src/core/lib/iomgr/tcp_client.h +55 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +368 -0
- data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
- data/src/core/lib/iomgr/tcp_client_uv.c +192 -0
- data/src/core/lib/iomgr/tcp_client_windows.c +260 -0
- data/src/core/lib/iomgr/tcp_posix.c +677 -0
- data/src/core/lib/iomgr/tcp_posix.h +70 -0
- data/src/core/lib/iomgr/tcp_server.h +116 -0
- data/src/core/lib/iomgr/tcp_server_posix.c +579 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
- data/src/core/lib/iomgr/tcp_server_uv.c +393 -0
- data/src/core/lib/iomgr/tcp_server_windows.c +558 -0
- data/src/core/lib/iomgr/tcp_uv.c +374 -0
- data/src/core/lib/iomgr/tcp_uv.h +59 -0
- data/src/core/lib/iomgr/tcp_windows.c +462 -0
- data/src/core/lib/iomgr/tcp_windows.h +59 -0
- data/src/core/lib/iomgr/time_averaged_stats.c +77 -0
- data/src/core/lib/iomgr/time_averaged_stats.h +88 -0
- data/src/core/lib/iomgr/timer.h +111 -0
- data/src/core/lib/iomgr/timer_generic.c +567 -0
- data/src/core/lib/iomgr/timer_generic.h +49 -0
- data/src/core/lib/iomgr/timer_heap.c +152 -0
- data/src/core/lib/iomgr/timer_heap.h +57 -0
- data/src/core/lib/iomgr/timer_uv.c +103 -0
- data/src/core/lib/iomgr/timer_uv.h +47 -0
- data/src/core/lib/iomgr/udp_server.c +529 -0
- data/src/core/lib/iomgr/udp_server.h +89 -0
- data/src/core/lib/iomgr/unix_sockets_posix.c +108 -0
- data/src/core/lib/iomgr/unix_sockets_posix.h +56 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +62 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
- data/src/core/lib/iomgr/wakeup_fd_eventfd.c +97 -0
- data/src/core/lib/iomgr/wakeup_fd_nospecial.c +51 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.c +112 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.h +41 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.c +101 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.h +109 -0
- data/src/core/lib/iomgr/workqueue.h +87 -0
- data/src/core/lib/iomgr/workqueue_uv.c +65 -0
- data/src/core/lib/iomgr/workqueue_uv.h +37 -0
- data/src/core/lib/iomgr/workqueue_windows.c +63 -0
- data/src/core/lib/iomgr/workqueue_windows.h +37 -0
- data/src/core/lib/json/json.c +63 -0
- data/src/core/lib/json/json.h +88 -0
- data/src/core/lib/json/json_common.h +49 -0
- data/src/core/lib/json/json_reader.c +675 -0
- data/src/core/lib/json/json_reader.h +160 -0
- data/src/core/lib/json/json_string.c +379 -0
- data/src/core/lib/json/json_writer.c +258 -0
- data/src/core/lib/json/json_writer.h +97 -0
- data/src/core/lib/profiling/basic_timers.c +298 -0
- data/src/core/lib/profiling/stap_timers.c +65 -0
- data/src/core/lib/profiling/timers.h +121 -0
- data/src/core/lib/security/context/security_context.c +350 -0
- data/src/core/lib/security/context/security_context.h +134 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.c +274 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
- data/src/core/lib/security/credentials/credentials.c +308 -0
- data/src/core/lib/security/credentials/credentials.h +268 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +103 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.c +141 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +71 -0
- data/src/core/lib/security/credentials/google_default/credentials_generic.c +54 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +337 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +60 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
- data/src/core/lib/security/credentials/jwt/json_token.c +321 -0
- data/src/core/lib/security/credentials/jwt/json_token.h +88 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +195 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +63 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +910 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +140 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +468 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +153 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +242 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
- data/src/core/lib/security/transport/auth_filters.h +42 -0
- data/src/core/lib/security/transport/client_auth_filter.c +384 -0
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +427 -0
- data/src/core/lib/security/transport/secure_endpoint.h +49 -0
- data/src/core/lib/security/transport/security_connector.c +909 -0
- data/src/core/lib/security/transport/security_connector.h +252 -0
- data/src/core/lib/security/transport/security_handshaker.c +507 -0
- data/src/core/lib/security/transport/security_handshaker.h +49 -0
- data/src/core/lib/security/transport/server_auth_filter.c +277 -0
- data/src/core/lib/security/transport/tsi_error.c +42 -0
- data/src/core/lib/security/transport/tsi_error.h +42 -0
- data/src/core/lib/security/util/json_util.c +61 -0
- data/src/core/lib/security/util/json_util.h +55 -0
- data/src/core/lib/slice/b64.c +251 -0
- data/src/core/lib/slice/b64.h +65 -0
- data/src/core/lib/slice/percent_encoding.c +182 -0
- data/src/core/lib/slice/percent_encoding.h +78 -0
- data/src/core/lib/slice/slice.c +466 -0
- data/src/core/lib/slice/slice_buffer.c +355 -0
- data/src/core/lib/slice/slice_hash_table.c +125 -0
- data/src/core/lib/slice/slice_hash_table.h +77 -0
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +64 -0
- data/src/core/lib/slice/slice_string_helpers.c +95 -0
- data/src/core/lib/slice/slice_string_helpers.h +63 -0
- data/src/core/lib/support/alloc.c +117 -0
- data/src/core/lib/support/arena.c +98 -0
- data/src/core/lib/support/arena.h +54 -0
- data/src/core/lib/support/atm.c +47 -0
- data/src/core/lib/support/avl.c +299 -0
- data/src/core/lib/support/backoff.c +87 -0
- data/src/core/lib/support/backoff.h +71 -0
- data/src/core/lib/support/block_annotate.h +48 -0
- data/src/core/lib/support/cmdline.c +345 -0
- data/src/core/lib/support/cpu_iphone.c +49 -0
- data/src/core/lib/support/cpu_linux.c +83 -0
- data/src/core/lib/support/cpu_posix.c +72 -0
- data/src/core/lib/support/cpu_windows.c +47 -0
- data/src/core/lib/support/env.h +58 -0
- data/src/core/lib/support/env_linux.c +89 -0
- data/src/core/lib/support/env_posix.c +57 -0
- data/src/core/lib/support/env_windows.c +79 -0
- data/src/core/lib/support/histogram.c +243 -0
- data/src/core/lib/support/host_port.c +110 -0
- data/src/core/lib/support/log.c +103 -0
- data/src/core/lib/support/log_android.c +87 -0
- data/src/core/lib/support/log_linux.c +105 -0
- data/src/core/lib/support/log_posix.c +106 -0
- data/src/core/lib/support/log_windows.c +112 -0
- data/src/core/lib/support/mpscq.c +83 -0
- data/src/core/lib/support/mpscq.h +65 -0
- data/src/core/lib/support/murmur_hash.c +94 -0
- data/src/core/lib/support/murmur_hash.h +44 -0
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/stack_lockfree.c +185 -0
- data/src/core/lib/support/stack_lockfree.h +53 -0
- data/src/core/lib/support/string.c +315 -0
- data/src/core/lib/support/string.h +128 -0
- data/src/core/lib/support/string_posix.c +86 -0
- data/src/core/lib/support/string_util_windows.c +94 -0
- data/src/core/lib/support/string_windows.c +83 -0
- data/src/core/lib/support/string_windows.h +47 -0
- data/src/core/lib/support/subprocess_posix.c +114 -0
- data/src/core/lib/support/subprocess_windows.c +141 -0
- data/src/core/lib/support/sync.c +137 -0
- data/src/core/lib/support/sync_posix.c +113 -0
- data/src/core/lib/support/sync_windows.c +133 -0
- data/src/core/lib/support/thd.c +64 -0
- data/src/core/lib/support/thd_internal.h +39 -0
- data/src/core/lib/support/thd_posix.c +95 -0
- data/src/core/lib/support/thd_windows.c +117 -0
- data/src/core/lib/support/time.c +262 -0
- data/src/core/lib/support/time_posix.c +176 -0
- data/src/core/lib/support/time_precise.c +89 -0
- data/src/core/lib/support/time_precise.h +42 -0
- data/src/core/lib/support/time_windows.c +116 -0
- data/src/core/lib/support/tls_pthread.c +45 -0
- data/src/core/lib/support/tmpfile.h +53 -0
- data/src/core/lib/support/tmpfile_msys.c +73 -0
- data/src/core/lib/support/tmpfile_posix.c +85 -0
- data/src/core/lib/support/tmpfile_windows.c +84 -0
- data/src/core/lib/support/wrap_memcpy.c +55 -0
- data/src/core/lib/surface/alarm.c +87 -0
- data/src/core/lib/surface/api_trace.c +36 -0
- data/src/core/lib/surface/api_trace.h +65 -0
- data/src/core/lib/surface/byte_buffer.c +103 -0
- data/src/core/lib/surface/byte_buffer_reader.c +140 -0
- data/src/core/lib/surface/call.c +1835 -0
- data/src/core/lib/surface/call.h +135 -0
- data/src/core/lib/surface/call_details.c +56 -0
- data/src/core/lib/surface/call_log_batch.c +131 -0
- data/src/core/lib/surface/call_test_only.h +64 -0
- data/src/core/lib/surface/channel.c +434 -0
- data/src/core/lib/surface/channel.h +99 -0
- data/src/core/lib/surface/channel_init.c +140 -0
- data/src/core/lib/surface/channel_init.h +96 -0
- data/src/core/lib/surface/channel_ping.c +80 -0
- data/src/core/lib/surface/channel_stack_type.c +54 -0
- data/src/core/lib/surface/channel_stack_type.h +58 -0
- data/src/core/lib/surface/completion_queue.c +692 -0
- data/src/core/lib/surface/completion_queue.h +102 -0
- data/src/core/lib/surface/completion_queue_factory.c +77 -0
- data/src/core/lib/surface/completion_queue_factory.h +51 -0
- data/src/core/lib/surface/event_string.c +81 -0
- data/src/core/lib/surface/event_string.h +42 -0
- data/src/core/lib/surface/init.c +261 -0
- data/src/core/lib/surface/init.h +42 -0
- data/src/core/lib/surface/init_secure.c +94 -0
- data/src/core/lib/surface/lame_client.c +188 -0
- data/src/core/lib/surface/lame_client.h +41 -0
- data/src/core/lib/surface/metadata_array.c +49 -0
- data/src/core/lib/surface/server.c +1529 -0
- data/src/core/lib/surface/server.h +71 -0
- data/src/core/lib/surface/validate_metadata.c +108 -0
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +41 -0
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/byte_stream.c +81 -0
- data/src/core/lib/transport/byte_stream.h +85 -0
- data/src/core/lib/transport/connectivity_state.c +219 -0
- data/src/core/lib/transport/connectivity_state.h +101 -0
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/lib/transport/http2_errors.h +56 -0
- data/src/core/lib/transport/metadata.c +529 -0
- data/src/core/lib/transport/metadata.h +186 -0
- data/src/core/lib/transport/metadata_batch.c +328 -0
- data/src/core/lib/transport/metadata_batch.h +166 -0
- data/src/core/lib/transport/pid_controller.c +78 -0
- data/src/core/lib/transport/pid_controller.h +77 -0
- data/src/core/lib/transport/service_config.c +266 -0
- data/src/core/lib/transport/service_config.h +77 -0
- data/src/core/lib/transport/static_metadata.c +801 -0
- data/src/core/lib/transport/static_metadata.h +557 -0
- data/src/core/lib/transport/status_conversion.c +113 -0
- data/src/core/lib/transport/status_conversion.h +49 -0
- data/src/core/lib/transport/timeout_encoding.c +190 -0
- data/src/core/lib/transport/timeout_encoding.h +49 -0
- data/src/core/lib/transport/transport.c +282 -0
- data/src/core/lib/transport/transport.h +354 -0
- data/src/core/lib/transport/transport_impl.h +90 -0
- data/src/core/lib/transport/transport_op_string.c +217 -0
- data/src/core/plugin_registry/grpc_plugin_registry.c +82 -0
- data/src/core/tsi/fake_transport_security.c +527 -0
- data/src/core/tsi/fake_transport_security.h +61 -0
- data/src/core/tsi/ssl_transport_security.c +1533 -0
- data/src/core/tsi/ssl_transport_security.h +214 -0
- data/src/core/tsi/ssl_types.h +55 -0
- data/src/core/tsi/transport_security.c +266 -0
- data/src/core/tsi/transport_security.h +111 -0
- data/src/core/tsi/transport_security_interface.h +353 -0
- data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
- data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/src/ruby/bin/math_client.rb +147 -0
- data/src/ruby/bin/math_pb.rb +32 -0
- data/src/ruby/bin/math_server.rb +206 -0
- data/src/ruby/bin/math_services_pb.rb +66 -0
- data/src/ruby/bin/noproto_client.rb +108 -0
- data/src/ruby/bin/noproto_server.rb +112 -0
- data/src/ruby/ext/grpc/extconf.rb +131 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +77 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +50 -0
- data/src/ruby/ext/grpc/rb_call.c +1009 -0
- data/src/ruby/ext/grpc/rb_call.h +66 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +295 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
- data/src/ruby/ext/grpc/rb_channel.c +662 -0
- data/src/ruby/ext/grpc/rb_channel.h +49 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +168 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +117 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +51 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +472 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +44 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
- data/src/ruby/ext/grpc/rb_grpc.c +343 -0
- data/src/ruby/ext/grpc/rb_grpc.h +87 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +634 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +955 -0
- data/src/ruby/ext/grpc/rb_loader.c +72 -0
- data/src/ruby/ext/grpc/rb_loader.h +40 -0
- data/src/ruby/ext/grpc/rb_server.c +359 -0
- data/src/ruby/ext/grpc/rb_server.h +47 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
- data/src/ruby/lib/grpc/errors.rb +215 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +547 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +229 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +463 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +173 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +476 -0
- data/src/ruby/lib/grpc/generic/service.rb +225 -0
- data/src/ruby/lib/grpc/grpc.rb +39 -0
- data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/logconfig.rb +59 -0
- data/src/ruby/lib/grpc/notifier.rb +60 -0
- data/src/ruby/lib/grpc/version.rb +33 -0
- data/src/ruby/lib/grpc.rb +49 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +58 -0
- data/src/ruby/pb/grpc/health/checker.rb +77 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +28 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +56 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +58 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +64 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +15 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +82 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +14 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +117 -0
- data/src/ruby/pb/test/client.rb +779 -0
- data/src/ruby/pb/test/server.rb +267 -0
- data/src/ruby/spec/call_credentials_spec.rb +57 -0
- data/src/ruby/spec/call_spec.rb +162 -0
- data/src/ruby/spec/channel_connection_spec.rb +141 -0
- data/src/ruby/spec/channel_credentials_spec.rb +97 -0
- data/src/ruby/spec/channel_spec.rb +205 -0
- data/src/ruby/spec/client_server_spec.rb +491 -0
- data/src/ruby/spec/compression_options_spec.rb +164 -0
- data/src/ruby/spec/error_sanity_spec.rb +64 -0
- data/src/ruby/spec/generic/active_call_spec.rb +632 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +556 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +351 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +142 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +524 -0
- data/src/ruby/spec/generic/service_spec.rb +276 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +71 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +222 -0
- data/src/ruby/spec/server_credentials_spec.rb +94 -0
- data/src/ruby/spec/server_spec.rb +205 -0
- data/src/ruby/spec/spec_helper.rb +71 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +15 -0
- data/src/ruby/spec/testdata/server1.key +16 -0
- data/src/ruby/spec/testdata/server1.pem +16 -0
- data/src/ruby/spec/time_consts_spec.rb +89 -0
- data/third_party/boringssl/crypto/aes/aes.c +1142 -0
- data/third_party/boringssl/crypto/aes/internal.h +87 -0
- data/third_party/boringssl/crypto/aes/mode_wrappers.c +112 -0
- data/third_party/boringssl/crypto/asn1/a_bitstr.c +263 -0
- data/third_party/boringssl/crypto/asn1/a_bool.c +110 -0
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +282 -0
- data/third_party/boringssl/crypto/asn1/a_dup.c +111 -0
- data/third_party/boringssl/crypto/asn1/a_enum.c +181 -0
- data/third_party/boringssl/crypto/asn1/a_gentm.c +256 -0
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +147 -0
- data/third_party/boringssl/crypto/asn1/a_int.c +460 -0
- data/third_party/boringssl/crypto/asn1/a_mbstr.c +409 -0
- data/third_party/boringssl/crypto/asn1/a_object.c +400 -0
- data/third_party/boringssl/crypto/asn1/a_octet.c +77 -0
- data/third_party/boringssl/crypto/asn1/a_print.c +121 -0
- data/third_party/boringssl/crypto/asn1/a_strnid.c +309 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +206 -0
- data/third_party/boringssl/crypto/asn1/a_type.c +151 -0
- data/third_party/boringssl/crypto/asn1/a_utctm.c +304 -0
- data/third_party/boringssl/crypto/asn1/a_utf8.c +234 -0
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +483 -0
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +63 -0
- data/third_party/boringssl/crypto/asn1/asn1_par.c +80 -0
- data/third_party/boringssl/crypto/asn1/asn_pack.c +105 -0
- data/third_party/boringssl/crypto/asn1/f_enum.c +93 -0
- data/third_party/boringssl/crypto/asn1/f_int.c +97 -0
- data/third_party/boringssl/crypto/asn1/f_string.c +91 -0
- data/third_party/boringssl/crypto/asn1/t_bitst.c +103 -0
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +1221 -0
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +665 -0
- data/third_party/boringssl/crypto/asn1/tasn_fre.c +246 -0
- data/third_party/boringssl/crypto/asn1/tasn_new.c +381 -0
- data/third_party/boringssl/crypto/asn1/tasn_typ.c +131 -0
- data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
- data/third_party/boringssl/crypto/asn1/x_bignum.c +153 -0
- data/third_party/boringssl/crypto/asn1/x_long.c +197 -0
- data/third_party/boringssl/crypto/base64/base64.c +442 -0
- data/third_party/boringssl/crypto/bio/bio.c +598 -0
- data/third_party/boringssl/crypto/bio/bio_mem.c +328 -0
- data/third_party/boringssl/crypto/bio/buffer.c +496 -0
- data/third_party/boringssl/crypto/bio/connect.c +553 -0
- data/third_party/boringssl/crypto/bio/fd.c +277 -0
- data/third_party/boringssl/crypto/bio/file.c +313 -0
- data/third_party/boringssl/crypto/bio/hexdump.c +191 -0
- data/third_party/boringssl/crypto/bio/internal.h +111 -0
- data/third_party/boringssl/crypto/bio/pair.c +803 -0
- data/third_party/boringssl/crypto/bio/printf.c +119 -0
- data/third_party/boringssl/crypto/bio/socket.c +203 -0
- data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
- data/third_party/boringssl/crypto/bn/add.c +377 -0
- data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +531 -0
- data/third_party/boringssl/crypto/bn/bn.c +379 -0
- data/third_party/boringssl/crypto/bn/bn_asn1.c +80 -0
- data/third_party/boringssl/crypto/bn/cmp.c +225 -0
- data/third_party/boringssl/crypto/bn/convert.c +599 -0
- data/third_party/boringssl/crypto/bn/ctx.c +311 -0
- data/third_party/boringssl/crypto/bn/div.c +671 -0
- data/third_party/boringssl/crypto/bn/exponentiation.c +1258 -0
- data/third_party/boringssl/crypto/bn/gcd.c +628 -0
- data/third_party/boringssl/crypto/bn/generic.c +703 -0
- data/third_party/boringssl/crypto/bn/internal.h +245 -0
- data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
- data/third_party/boringssl/crypto/bn/montgomery.c +410 -0
- data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
- data/third_party/boringssl/crypto/bn/mul.c +869 -0
- data/third_party/boringssl/crypto/bn/prime.c +861 -0
- data/third_party/boringssl/crypto/bn/random.c +340 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.c +319 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
- data/third_party/boringssl/crypto/bn/shift.c +299 -0
- data/third_party/boringssl/crypto/bn/sqrt.c +504 -0
- data/third_party/boringssl/crypto/buf/buf.c +239 -0
- data/third_party/boringssl/crypto/bytestring/asn1_compat.c +51 -0
- data/third_party/boringssl/crypto/bytestring/ber.c +263 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +473 -0
- data/third_party/boringssl/crypto/bytestring/cbs.c +439 -0
- data/third_party/boringssl/crypto/bytestring/internal.h +75 -0
- data/third_party/boringssl/crypto/chacha/chacha.c +167 -0
- data/third_party/boringssl/crypto/cipher/aead.c +156 -0
- data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
- data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
- data/third_party/boringssl/crypto/cipher/e_aes.c +1717 -0
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +300 -0
- data/third_party/boringssl/crypto/cipher/e_des.c +205 -0
- data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
- data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
- data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
- data/third_party/boringssl/crypto/cipher/e_ssl3.c +403 -0
- data/third_party/boringssl/crypto/cipher/e_tls.c +602 -0
- data/third_party/boringssl/crypto/cipher/internal.h +162 -0
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +553 -0
- data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
- data/third_party/boringssl/crypto/conf/conf.c +788 -0
- data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
- data/third_party/boringssl/crypto/conf/internal.h +31 -0
- data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
- data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
- data/third_party/boringssl/crypto/cpu-arm.c +38 -0
- data/third_party/boringssl/crypto/cpu-intel.c +263 -0
- data/third_party/boringssl/crypto/cpu-ppc64le.c +40 -0
- data/third_party/boringssl/crypto/crypto.c +164 -0
- data/third_party/boringssl/crypto/curve25519/curve25519.c +4944 -0
- data/third_party/boringssl/crypto/curve25519/internal.h +109 -0
- data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +246 -0
- data/third_party/boringssl/crypto/des/des.c +771 -0
- data/third_party/boringssl/crypto/des/internal.h +212 -0
- data/third_party/boringssl/crypto/dh/check.c +218 -0
- data/third_party/boringssl/crypto/dh/dh.c +487 -0
- data/third_party/boringssl/crypto/dh/dh_asn1.c +160 -0
- data/third_party/boringssl/crypto/dh/params.c +253 -0
- data/third_party/boringssl/crypto/digest/digest.c +248 -0
- data/third_party/boringssl/crypto/digest/digests.c +321 -0
- data/third_party/boringssl/crypto/digest/internal.h +112 -0
- data/third_party/boringssl/crypto/digest/md32_common.h +262 -0
- data/third_party/boringssl/crypto/dsa/dsa.c +964 -0
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +339 -0
- data/third_party/boringssl/crypto/ec/ec.c +847 -0
- data/third_party/boringssl/crypto/ec/ec_asn1.c +549 -0
- data/third_party/boringssl/crypto/ec/ec_key.c +479 -0
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +308 -0
- data/third_party/boringssl/crypto/ec/internal.h +276 -0
- data/third_party/boringssl/crypto/ec/oct.c +428 -0
- data/third_party/boringssl/crypto/ec/p224-64.c +1187 -0
- data/third_party/boringssl/crypto/ec/p256-64.c +1741 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9543 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +574 -0
- data/third_party/boringssl/crypto/ec/simple.c +1117 -0
- data/third_party/boringssl/crypto/ec/util-64.c +109 -0
- data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
- data/third_party/boringssl/crypto/ecdh/ecdh.c +159 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +478 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +227 -0
- data/third_party/boringssl/crypto/engine/engine.c +96 -0
- data/third_party/boringssl/crypto/err/err.c +756 -0
- data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
- data/third_party/boringssl/crypto/evp/evp.c +367 -0
- data/third_party/boringssl/crypto/evp/evp_asn1.c +337 -0
- data/third_party/boringssl/crypto/evp/evp_ctx.c +448 -0
- data/third_party/boringssl/crypto/evp/internal.h +237 -0
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +268 -0
- data/third_party/boringssl/crypto/evp/p_ec.c +236 -0
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +257 -0
- data/third_party/boringssl/crypto/evp/p_rsa.c +673 -0
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +200 -0
- data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
- data/third_party/boringssl/crypto/evp/print.c +520 -0
- data/third_party/boringssl/crypto/evp/sign.c +151 -0
- data/third_party/boringssl/crypto/ex_data.c +292 -0
- data/third_party/boringssl/crypto/hkdf/hkdf.c +110 -0
- data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
- data/third_party/boringssl/crypto/internal.h +527 -0
- data/third_party/boringssl/crypto/lhash/lhash.c +342 -0
- data/third_party/boringssl/crypto/md4/md4.c +234 -0
- data/third_party/boringssl/crypto/md5/md5.c +275 -0
- data/third_party/boringssl/crypto/mem.c +200 -0
- data/third_party/boringssl/crypto/modes/cbc.c +216 -0
- data/third_party/boringssl/crypto/modes/cfb.c +230 -0
- data/third_party/boringssl/crypto/modes/ctr.c +219 -0
- data/third_party/boringssl/crypto/modes/gcm.c +1288 -0
- data/third_party/boringssl/crypto/modes/internal.h +358 -0
- data/third_party/boringssl/crypto/modes/ofb.c +95 -0
- data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
- data/third_party/boringssl/crypto/newhope/internal.h +71 -0
- data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
- data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
- data/third_party/boringssl/crypto/newhope/poly.c +183 -0
- data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
- data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
- data/third_party/boringssl/crypto/obj/obj.c +640 -0
- data/third_party/boringssl/crypto/obj/obj_dat.h +5254 -0
- data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
- data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
- data/third_party/boringssl/crypto/pem/pem_all.c +262 -0
- data/third_party/boringssl/crypto/pem/pem_info.c +381 -0
- data/third_party/boringssl/crypto/pem/pem_lib.c +778 -0
- data/third_party/boringssl/crypto/pem/pem_oth.c +88 -0
- data/third_party/boringssl/crypto/pem/pem_pk8.c +257 -0
- data/third_party/boringssl/crypto/pem/pem_pkey.c +227 -0
- data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
- data/third_party/boringssl/crypto/pem/pem_xaux.c +67 -0
- data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +151 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +441 -0
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1219 -0
- data/third_party/boringssl/crypto/poly1305/internal.h +40 -0
- data/third_party/boringssl/crypto/poly1305/poly1305.c +324 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +304 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +890 -0
- data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
- data/third_party/boringssl/crypto/rand/internal.h +32 -0
- data/third_party/boringssl/crypto/rand/rand.c +244 -0
- data/third_party/boringssl/crypto/rand/urandom.c +221 -0
- data/third_party/boringssl/crypto/rand/windows.c +53 -0
- data/third_party/boringssl/crypto/rc4/rc4.c +98 -0
- data/third_party/boringssl/crypto/refcount_c11.c +67 -0
- data/third_party/boringssl/crypto/refcount_lock.c +53 -0
- data/third_party/boringssl/crypto/rsa/blinding.c +264 -0
- data/third_party/boringssl/crypto/rsa/internal.h +148 -0
- data/third_party/boringssl/crypto/rsa/padding.c +708 -0
- data/third_party/boringssl/crypto/rsa/rsa.c +830 -0
- data/third_party/boringssl/crypto/rsa/rsa_asn1.c +446 -0
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +1139 -0
- data/third_party/boringssl/crypto/sha/sha1.c +337 -0
- data/third_party/boringssl/crypto/sha/sha256.c +327 -0
- data/third_party/boringssl/crypto/sha/sha512.c +607 -0
- data/third_party/boringssl/crypto/stack/stack.c +377 -0
- data/third_party/boringssl/crypto/thread.c +110 -0
- data/third_party/boringssl/crypto/thread_none.c +59 -0
- data/third_party/boringssl/crypto/thread_pthread.c +176 -0
- data/third_party/boringssl/crypto/thread_win.c +237 -0
- data/third_party/boringssl/crypto/time_support.c +206 -0
- data/third_party/boringssl/crypto/x509/a_digest.c +96 -0
- data/third_party/boringssl/crypto/x509/a_sign.c +135 -0
- data/third_party/boringssl/crypto/x509/a_strex.c +633 -0
- data/third_party/boringssl/crypto/x509/a_verify.c +127 -0
- data/third_party/boringssl/crypto/x509/algorithm.c +137 -0
- data/third_party/boringssl/crypto/x509/asn1_gen.c +818 -0
- data/third_party/boringssl/crypto/x509/by_dir.c +453 -0
- data/third_party/boringssl/crypto/x509/by_file.c +275 -0
- data/third_party/boringssl/crypto/x509/charmap.h +15 -0
- data/third_party/boringssl/crypto/x509/i2d_pr.c +83 -0
- data/third_party/boringssl/crypto/x509/internal.h +66 -0
- data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
- data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
- data/third_party/boringssl/crypto/x509/t_crl.c +128 -0
- data/third_party/boringssl/crypto/x509/t_req.c +246 -0
- data/third_party/boringssl/crypto/x509/t_x509.c +506 -0
- data/third_party/boringssl/crypto/x509/t_x509a.c +111 -0
- data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
- data/third_party/boringssl/crypto/x509/x509.c +157 -0
- data/third_party/boringssl/crypto/x509/x509_att.c +381 -0
- data/third_party/boringssl/crypto/x509/x509_cmp.c +474 -0
- data/third_party/boringssl/crypto/x509/x509_d2.c +106 -0
- data/third_party/boringssl/crypto/x509/x509_def.c +98 -0
- data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
- data/third_party/boringssl/crypto/x509/x509_lu.c +690 -0
- data/third_party/boringssl/crypto/x509/x509_obj.c +197 -0
- data/third_party/boringssl/crypto/x509/x509_r2x.c +117 -0
- data/third_party/boringssl/crypto/x509/x509_req.c +322 -0
- data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
- data/third_party/boringssl/crypto/x509/x509_trs.c +326 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +211 -0
- data/third_party/boringssl/crypto/x509/x509_v3.c +278 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +2436 -0
- data/third_party/boringssl/crypto/x509/x509_vpm.c +647 -0
- data/third_party/boringssl/crypto/x509/x509cset.c +170 -0
- data/third_party/boringssl/crypto/x509/x509name.c +386 -0
- data/third_party/boringssl/crypto/x509/x509rset.c +81 -0
- data/third_party/boringssl/crypto/x509/x509spki.c +137 -0
- data/third_party/boringssl/crypto/x509/x509type.c +126 -0
- data/third_party/boringssl/crypto/x509/x_algor.c +151 -0
- data/third_party/boringssl/crypto/x509/x_all.c +501 -0
- data/third_party/boringssl/crypto/x509/x_attrib.c +111 -0
- data/third_party/boringssl/crypto/x509/x_crl.c +539 -0
- data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
- data/third_party/boringssl/crypto/x509/x_info.c +98 -0
- data/third_party/boringssl/crypto/x509/x_name.c +534 -0
- data/third_party/boringssl/crypto/x509/x_pkey.c +103 -0
- data/third_party/boringssl/crypto/x509/x_pubkey.c +368 -0
- data/third_party/boringssl/crypto/x509/x_req.c +109 -0
- data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
- data/third_party/boringssl/crypto/x509/x_spki.c +80 -0
- data/third_party/boringssl/crypto/x509/x_val.c +69 -0
- data/third_party/boringssl/crypto/x509/x_x509.c +289 -0
- data/third_party/boringssl/crypto/x509/x_x509a.c +205 -0
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +135 -0
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +284 -0
- data/third_party/boringssl/crypto/x509v3/pcy_data.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_int.h +217 -0
- data/third_party/boringssl/crypto/x509v3/pcy_lib.c +164 -0
- data/third_party/boringssl/crypto/x509v3/pcy_map.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +188 -0
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +829 -0
- data/third_party/boringssl/crypto/x509v3/v3_akey.c +204 -0
- data/third_party/boringssl/crypto/x509v3/v3_akeya.c +72 -0
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +614 -0
- data/third_party/boringssl/crypto/x509v3/v3_bcons.c +133 -0
- data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +462 -0
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +496 -0
- data/third_party/boringssl/crypto/x509v3/v3_crld.c +561 -0
- data/third_party/boringssl/crypto/x509v3/v3_enum.c +100 -0
- data/third_party/boringssl/crypto/x509v3/v3_extku.c +148 -0
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +250 -0
- data/third_party/boringssl/crypto/x509v3/v3_ia5.c +119 -0
- data/third_party/boringssl/crypto/x509v3/v3_info.c +212 -0
- data/third_party/boringssl/crypto/x509v3/v3_int.c +91 -0
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +362 -0
- data/third_party/boringssl/crypto/x509v3/v3_ncons.c +482 -0
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +317 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcia.c +57 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcons.c +139 -0
- data/third_party/boringssl/crypto/x509v3/v3_pku.c +110 -0
- data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +154 -0
- data/third_party/boringssl/crypto/x509v3/v3_prn.c +229 -0
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +874 -0
- data/third_party/boringssl/crypto/x509v3/v3_skey.c +152 -0
- data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +274 -0
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +1327 -0
- data/third_party/boringssl/include/openssl/aead.h +345 -0
- data/third_party/boringssl/include/openssl/aes.h +158 -0
- data/third_party/boringssl/include/openssl/arm_arch.h +121 -0
- data/third_party/boringssl/include/openssl/asn1.h +1038 -0
- data/third_party/boringssl/include/openssl/asn1_mac.h +18 -0
- data/third_party/boringssl/include/openssl/asn1t.h +896 -0
- data/third_party/boringssl/include/openssl/base.h +412 -0
- data/third_party/boringssl/include/openssl/base64.h +187 -0
- data/third_party/boringssl/include/openssl/bio.h +926 -0
- data/third_party/boringssl/include/openssl/blowfish.h +93 -0
- data/third_party/boringssl/include/openssl/bn.h +955 -0
- data/third_party/boringssl/include/openssl/buf.h +133 -0
- data/third_party/boringssl/include/openssl/buffer.h +18 -0
- data/third_party/boringssl/include/openssl/bytestring.h +437 -0
- data/third_party/boringssl/include/openssl/cast.h +96 -0
- data/third_party/boringssl/include/openssl/chacha.h +37 -0
- data/third_party/boringssl/include/openssl/cipher.h +588 -0
- data/third_party/boringssl/include/openssl/cmac.h +87 -0
- data/third_party/boringssl/include/openssl/conf.h +181 -0
- data/third_party/boringssl/include/openssl/cpu.h +181 -0
- data/third_party/boringssl/include/openssl/crypto.h +94 -0
- data/third_party/boringssl/include/openssl/curve25519.h +183 -0
- data/third_party/boringssl/include/openssl/des.h +177 -0
- data/third_party/boringssl/include/openssl/dh.h +297 -0
- data/third_party/boringssl/include/openssl/digest.h +285 -0
- data/third_party/boringssl/include/openssl/dsa.h +436 -0
- data/third_party/boringssl/include/openssl/dtls1.h +16 -0
- data/third_party/boringssl/include/openssl/ec.h +406 -0
- data/third_party/boringssl/include/openssl/ec_key.h +337 -0
- data/third_party/boringssl/include/openssl/ecdh.h +102 -0
- data/third_party/boringssl/include/openssl/ecdsa.h +217 -0
- data/third_party/boringssl/include/openssl/engine.h +109 -0
- data/third_party/boringssl/include/openssl/err.h +488 -0
- data/third_party/boringssl/include/openssl/evp.h +797 -0
- data/third_party/boringssl/include/openssl/ex_data.h +213 -0
- data/third_party/boringssl/include/openssl/hkdf.h +64 -0
- data/third_party/boringssl/include/openssl/hmac.h +174 -0
- data/third_party/boringssl/include/openssl/lhash.h +192 -0
- data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
- data/third_party/boringssl/include/openssl/md4.h +106 -0
- data/third_party/boringssl/include/openssl/md5.h +107 -0
- data/third_party/boringssl/include/openssl/mem.h +150 -0
- data/third_party/boringssl/include/openssl/newhope.h +158 -0
- data/third_party/boringssl/include/openssl/nid.h +4166 -0
- data/third_party/boringssl/include/openssl/obj.h +226 -0
- data/third_party/boringssl/include/openssl/obj_mac.h +18 -0
- data/third_party/boringssl/include/openssl/objects.h +18 -0
- data/third_party/boringssl/include/openssl/opensslconf.h +60 -0
- data/third_party/boringssl/include/openssl/opensslv.h +18 -0
- data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
- data/third_party/boringssl/include/openssl/pem.h +517 -0
- data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
- data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
- data/third_party/boringssl/include/openssl/pkcs8.h +236 -0
- data/third_party/boringssl/include/openssl/poly1305.h +51 -0
- data/third_party/boringssl/include/openssl/rand.h +122 -0
- data/third_party/boringssl/include/openssl/rc4.h +96 -0
- data/third_party/boringssl/include/openssl/ripemd.h +107 -0
- data/third_party/boringssl/include/openssl/rsa.h +699 -0
- data/third_party/boringssl/include/openssl/safestack.h +16 -0
- data/third_party/boringssl/include/openssl/sha.h +260 -0
- data/third_party/boringssl/include/openssl/srtp.h +18 -0
- data/third_party/boringssl/include/openssl/ssl.h +4826 -0
- data/third_party/boringssl/include/openssl/ssl3.h +434 -0
- data/third_party/boringssl/include/openssl/stack.h +293 -0
- data/third_party/boringssl/include/openssl/stack_macros.h +3902 -0
- data/third_party/boringssl/include/openssl/thread.h +191 -0
- data/third_party/boringssl/include/openssl/time_support.h +91 -0
- data/third_party/boringssl/include/openssl/tls1.h +657 -0
- data/third_party/boringssl/include/openssl/type_check.h +91 -0
- data/third_party/boringssl/include/openssl/x509.h +1299 -0
- data/third_party/boringssl/include/openssl/x509_vfy.h +618 -0
- data/third_party/boringssl/include/openssl/x509v3.h +819 -0
- data/third_party/boringssl/ssl/custom_extensions.c +255 -0
- data/third_party/boringssl/ssl/d1_both.c +845 -0
- data/third_party/boringssl/ssl/d1_lib.c +270 -0
- data/third_party/boringssl/ssl/d1_pkt.c +419 -0
- data/third_party/boringssl/ssl/d1_srtp.c +236 -0
- data/third_party/boringssl/ssl/dtls_method.c +203 -0
- data/third_party/boringssl/ssl/dtls_record.c +309 -0
- data/third_party/boringssl/ssl/handshake_client.c +2002 -0
- data/third_party/boringssl/ssl/handshake_server.c +1932 -0
- data/third_party/boringssl/ssl/internal.h +1551 -0
- data/third_party/boringssl/ssl/s3_both.c +745 -0
- data/third_party/boringssl/ssl/s3_enc.c +412 -0
- data/third_party/boringssl/ssl/s3_lib.c +336 -0
- data/third_party/boringssl/ssl/s3_pkt.c +497 -0
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +329 -0
- data/third_party/boringssl/ssl/ssl_asn1.c +748 -0
- data/third_party/boringssl/ssl/ssl_buffer.c +311 -0
- data/third_party/boringssl/ssl/ssl_cert.c +814 -0
- data/third_party/boringssl/ssl/ssl_cipher.c +2062 -0
- data/third_party/boringssl/ssl/ssl_ecdh.c +610 -0
- data/third_party/boringssl/ssl/ssl_file.c +586 -0
- data/third_party/boringssl/ssl/ssl_lib.c +3063 -0
- data/third_party/boringssl/ssl/ssl_rsa.c +793 -0
- data/third_party/boringssl/ssl/ssl_session.c +985 -0
- data/third_party/boringssl/ssl/ssl_stat.c +509 -0
- data/third_party/boringssl/ssl/t1_enc.c +547 -0
- data/third_party/boringssl/ssl/t1_lib.c +3279 -0
- data/third_party/boringssl/ssl/tls13_both.c +440 -0
- data/third_party/boringssl/ssl/tls13_client.c +682 -0
- data/third_party/boringssl/ssl/tls13_enc.c +391 -0
- data/third_party/boringssl/ssl/tls13_server.c +672 -0
- data/third_party/boringssl/ssl/tls_method.c +245 -0
- data/third_party/boringssl/ssl/tls_record.c +461 -0
- data/third_party/cares/ares_build.h +264 -0
- data/third_party/cares/cares/ares.h +636 -0
- data/third_party/cares/cares/ares__close_sockets.c +61 -0
- data/third_party/cares/cares/ares__get_hostent.c +261 -0
- data/third_party/cares/cares/ares__read_line.c +73 -0
- data/third_party/cares/cares/ares__timeval.c +111 -0
- data/third_party/cares/cares/ares_cancel.c +63 -0
- data/third_party/cares/cares/ares_create_query.c +202 -0
- data/third_party/cares/cares/ares_data.c +221 -0
- data/third_party/cares/cares/ares_data.h +72 -0
- data/third_party/cares/cares/ares_destroy.c +108 -0
- data/third_party/cares/cares/ares_dns.h +103 -0
- data/third_party/cares/cares/ares_expand_name.c +205 -0
- data/third_party/cares/cares/ares_expand_string.c +70 -0
- data/third_party/cares/cares/ares_fds.c +59 -0
- data/third_party/cares/cares/ares_free_hostent.c +41 -0
- data/third_party/cares/cares/ares_free_string.c +25 -0
- data/third_party/cares/cares/ares_getenv.c +30 -0
- data/third_party/cares/cares/ares_getenv.h +26 -0
- data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
- data/third_party/cares/cares/ares_gethostbyname.c +518 -0
- data/third_party/cares/cares/ares_getnameinfo.c +422 -0
- data/third_party/cares/cares/ares_getopt.c +122 -0
- data/third_party/cares/cares/ares_getopt.h +53 -0
- data/third_party/cares/cares/ares_getsock.c +66 -0
- data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
- data/third_party/cares/cares/ares_init.c +2146 -0
- data/third_party/cares/cares/ares_iphlpapi.h +221 -0
- data/third_party/cares/cares/ares_ipv6.h +78 -0
- data/third_party/cares/cares/ares_library_init.c +167 -0
- data/third_party/cares/cares/ares_library_init.h +42 -0
- data/third_party/cares/cares/ares_llist.c +63 -0
- data/third_party/cares/cares/ares_llist.h +39 -0
- data/third_party/cares/cares/ares_mkquery.c +24 -0
- data/third_party/cares/cares/ares_nowarn.c +260 -0
- data/third_party/cares/cares/ares_nowarn.h +61 -0
- data/third_party/cares/cares/ares_options.c +402 -0
- data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
- data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
- data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
- data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
- data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
- data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
- data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
- data/third_party/cares/cares/ares_platform.c +11035 -0
- data/third_party/cares/cares/ares_platform.h +43 -0
- data/third_party/cares/cares/ares_private.h +363 -0
- data/third_party/cares/cares/ares_process.c +1359 -0
- data/third_party/cares/cares/ares_query.c +186 -0
- data/third_party/cares/cares/ares_rules.h +125 -0
- data/third_party/cares/cares/ares_search.c +316 -0
- data/third_party/cares/cares/ares_send.c +131 -0
- data/third_party/cares/cares/ares_setup.h +217 -0
- data/third_party/cares/cares/ares_strcasecmp.c +66 -0
- data/third_party/cares/cares/ares_strcasecmp.h +30 -0
- data/third_party/cares/cares/ares_strdup.c +49 -0
- data/third_party/cares/cares/ares_strdup.h +24 -0
- data/third_party/cares/cares/ares_strerror.c +56 -0
- data/third_party/cares/cares/ares_timeout.c +88 -0
- data/third_party/cares/cares/ares_version.c +11 -0
- data/third_party/cares/cares/ares_version.h +24 -0
- data/third_party/cares/cares/ares_writev.c +79 -0
- data/third_party/cares/cares/bitncmp.c +59 -0
- data/third_party/cares/cares/bitncmp.h +26 -0
- data/third_party/cares/cares/config-win32.h +377 -0
- data/third_party/cares/cares/inet_net_pton.c +450 -0
- data/third_party/cares/cares/inet_ntop.c +208 -0
- data/third_party/cares/cares/setup_once.h +554 -0
- data/third_party/cares/cares/windows_port.c +22 -0
- data/third_party/cares/config_darwin/ares_config.h +523 -0
- data/third_party/cares/config_linux/ares_config.h +524 -0
- data/third_party/nanopb/pb.h +579 -0
- data/third_party/nanopb/pb_common.c +97 -0
- data/third_party/nanopb/pb_common.h +42 -0
- data/third_party/nanopb/pb_decode.c +1347 -0
- data/third_party/nanopb/pb_decode.h +149 -0
- data/third_party/nanopb/pb_encode.c +696 -0
- data/third_party/nanopb/pb_encode.h +154 -0
- data/third_party/zlib/adler32.c +179 -0
- data/third_party/zlib/compress.c +80 -0
- data/third_party/zlib/crc32.c +425 -0
- data/third_party/zlib/crc32.h +441 -0
- data/third_party/zlib/deflate.c +1967 -0
- data/third_party/zlib/deflate.h +346 -0
- data/third_party/zlib/gzclose.c +25 -0
- data/third_party/zlib/gzguts.h +209 -0
- data/third_party/zlib/gzlib.c +634 -0
- data/third_party/zlib/gzread.c +594 -0
- data/third_party/zlib/gzwrite.c +577 -0
- data/third_party/zlib/infback.c +640 -0
- data/third_party/zlib/inffast.c +340 -0
- data/third_party/zlib/inffast.h +11 -0
- data/third_party/zlib/inffixed.h +94 -0
- data/third_party/zlib/inflate.c +1512 -0
- data/third_party/zlib/inflate.h +122 -0
- data/third_party/zlib/inftrees.c +306 -0
- data/third_party/zlib/inftrees.h +62 -0
- data/third_party/zlib/trees.c +1226 -0
- data/third_party/zlib/trees.h +128 -0
- data/third_party/zlib/uncompr.c +59 -0
- data/third_party/zlib/zconf.h +511 -0
- data/third_party/zlib/zlib.h +1768 -0
- data/third_party/zlib/zutil.c +324 -0
- data/third_party/zlib/zutil.h +253 -0
- metadata +1397 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_CORE_LIB_IOMGR_ERROR_H
|
35
|
+
#define GRPC_CORE_LIB_IOMGR_ERROR_H
|
36
|
+
|
37
|
+
#include <stdbool.h>
|
38
|
+
#include <stdint.h>
|
39
|
+
|
40
|
+
#include <grpc/slice.h>
|
41
|
+
#include <grpc/status.h>
|
42
|
+
#include <grpc/support/time.h>
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
extern "C" {
|
46
|
+
#endif
|
47
|
+
|
48
|
+
/// Opaque representation of an error.
|
49
|
+
/// See https://github.com/grpc/grpc/blob/master/doc/core/grpc-error.md for a
|
50
|
+
/// full write up of this object.
|
51
|
+
|
52
|
+
typedef struct grpc_error grpc_error;
|
53
|
+
|
54
|
+
typedef enum {
|
55
|
+
/// 'errno' from the operating system
|
56
|
+
GRPC_ERROR_INT_ERRNO,
|
57
|
+
/// __LINE__ from the call site creating the error
|
58
|
+
GRPC_ERROR_INT_FILE_LINE,
|
59
|
+
/// stream identifier: for errors that are associated with an individual
|
60
|
+
/// wire stream
|
61
|
+
GRPC_ERROR_INT_STREAM_ID,
|
62
|
+
/// grpc status code representing this error
|
63
|
+
GRPC_ERROR_INT_GRPC_STATUS,
|
64
|
+
/// offset into some binary blob (usually represented by
|
65
|
+
/// GRPC_ERROR_STR_RAW_BYTES) where the error occurred
|
66
|
+
GRPC_ERROR_INT_OFFSET,
|
67
|
+
/// context sensitive index associated with the error
|
68
|
+
GRPC_ERROR_INT_INDEX,
|
69
|
+
/// context sensitive size associated with the error
|
70
|
+
GRPC_ERROR_INT_SIZE,
|
71
|
+
/// http2 error code associated with the error (see the HTTP2 RFC)
|
72
|
+
GRPC_ERROR_INT_HTTP2_ERROR,
|
73
|
+
/// TSI status code associated with the error
|
74
|
+
GRPC_ERROR_INT_TSI_CODE,
|
75
|
+
/// grpc_security_status associated with the error
|
76
|
+
GRPC_ERROR_INT_SECURITY_STATUS,
|
77
|
+
/// WSAGetLastError() reported when this error occurred
|
78
|
+
GRPC_ERROR_INT_WSA_ERROR,
|
79
|
+
/// File descriptor associated with this error
|
80
|
+
GRPC_ERROR_INT_FD,
|
81
|
+
/// HTTP status (i.e. 404)
|
82
|
+
GRPC_ERROR_INT_HTTP_STATUS,
|
83
|
+
/// context sensitive limit associated with the error
|
84
|
+
GRPC_ERROR_INT_LIMIT,
|
85
|
+
/// chttp2: did the error occur while a write was in progress
|
86
|
+
GRPC_ERROR_INT_OCCURRED_DURING_WRITE,
|
87
|
+
|
88
|
+
/// Must always be last
|
89
|
+
GRPC_ERROR_INT_MAX,
|
90
|
+
} grpc_error_ints;
|
91
|
+
|
92
|
+
typedef enum {
|
93
|
+
/// top-level textual description of this error
|
94
|
+
GRPC_ERROR_STR_DESCRIPTION,
|
95
|
+
/// source file in which this error occurred
|
96
|
+
GRPC_ERROR_STR_FILE,
|
97
|
+
/// operating system description of this error
|
98
|
+
GRPC_ERROR_STR_OS_ERROR,
|
99
|
+
/// syscall that generated this error
|
100
|
+
GRPC_ERROR_STR_SYSCALL,
|
101
|
+
/// peer that we were trying to communicate when this error occurred
|
102
|
+
GRPC_ERROR_STR_TARGET_ADDRESS,
|
103
|
+
/// grpc status message associated with this error
|
104
|
+
GRPC_ERROR_STR_GRPC_MESSAGE,
|
105
|
+
/// hex dump (or similar) with the data that generated this error
|
106
|
+
GRPC_ERROR_STR_RAW_BYTES,
|
107
|
+
/// tsi error string associated with this error
|
108
|
+
GRPC_ERROR_STR_TSI_ERROR,
|
109
|
+
/// filename that we were trying to read/write when this error occurred
|
110
|
+
GRPC_ERROR_STR_FILENAME,
|
111
|
+
/// which data was queued for writing when the error occurred
|
112
|
+
GRPC_ERROR_STR_QUEUED_BUFFERS,
|
113
|
+
/// key associated with the error
|
114
|
+
GRPC_ERROR_STR_KEY,
|
115
|
+
/// value associated with the error
|
116
|
+
GRPC_ERROR_STR_VALUE,
|
117
|
+
|
118
|
+
/// Must always be last
|
119
|
+
GRPC_ERROR_STR_MAX,
|
120
|
+
} grpc_error_strs;
|
121
|
+
|
122
|
+
typedef enum {
|
123
|
+
/// timestamp of error creation
|
124
|
+
GRPC_ERROR_TIME_CREATED,
|
125
|
+
|
126
|
+
/// Must always be last
|
127
|
+
GRPC_ERROR_TIME_MAX,
|
128
|
+
} grpc_error_times;
|
129
|
+
|
130
|
+
/// The following "special" errors can be propagated without allocating memory.
|
131
|
+
/// They are always even so that other code (particularly combiner locks,
|
132
|
+
/// polling engines) can safely use the lower bit for themselves.
|
133
|
+
|
134
|
+
#define GRPC_ERROR_NONE ((grpc_error *)NULL)
|
135
|
+
#define GRPC_ERROR_OOM ((grpc_error *)2)
|
136
|
+
#define GRPC_ERROR_CANCELLED ((grpc_error *)4)
|
137
|
+
|
138
|
+
const char *grpc_error_string(grpc_error *error);
|
139
|
+
|
140
|
+
/// Create an error - but use GRPC_ERROR_CREATE instead
|
141
|
+
grpc_error *grpc_error_create(grpc_slice file, int line, grpc_slice desc,
|
142
|
+
grpc_error **referencing, size_t num_referencing);
|
143
|
+
/// Create an error (this is the preferred way of generating an error that is
|
144
|
+
/// not due to a system call - for system calls, use GRPC_OS_ERROR or
|
145
|
+
/// GRPC_WSA_ERROR as appropriate)
|
146
|
+
/// \a referencing is an array of num_referencing elements indicating one or
|
147
|
+
/// more errors that are believed to have contributed to this one
|
148
|
+
/// err = grpc_error_create(x, y, z, r, nr) is equivalent to:
|
149
|
+
/// err = grpc_error_create(x, y, z, NULL, 0);
|
150
|
+
/// for (i=0; i<nr; i++) err = grpc_error_add_child(err, r[i]);
|
151
|
+
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc) \
|
152
|
+
grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \
|
153
|
+
grpc_slice_from_static_string(desc), NULL, 0)
|
154
|
+
#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \
|
155
|
+
grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \
|
156
|
+
grpc_slice_from_copied_string(desc), NULL, 0)
|
157
|
+
|
158
|
+
// Create an error that references some other errors. This function adds a
|
159
|
+
// reference to each error in errs - it does not consume an existing reference
|
160
|
+
#define GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(desc, errs, count) \
|
161
|
+
grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \
|
162
|
+
grpc_slice_from_static_string(desc), errs, count)
|
163
|
+
#define GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(desc, errs, count) \
|
164
|
+
grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \
|
165
|
+
grpc_slice_from_copied_string(desc), errs, count)
|
166
|
+
|
167
|
+
//#define GRPC_ERROR_REFCOUNT_DEBUG
|
168
|
+
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
|
169
|
+
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line,
|
170
|
+
const char *func);
|
171
|
+
void grpc_error_unref(grpc_error *err, const char *file, int line,
|
172
|
+
const char *func);
|
173
|
+
#define GRPC_ERROR_REF(err) grpc_error_ref(err, __FILE__, __LINE__, __func__)
|
174
|
+
#define GRPC_ERROR_UNREF(err) \
|
175
|
+
grpc_error_unref(err, __FILE__, __LINE__, __func__)
|
176
|
+
#else
|
177
|
+
grpc_error *grpc_error_ref(grpc_error *err);
|
178
|
+
void grpc_error_unref(grpc_error *err);
|
179
|
+
#define GRPC_ERROR_REF(err) grpc_error_ref(err)
|
180
|
+
#define GRPC_ERROR_UNREF(err) grpc_error_unref(err)
|
181
|
+
#endif
|
182
|
+
|
183
|
+
grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which,
|
184
|
+
intptr_t value) GRPC_MUST_USE_RESULT;
|
185
|
+
bool grpc_error_get_int(grpc_error *error, grpc_error_ints which, intptr_t *p);
|
186
|
+
grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which,
|
187
|
+
grpc_slice str) GRPC_MUST_USE_RESULT;
|
188
|
+
/// Returns false if the specified string is not set.
|
189
|
+
/// Caller does NOT own the slice.
|
190
|
+
bool grpc_error_get_str(grpc_error *error, grpc_error_strs which,
|
191
|
+
grpc_slice *s);
|
192
|
+
|
193
|
+
/// Add a child error: an error that is believed to have contributed to this
|
194
|
+
/// error occurring. Allows root causing high level errors from lower level
|
195
|
+
/// errors that contributed to them.
|
196
|
+
grpc_error *grpc_error_add_child(grpc_error *src,
|
197
|
+
grpc_error *child) GRPC_MUST_USE_RESULT;
|
198
|
+
grpc_error *grpc_os_error(const char *file, int line, int err,
|
199
|
+
const char *call_name) GRPC_MUST_USE_RESULT;
|
200
|
+
/// create an error associated with errno!=0 (an 'operating system' error)
|
201
|
+
#define GRPC_OS_ERROR(err, call_name) \
|
202
|
+
grpc_os_error(__FILE__, __LINE__, err, call_name)
|
203
|
+
grpc_error *grpc_wsa_error(const char *file, int line, int err,
|
204
|
+
const char *call_name) GRPC_MUST_USE_RESULT;
|
205
|
+
/// windows only: create an error associated with WSAGetLastError()!=0
|
206
|
+
#define GRPC_WSA_ERROR(err, call_name) \
|
207
|
+
grpc_wsa_error(__FILE__, __LINE__, err, call_name)
|
208
|
+
|
209
|
+
bool grpc_log_if_error(const char *what, grpc_error *error, const char *file,
|
210
|
+
int line);
|
211
|
+
#define GRPC_LOG_IF_ERROR(what, error) \
|
212
|
+
grpc_log_if_error((what), (error), __FILE__, __LINE__)
|
213
|
+
|
214
|
+
#ifdef __cplusplus
|
215
|
+
}
|
216
|
+
#endif
|
217
|
+
|
218
|
+
#endif /* GRPC_CORE_LIB_IOMGR_ERROR_H */
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H
|
35
|
+
#define GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H
|
36
|
+
|
37
|
+
#include <inttypes.h>
|
38
|
+
#include <stdbool.h> // TODO, do we need this?
|
39
|
+
|
40
|
+
#include <grpc/support/sync.h>
|
41
|
+
|
42
|
+
typedef struct grpc_linked_error grpc_linked_error;
|
43
|
+
|
44
|
+
struct grpc_linked_error {
|
45
|
+
grpc_error *err;
|
46
|
+
uint8_t next;
|
47
|
+
};
|
48
|
+
|
49
|
+
// c core representation of an error. See error.h for high level description of
|
50
|
+
// this object.
|
51
|
+
struct grpc_error {
|
52
|
+
// All atomics in grpc_error must be stored in this nested struct. The rest of
|
53
|
+
// the object is memcpy-ed in bulk in copy_and_unref.
|
54
|
+
struct atomics {
|
55
|
+
gpr_refcount refs;
|
56
|
+
gpr_atm error_string;
|
57
|
+
} atomics;
|
58
|
+
// These arrays index into dynamic arena at the bottom of the struct.
|
59
|
+
// UINT8_MAX is used as a sentinel value.
|
60
|
+
uint8_t ints[GRPC_ERROR_INT_MAX];
|
61
|
+
uint8_t strs[GRPC_ERROR_STR_MAX];
|
62
|
+
uint8_t times[GRPC_ERROR_TIME_MAX];
|
63
|
+
// The child errors are stored in the arena, but are effectively a linked list
|
64
|
+
// structure, since they are contained withing grpc_linked_error objects.
|
65
|
+
uint8_t first_err;
|
66
|
+
uint8_t last_err;
|
67
|
+
// The arena is dynamically reallocated with a grow factor of 1.5.
|
68
|
+
uint8_t arena_size;
|
69
|
+
uint8_t arena_capacity;
|
70
|
+
intptr_t arena[0];
|
71
|
+
};
|
72
|
+
|
73
|
+
bool grpc_error_is_special(grpc_error *err);
|
74
|
+
|
75
|
+
#endif /* GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H */
|
@@ -0,0 +1,1965 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "src/core/lib/iomgr/port.h"
|
35
|
+
|
36
|
+
/* This polling engine is only relevant on linux kernels supporting epoll() */
|
37
|
+
#ifdef GRPC_LINUX_EPOLL
|
38
|
+
|
39
|
+
#include "src/core/lib/iomgr/ev_epoll_linux.h"
|
40
|
+
|
41
|
+
#include <assert.h>
|
42
|
+
#include <errno.h>
|
43
|
+
#include <poll.h>
|
44
|
+
#include <pthread.h>
|
45
|
+
#include <signal.h>
|
46
|
+
#include <string.h>
|
47
|
+
#include <sys/epoll.h>
|
48
|
+
#include <sys/socket.h>
|
49
|
+
#include <unistd.h>
|
50
|
+
|
51
|
+
#include <grpc/support/alloc.h>
|
52
|
+
#include <grpc/support/log.h>
|
53
|
+
#include <grpc/support/string_util.h>
|
54
|
+
#include <grpc/support/tls.h>
|
55
|
+
#include <grpc/support/useful.h>
|
56
|
+
|
57
|
+
#include "src/core/lib/iomgr/ev_posix.h"
|
58
|
+
#include "src/core/lib/iomgr/iomgr_internal.h"
|
59
|
+
#include "src/core/lib/iomgr/lockfree_event.h"
|
60
|
+
#include "src/core/lib/iomgr/timer.h"
|
61
|
+
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
|
62
|
+
#include "src/core/lib/iomgr/workqueue.h"
|
63
|
+
#include "src/core/lib/profiling/timers.h"
|
64
|
+
#include "src/core/lib/support/block_annotate.h"
|
65
|
+
|
66
|
+
/* TODO: sreek - Move this to init.c and initialize this like other tracers. */
|
67
|
+
static int grpc_polling_trace = 0; /* Disabled by default */
|
68
|
+
#define GRPC_POLLING_TRACE(fmt, ...) \
|
69
|
+
if (grpc_polling_trace) { \
|
70
|
+
gpr_log(GPR_INFO, (fmt), __VA_ARGS__); \
|
71
|
+
}
|
72
|
+
|
73
|
+
/* Uncomment the following to enable extra checks on poll_object operations */
|
74
|
+
/* #define PO_DEBUG */
|
75
|
+
|
76
|
+
static int grpc_wakeup_signal = -1;
|
77
|
+
static bool is_grpc_wakeup_signal_initialized = false;
|
78
|
+
|
79
|
+
/* TODO: sreek: Right now, this wakes up all pollers. In future we should make
|
80
|
+
* sure to wake up one polling thread (which can wake up other threads if
|
81
|
+
* needed) */
|
82
|
+
static grpc_wakeup_fd global_wakeup_fd;
|
83
|
+
|
84
|
+
/* Implements the function defined in grpc_posix.h. This function might be
|
85
|
+
* called before even calling grpc_init() to set either a different signal to
|
86
|
+
* use. If signum == -1, then the use of signals is disabled */
|
87
|
+
void grpc_use_signal(int signum) {
|
88
|
+
grpc_wakeup_signal = signum;
|
89
|
+
is_grpc_wakeup_signal_initialized = true;
|
90
|
+
|
91
|
+
if (grpc_wakeup_signal < 0) {
|
92
|
+
gpr_log(GPR_INFO,
|
93
|
+
"Use of signals is disabled. Epoll engine will not be used");
|
94
|
+
} else {
|
95
|
+
gpr_log(GPR_INFO, "epoll engine will be using signal: %d",
|
96
|
+
grpc_wakeup_signal);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
struct polling_island;
|
101
|
+
|
102
|
+
typedef enum {
|
103
|
+
POLL_OBJ_FD,
|
104
|
+
POLL_OBJ_POLLSET,
|
105
|
+
POLL_OBJ_POLLSET_SET
|
106
|
+
} poll_obj_type;
|
107
|
+
|
108
|
+
typedef struct poll_obj {
|
109
|
+
#ifdef PO_DEBUG
|
110
|
+
poll_obj_type obj_type;
|
111
|
+
#endif
|
112
|
+
gpr_mu mu;
|
113
|
+
struct polling_island *pi;
|
114
|
+
} poll_obj;
|
115
|
+
|
116
|
+
const char *poll_obj_string(poll_obj_type po_type) {
|
117
|
+
switch (po_type) {
|
118
|
+
case POLL_OBJ_FD:
|
119
|
+
return "fd";
|
120
|
+
case POLL_OBJ_POLLSET:
|
121
|
+
return "pollset";
|
122
|
+
case POLL_OBJ_POLLSET_SET:
|
123
|
+
return "pollset_set";
|
124
|
+
}
|
125
|
+
|
126
|
+
GPR_UNREACHABLE_CODE(return "UNKNOWN");
|
127
|
+
}
|
128
|
+
|
129
|
+
/*******************************************************************************
|
130
|
+
* Fd Declarations
|
131
|
+
*/
|
132
|
+
|
133
|
+
#define FD_FROM_PO(po) ((grpc_fd *)(po))
|
134
|
+
|
135
|
+
struct grpc_fd {
|
136
|
+
poll_obj po;
|
137
|
+
|
138
|
+
int fd;
|
139
|
+
/* refst format:
|
140
|
+
bit 0 : 1=Active / 0=Orphaned
|
141
|
+
bits 1-n : refcount
|
142
|
+
Ref/Unref by two to avoid altering the orphaned bit */
|
143
|
+
gpr_atm refst;
|
144
|
+
|
145
|
+
/* The fd is either closed or we relinquished control of it. In either
|
146
|
+
cases, this indicates that the 'fd' on this structure is no longer
|
147
|
+
valid */
|
148
|
+
bool orphaned;
|
149
|
+
|
150
|
+
gpr_atm read_closure;
|
151
|
+
gpr_atm write_closure;
|
152
|
+
|
153
|
+
struct grpc_fd *freelist_next;
|
154
|
+
grpc_closure *on_done_closure;
|
155
|
+
|
156
|
+
/* The pollset that last noticed that the fd is readable. The actual type
|
157
|
+
* stored in this is (grpc_pollset *) */
|
158
|
+
gpr_atm read_notifier_pollset;
|
159
|
+
|
160
|
+
grpc_iomgr_object iomgr_object;
|
161
|
+
};
|
162
|
+
|
163
|
+
/* Reference counting for fds */
|
164
|
+
// #define GRPC_FD_REF_COUNT_DEBUG
|
165
|
+
#ifdef GRPC_FD_REF_COUNT_DEBUG
|
166
|
+
static void fd_ref(grpc_fd *fd, const char *reason, const char *file, int line);
|
167
|
+
static void fd_unref(grpc_fd *fd, const char *reason, const char *file,
|
168
|
+
int line);
|
169
|
+
#define GRPC_FD_REF(fd, reason) fd_ref(fd, reason, __FILE__, __LINE__)
|
170
|
+
#define GRPC_FD_UNREF(fd, reason) fd_unref(fd, reason, __FILE__, __LINE__)
|
171
|
+
#else
|
172
|
+
static void fd_ref(grpc_fd *fd);
|
173
|
+
static void fd_unref(grpc_fd *fd);
|
174
|
+
#define GRPC_FD_REF(fd, reason) fd_ref(fd)
|
175
|
+
#define GRPC_FD_UNREF(fd, reason) fd_unref(fd)
|
176
|
+
#endif
|
177
|
+
|
178
|
+
static void fd_global_init(void);
|
179
|
+
static void fd_global_shutdown(void);
|
180
|
+
|
181
|
+
/*******************************************************************************
|
182
|
+
* Polling island Declarations
|
183
|
+
*/
|
184
|
+
|
185
|
+
#ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG
|
186
|
+
|
187
|
+
#define PI_ADD_REF(p, r) pi_add_ref_dbg((p), (r), __FILE__, __LINE__)
|
188
|
+
#define PI_UNREF(exec_ctx, p, r) \
|
189
|
+
pi_unref_dbg((exec_ctx), (p), (r), __FILE__, __LINE__)
|
190
|
+
|
191
|
+
#else /* defined(GRPC_WORKQUEUE_REFCOUNT_DEBUG) */
|
192
|
+
|
193
|
+
#define PI_ADD_REF(p, r) pi_add_ref((p))
|
194
|
+
#define PI_UNREF(exec_ctx, p, r) pi_unref((exec_ctx), (p))
|
195
|
+
|
196
|
+
#endif /* !defined(GRPC_PI_REF_COUNT_DEBUG) */
|
197
|
+
|
198
|
+
/* This is also used as grpc_workqueue (by directly casing it) */
|
199
|
+
typedef struct polling_island {
|
200
|
+
grpc_closure_scheduler workqueue_scheduler;
|
201
|
+
|
202
|
+
gpr_mu mu;
|
203
|
+
/* Ref count. Use PI_ADD_REF() and PI_UNREF() macros to increment/decrement
|
204
|
+
the refcount.
|
205
|
+
Once the ref count becomes zero, this structure is destroyed which means
|
206
|
+
we should ensure that there is never a scenario where a PI_ADD_REF() is
|
207
|
+
racing with a PI_UNREF() that just made the ref_count zero. */
|
208
|
+
gpr_atm ref_count;
|
209
|
+
|
210
|
+
/* Pointer to the polling_island this merged into.
|
211
|
+
* merged_to value is only set once in polling_island's lifetime (and that too
|
212
|
+
* only if the island is merged with another island). Because of this, we can
|
213
|
+
* use gpr_atm type here so that we can do atomic access on this and reduce
|
214
|
+
* lock contention on 'mu' mutex.
|
215
|
+
*
|
216
|
+
* Note that if this field is not NULL (i.e not 0), all the remaining fields
|
217
|
+
* (except mu and ref_count) are invalid and must be ignored. */
|
218
|
+
gpr_atm merged_to;
|
219
|
+
|
220
|
+
/* Number of threads currently polling on this island */
|
221
|
+
gpr_atm poller_count;
|
222
|
+
/* Mutex guarding the read end of the workqueue (must be held to pop from
|
223
|
+
* workqueue_items) */
|
224
|
+
gpr_mu workqueue_read_mu;
|
225
|
+
/* Queue of closures to be executed */
|
226
|
+
gpr_mpscq workqueue_items;
|
227
|
+
/* Count of items in workqueue_items */
|
228
|
+
gpr_atm workqueue_item_count;
|
229
|
+
/* Wakeup fd used to wake pollers to check the contents of workqueue_items */
|
230
|
+
grpc_wakeup_fd workqueue_wakeup_fd;
|
231
|
+
|
232
|
+
/* The fd of the underlying epoll set */
|
233
|
+
int epoll_fd;
|
234
|
+
|
235
|
+
/* The file descriptors in the epoll set */
|
236
|
+
size_t fd_cnt;
|
237
|
+
size_t fd_capacity;
|
238
|
+
grpc_fd **fds;
|
239
|
+
} polling_island;
|
240
|
+
|
241
|
+
/*******************************************************************************
|
242
|
+
* Pollset Declarations
|
243
|
+
*/
|
244
|
+
struct grpc_pollset_worker {
|
245
|
+
/* Thread id of this worker */
|
246
|
+
pthread_t pt_id;
|
247
|
+
|
248
|
+
/* Used to prevent a worker from getting kicked multiple times */
|
249
|
+
gpr_atm is_kicked;
|
250
|
+
struct grpc_pollset_worker *next;
|
251
|
+
struct grpc_pollset_worker *prev;
|
252
|
+
};
|
253
|
+
|
254
|
+
struct grpc_pollset {
|
255
|
+
poll_obj po;
|
256
|
+
|
257
|
+
grpc_pollset_worker root_worker;
|
258
|
+
bool kicked_without_pollers;
|
259
|
+
|
260
|
+
bool shutting_down; /* Is the pollset shutting down ? */
|
261
|
+
bool finish_shutdown_called; /* Is the 'finish_shutdown_locked()' called ? */
|
262
|
+
grpc_closure *shutdown_done; /* Called after after shutdown is complete */
|
263
|
+
};
|
264
|
+
|
265
|
+
/*******************************************************************************
|
266
|
+
* Pollset-set Declarations
|
267
|
+
*/
|
268
|
+
struct grpc_pollset_set {
|
269
|
+
poll_obj po;
|
270
|
+
};
|
271
|
+
|
272
|
+
/*******************************************************************************
|
273
|
+
* Common helpers
|
274
|
+
*/
|
275
|
+
|
276
|
+
static bool append_error(grpc_error **composite, grpc_error *error,
|
277
|
+
const char *desc) {
|
278
|
+
if (error == GRPC_ERROR_NONE) return true;
|
279
|
+
if (*composite == GRPC_ERROR_NONE) {
|
280
|
+
*composite = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc);
|
281
|
+
}
|
282
|
+
*composite = grpc_error_add_child(*composite, error);
|
283
|
+
return false;
|
284
|
+
}
|
285
|
+
|
286
|
+
/*******************************************************************************
|
287
|
+
* Polling island Definitions
|
288
|
+
*/
|
289
|
+
|
290
|
+
/* The wakeup fd that is used to wake up all threads in a Polling island. This
|
291
|
+
is useful in the polling island merge operation where we need to wakeup all
|
292
|
+
the threads currently polling the smaller polling island (so that they can
|
293
|
+
start polling the new/merged polling island)
|
294
|
+
|
295
|
+
NOTE: This fd is initialized to be readable and MUST NOT be consumed i.e the
|
296
|
+
threads that woke up MUST NOT call grpc_wakeup_fd_consume_wakeup() */
|
297
|
+
static grpc_wakeup_fd polling_island_wakeup_fd;
|
298
|
+
|
299
|
+
/* The polling island being polled right now.
|
300
|
+
See comments in workqueue_maybe_wakeup for why this is tracked. */
|
301
|
+
static __thread polling_island *g_current_thread_polling_island;
|
302
|
+
|
303
|
+
/* Forward declaration */
|
304
|
+
static void polling_island_delete(grpc_exec_ctx *exec_ctx, polling_island *pi);
|
305
|
+
static void workqueue_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
|
306
|
+
grpc_error *error);
|
307
|
+
|
308
|
+
#ifdef GRPC_TSAN
|
309
|
+
/* Currently TSAN may incorrectly flag data races between epoll_ctl and
|
310
|
+
epoll_wait for any grpc_fd structs that are added to the epoll set via
|
311
|
+
epoll_ctl and are returned (within a very short window) via epoll_wait().
|
312
|
+
|
313
|
+
To work-around this race, we establish a happens-before relation between
|
314
|
+
the code just-before epoll_ctl() and the code after epoll_wait() by using
|
315
|
+
this atomic */
|
316
|
+
gpr_atm g_epoll_sync;
|
317
|
+
#endif /* defined(GRPC_TSAN) */
|
318
|
+
|
319
|
+
static const grpc_closure_scheduler_vtable workqueue_scheduler_vtable = {
|
320
|
+
workqueue_enqueue, workqueue_enqueue, "workqueue"};
|
321
|
+
|
322
|
+
static void pi_add_ref(polling_island *pi);
|
323
|
+
static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi);
|
324
|
+
|
325
|
+
#ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG
|
326
|
+
static void pi_add_ref_dbg(polling_island *pi, const char *reason,
|
327
|
+
const char *file, int line) {
|
328
|
+
long old_cnt = gpr_atm_acq_load(&pi->ref_count);
|
329
|
+
pi_add_ref(pi);
|
330
|
+
gpr_log(GPR_DEBUG, "Add ref pi: %p, old: %ld -> new:%ld (%s) - (%s, %d)",
|
331
|
+
(void *)pi, old_cnt, old_cnt + 1, reason, file, line);
|
332
|
+
}
|
333
|
+
|
334
|
+
static void pi_unref_dbg(grpc_exec_ctx *exec_ctx, polling_island *pi,
|
335
|
+
const char *reason, const char *file, int line) {
|
336
|
+
long old_cnt = gpr_atm_acq_load(&pi->ref_count);
|
337
|
+
pi_unref(exec_ctx, pi);
|
338
|
+
gpr_log(GPR_DEBUG, "Unref pi: %p, old:%ld -> new:%ld (%s) - (%s, %d)",
|
339
|
+
(void *)pi, old_cnt, (old_cnt - 1), reason, file, line);
|
340
|
+
}
|
341
|
+
|
342
|
+
static grpc_workqueue *workqueue_ref(grpc_workqueue *workqueue,
|
343
|
+
const char *file, int line,
|
344
|
+
const char *reason) {
|
345
|
+
if (workqueue != NULL) {
|
346
|
+
pi_add_ref_dbg((polling_island *)workqueue, reason, file, line);
|
347
|
+
}
|
348
|
+
return workqueue;
|
349
|
+
}
|
350
|
+
|
351
|
+
static void workqueue_unref(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue,
|
352
|
+
const char *file, int line, const char *reason) {
|
353
|
+
if (workqueue != NULL) {
|
354
|
+
pi_unref_dbg(exec_ctx, (polling_island *)workqueue, reason, file, line);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
#else
|
358
|
+
static grpc_workqueue *workqueue_ref(grpc_workqueue *workqueue) {
|
359
|
+
if (workqueue != NULL) {
|
360
|
+
pi_add_ref((polling_island *)workqueue);
|
361
|
+
}
|
362
|
+
return workqueue;
|
363
|
+
}
|
364
|
+
|
365
|
+
static void workqueue_unref(grpc_exec_ctx *exec_ctx,
|
366
|
+
grpc_workqueue *workqueue) {
|
367
|
+
if (workqueue != NULL) {
|
368
|
+
pi_unref(exec_ctx, (polling_island *)workqueue);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
#endif
|
372
|
+
|
373
|
+
static void pi_add_ref(polling_island *pi) {
|
374
|
+
gpr_atm_no_barrier_fetch_add(&pi->ref_count, 1);
|
375
|
+
}
|
376
|
+
|
377
|
+
static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi) {
|
378
|
+
/* If ref count went to zero, delete the polling island.
|
379
|
+
Note that this deletion not be done under a lock. Once the ref count goes
|
380
|
+
to zero, we are guaranteed that no one else holds a reference to the
|
381
|
+
polling island (and that there is no racing pi_add_ref() call either).
|
382
|
+
|
383
|
+
Also, if we are deleting the polling island and the merged_to field is
|
384
|
+
non-empty, we should remove a ref to the merged_to polling island
|
385
|
+
*/
|
386
|
+
if (1 == gpr_atm_full_fetch_add(&pi->ref_count, -1)) {
|
387
|
+
polling_island *next = (polling_island *)gpr_atm_acq_load(&pi->merged_to);
|
388
|
+
polling_island_delete(exec_ctx, pi);
|
389
|
+
if (next != NULL) {
|
390
|
+
PI_UNREF(exec_ctx, next, "pi_delete"); /* Recursive call */
|
391
|
+
}
|
392
|
+
}
|
393
|
+
}
|
394
|
+
|
395
|
+
/* The caller is expected to hold pi->mu lock before calling this function */
|
396
|
+
static void polling_island_add_fds_locked(polling_island *pi, grpc_fd **fds,
|
397
|
+
size_t fd_count, bool add_fd_refs,
|
398
|
+
grpc_error **error) {
|
399
|
+
int err;
|
400
|
+
size_t i;
|
401
|
+
struct epoll_event ev;
|
402
|
+
char *err_msg;
|
403
|
+
const char *err_desc = "polling_island_add_fds";
|
404
|
+
|
405
|
+
#ifdef GRPC_TSAN
|
406
|
+
/* See the definition of g_epoll_sync for more context */
|
407
|
+
gpr_atm_rel_store(&g_epoll_sync, (gpr_atm)0);
|
408
|
+
#endif /* defined(GRPC_TSAN) */
|
409
|
+
|
410
|
+
for (i = 0; i < fd_count; i++) {
|
411
|
+
ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET);
|
412
|
+
ev.data.ptr = fds[i];
|
413
|
+
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD, fds[i]->fd, &ev);
|
414
|
+
|
415
|
+
if (err < 0) {
|
416
|
+
if (errno != EEXIST) {
|
417
|
+
gpr_asprintf(
|
418
|
+
&err_msg,
|
419
|
+
"epoll_ctl (epoll_fd: %d) add fd: %d failed with error: %d (%s)",
|
420
|
+
pi->epoll_fd, fds[i]->fd, errno, strerror(errno));
|
421
|
+
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc);
|
422
|
+
gpr_free(err_msg);
|
423
|
+
}
|
424
|
+
|
425
|
+
continue;
|
426
|
+
}
|
427
|
+
|
428
|
+
if (pi->fd_cnt == pi->fd_capacity) {
|
429
|
+
pi->fd_capacity = GPR_MAX(pi->fd_capacity + 8, pi->fd_cnt * 3 / 2);
|
430
|
+
pi->fds = gpr_realloc(pi->fds, sizeof(grpc_fd *) * pi->fd_capacity);
|
431
|
+
}
|
432
|
+
|
433
|
+
pi->fds[pi->fd_cnt++] = fds[i];
|
434
|
+
if (add_fd_refs) {
|
435
|
+
GRPC_FD_REF(fds[i], "polling_island");
|
436
|
+
}
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
/* The caller is expected to hold pi->mu before calling this */
|
441
|
+
static void polling_island_add_wakeup_fd_locked(polling_island *pi,
|
442
|
+
grpc_wakeup_fd *wakeup_fd,
|
443
|
+
grpc_error **error) {
|
444
|
+
struct epoll_event ev;
|
445
|
+
int err;
|
446
|
+
char *err_msg;
|
447
|
+
const char *err_desc = "polling_island_add_wakeup_fd";
|
448
|
+
|
449
|
+
ev.events = (uint32_t)(EPOLLIN | EPOLLET);
|
450
|
+
ev.data.ptr = wakeup_fd;
|
451
|
+
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_ADD,
|
452
|
+
GRPC_WAKEUP_FD_GET_READ_FD(wakeup_fd), &ev);
|
453
|
+
if (err < 0 && errno != EEXIST) {
|
454
|
+
gpr_asprintf(&err_msg,
|
455
|
+
"epoll_ctl (epoll_fd: %d) add wakeup fd: %d failed with "
|
456
|
+
"error: %d (%s)",
|
457
|
+
pi->epoll_fd, GRPC_WAKEUP_FD_GET_READ_FD(&global_wakeup_fd),
|
458
|
+
errno, strerror(errno));
|
459
|
+
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc);
|
460
|
+
gpr_free(err_msg);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
|
464
|
+
/* The caller is expected to hold pi->mu lock before calling this function */
|
465
|
+
static void polling_island_remove_all_fds_locked(polling_island *pi,
|
466
|
+
bool remove_fd_refs,
|
467
|
+
grpc_error **error) {
|
468
|
+
int err;
|
469
|
+
size_t i;
|
470
|
+
char *err_msg;
|
471
|
+
const char *err_desc = "polling_island_remove_fds";
|
472
|
+
|
473
|
+
for (i = 0; i < pi->fd_cnt; i++) {
|
474
|
+
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, pi->fds[i]->fd, NULL);
|
475
|
+
if (err < 0 && errno != ENOENT) {
|
476
|
+
gpr_asprintf(&err_msg,
|
477
|
+
"epoll_ctl (epoll_fd: %d) delete fds[%zu]: %d failed with "
|
478
|
+
"error: %d (%s)",
|
479
|
+
pi->epoll_fd, i, pi->fds[i]->fd, errno, strerror(errno));
|
480
|
+
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc);
|
481
|
+
gpr_free(err_msg);
|
482
|
+
}
|
483
|
+
|
484
|
+
if (remove_fd_refs) {
|
485
|
+
GRPC_FD_UNREF(pi->fds[i], "polling_island");
|
486
|
+
}
|
487
|
+
}
|
488
|
+
|
489
|
+
pi->fd_cnt = 0;
|
490
|
+
}
|
491
|
+
|
492
|
+
/* The caller is expected to hold pi->mu lock before calling this function */
|
493
|
+
static void polling_island_remove_fd_locked(polling_island *pi, grpc_fd *fd,
|
494
|
+
bool is_fd_closed,
|
495
|
+
grpc_error **error) {
|
496
|
+
int err;
|
497
|
+
size_t i;
|
498
|
+
char *err_msg;
|
499
|
+
const char *err_desc = "polling_island_remove_fd";
|
500
|
+
|
501
|
+
/* If fd is already closed, then it would have been automatically been removed
|
502
|
+
from the epoll set */
|
503
|
+
if (!is_fd_closed) {
|
504
|
+
err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, fd->fd, NULL);
|
505
|
+
if (err < 0 && errno != ENOENT) {
|
506
|
+
gpr_asprintf(
|
507
|
+
&err_msg,
|
508
|
+
"epoll_ctl (epoll_fd: %d) del fd: %d failed with error: %d (%s)",
|
509
|
+
pi->epoll_fd, fd->fd, errno, strerror(errno));
|
510
|
+
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc);
|
511
|
+
gpr_free(err_msg);
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
for (i = 0; i < pi->fd_cnt; i++) {
|
516
|
+
if (pi->fds[i] == fd) {
|
517
|
+
pi->fds[i] = pi->fds[--pi->fd_cnt];
|
518
|
+
GRPC_FD_UNREF(fd, "polling_island");
|
519
|
+
break;
|
520
|
+
}
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
/* Might return NULL in case of an error */
|
525
|
+
static polling_island *polling_island_create(grpc_exec_ctx *exec_ctx,
|
526
|
+
grpc_fd *initial_fd,
|
527
|
+
grpc_error **error) {
|
528
|
+
polling_island *pi = NULL;
|
529
|
+
const char *err_desc = "polling_island_create";
|
530
|
+
|
531
|
+
*error = GRPC_ERROR_NONE;
|
532
|
+
|
533
|
+
pi = gpr_malloc(sizeof(*pi));
|
534
|
+
pi->workqueue_scheduler.vtable = &workqueue_scheduler_vtable;
|
535
|
+
gpr_mu_init(&pi->mu);
|
536
|
+
pi->fd_cnt = 0;
|
537
|
+
pi->fd_capacity = 0;
|
538
|
+
pi->fds = NULL;
|
539
|
+
pi->epoll_fd = -1;
|
540
|
+
|
541
|
+
gpr_mu_init(&pi->workqueue_read_mu);
|
542
|
+
gpr_mpscq_init(&pi->workqueue_items);
|
543
|
+
gpr_atm_rel_store(&pi->workqueue_item_count, 0);
|
544
|
+
|
545
|
+
gpr_atm_rel_store(&pi->ref_count, 0);
|
546
|
+
gpr_atm_rel_store(&pi->poller_count, 0);
|
547
|
+
gpr_atm_rel_store(&pi->merged_to, (gpr_atm)NULL);
|
548
|
+
|
549
|
+
if (!append_error(error, grpc_wakeup_fd_init(&pi->workqueue_wakeup_fd),
|
550
|
+
err_desc)) {
|
551
|
+
goto done;
|
552
|
+
}
|
553
|
+
|
554
|
+
pi->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
555
|
+
|
556
|
+
if (pi->epoll_fd < 0) {
|
557
|
+
append_error(error, GRPC_OS_ERROR(errno, "epoll_create1"), err_desc);
|
558
|
+
goto done;
|
559
|
+
}
|
560
|
+
|
561
|
+
polling_island_add_wakeup_fd_locked(pi, &global_wakeup_fd, error);
|
562
|
+
polling_island_add_wakeup_fd_locked(pi, &pi->workqueue_wakeup_fd, error);
|
563
|
+
|
564
|
+
if (initial_fd != NULL) {
|
565
|
+
polling_island_add_fds_locked(pi, &initial_fd, 1, true, error);
|
566
|
+
}
|
567
|
+
|
568
|
+
done:
|
569
|
+
if (*error != GRPC_ERROR_NONE) {
|
570
|
+
polling_island_delete(exec_ctx, pi);
|
571
|
+
pi = NULL;
|
572
|
+
}
|
573
|
+
return pi;
|
574
|
+
}
|
575
|
+
|
576
|
+
static void polling_island_delete(grpc_exec_ctx *exec_ctx, polling_island *pi) {
|
577
|
+
GPR_ASSERT(pi->fd_cnt == 0);
|
578
|
+
|
579
|
+
if (pi->epoll_fd >= 0) {
|
580
|
+
close(pi->epoll_fd);
|
581
|
+
}
|
582
|
+
GPR_ASSERT(gpr_atm_no_barrier_load(&pi->workqueue_item_count) == 0);
|
583
|
+
gpr_mu_destroy(&pi->workqueue_read_mu);
|
584
|
+
gpr_mpscq_destroy(&pi->workqueue_items);
|
585
|
+
gpr_mu_destroy(&pi->mu);
|
586
|
+
grpc_wakeup_fd_destroy(&pi->workqueue_wakeup_fd);
|
587
|
+
gpr_free(pi->fds);
|
588
|
+
gpr_free(pi);
|
589
|
+
}
|
590
|
+
|
591
|
+
/* Attempts to gets the last polling island in the linked list (liked by the
|
592
|
+
* 'merged_to' field). Since this does not lock the polling island, there are no
|
593
|
+
* guarantees that the island returned is the last island */
|
594
|
+
static polling_island *polling_island_maybe_get_latest(polling_island *pi) {
|
595
|
+
polling_island *next = (polling_island *)gpr_atm_acq_load(&pi->merged_to);
|
596
|
+
while (next != NULL) {
|
597
|
+
pi = next;
|
598
|
+
next = (polling_island *)gpr_atm_acq_load(&pi->merged_to);
|
599
|
+
}
|
600
|
+
|
601
|
+
return pi;
|
602
|
+
}
|
603
|
+
|
604
|
+
/* Gets the lock on the *latest* polling island i.e the last polling island in
|
605
|
+
the linked list (linked by the 'merged_to' field). Call gpr_mu_unlock on the
|
606
|
+
returned polling island's mu.
|
607
|
+
Usage: To lock/unlock polling island "pi", do the following:
|
608
|
+
polling_island *pi_latest = polling_island_lock(pi);
|
609
|
+
...
|
610
|
+
... critical section ..
|
611
|
+
...
|
612
|
+
gpr_mu_unlock(&pi_latest->mu); // NOTE: use pi_latest->mu. NOT pi->mu */
|
613
|
+
static polling_island *polling_island_lock(polling_island *pi) {
|
614
|
+
polling_island *next = NULL;
|
615
|
+
|
616
|
+
while (true) {
|
617
|
+
next = (polling_island *)gpr_atm_acq_load(&pi->merged_to);
|
618
|
+
if (next == NULL) {
|
619
|
+
/* Looks like 'pi' is the last node in the linked list but unless we check
|
620
|
+
this by holding the pi->mu lock, we cannot be sure (i.e without the
|
621
|
+
pi->mu lock, we don't prevent island merges).
|
622
|
+
To be absolutely sure, check once more by holding the pi->mu lock */
|
623
|
+
gpr_mu_lock(&pi->mu);
|
624
|
+
next = (polling_island *)gpr_atm_acq_load(&pi->merged_to);
|
625
|
+
if (next == NULL) {
|
626
|
+
/* pi is infact the last node and we have the pi->mu lock. we're done */
|
627
|
+
break;
|
628
|
+
}
|
629
|
+
|
630
|
+
/* pi->merged_to is not NULL i.e pi isn't the last node anymore. pi->mu
|
631
|
+
* isn't the lock we are interested in. Continue traversing the list */
|
632
|
+
gpr_mu_unlock(&pi->mu);
|
633
|
+
}
|
634
|
+
|
635
|
+
pi = next;
|
636
|
+
}
|
637
|
+
|
638
|
+
return pi;
|
639
|
+
}
|
640
|
+
|
641
|
+
/* Gets the lock on the *latest* polling islands in the linked lists pointed by
|
642
|
+
*p and *q (and also updates *p and *q to point to the latest polling islands)
|
643
|
+
|
644
|
+
This function is needed because calling the following block of code to obtain
|
645
|
+
locks on polling islands (*p and *q) is prone to deadlocks.
|
646
|
+
{
|
647
|
+
polling_island_lock(*p, true);
|
648
|
+
polling_island_lock(*q, true);
|
649
|
+
}
|
650
|
+
|
651
|
+
Usage/example:
|
652
|
+
polling_island *p1;
|
653
|
+
polling_island *p2;
|
654
|
+
..
|
655
|
+
polling_island_lock_pair(&p1, &p2);
|
656
|
+
..
|
657
|
+
.. Critical section with both p1 and p2 locked
|
658
|
+
..
|
659
|
+
// Release locks: Always call polling_island_unlock_pair() to release locks
|
660
|
+
polling_island_unlock_pair(p1, p2);
|
661
|
+
*/
|
662
|
+
static void polling_island_lock_pair(polling_island **p, polling_island **q) {
|
663
|
+
polling_island *pi_1 = *p;
|
664
|
+
polling_island *pi_2 = *q;
|
665
|
+
polling_island *next_1 = NULL;
|
666
|
+
polling_island *next_2 = NULL;
|
667
|
+
|
668
|
+
/* The algorithm is simple:
|
669
|
+
- Go to the last polling islands in the linked lists *pi_1 and *pi_2 (and
|
670
|
+
keep updating pi_1 and pi_2)
|
671
|
+
- Then obtain locks on the islands by following a lock order rule of
|
672
|
+
locking polling_island with lower address first
|
673
|
+
Special case: Before obtaining the locks, check if pi_1 and pi_2 are
|
674
|
+
pointing to the same island. If that is the case, we can just call
|
675
|
+
polling_island_lock()
|
676
|
+
- After obtaining both the locks, double check that the polling islands
|
677
|
+
are still the last polling islands in their respective linked lists
|
678
|
+
(this is because there might have been polling island merges before
|
679
|
+
we got the lock)
|
680
|
+
- If the polling islands are the last islands, we are done. If not,
|
681
|
+
release the locks and continue the process from the first step */
|
682
|
+
while (true) {
|
683
|
+
next_1 = (polling_island *)gpr_atm_acq_load(&pi_1->merged_to);
|
684
|
+
while (next_1 != NULL) {
|
685
|
+
pi_1 = next_1;
|
686
|
+
next_1 = (polling_island *)gpr_atm_acq_load(&pi_1->merged_to);
|
687
|
+
}
|
688
|
+
|
689
|
+
next_2 = (polling_island *)gpr_atm_acq_load(&pi_2->merged_to);
|
690
|
+
while (next_2 != NULL) {
|
691
|
+
pi_2 = next_2;
|
692
|
+
next_2 = (polling_island *)gpr_atm_acq_load(&pi_2->merged_to);
|
693
|
+
}
|
694
|
+
|
695
|
+
if (pi_1 == pi_2) {
|
696
|
+
pi_1 = pi_2 = polling_island_lock(pi_1);
|
697
|
+
break;
|
698
|
+
}
|
699
|
+
|
700
|
+
if (pi_1 < pi_2) {
|
701
|
+
gpr_mu_lock(&pi_1->mu);
|
702
|
+
gpr_mu_lock(&pi_2->mu);
|
703
|
+
} else {
|
704
|
+
gpr_mu_lock(&pi_2->mu);
|
705
|
+
gpr_mu_lock(&pi_1->mu);
|
706
|
+
}
|
707
|
+
|
708
|
+
next_1 = (polling_island *)gpr_atm_acq_load(&pi_1->merged_to);
|
709
|
+
next_2 = (polling_island *)gpr_atm_acq_load(&pi_2->merged_to);
|
710
|
+
if (next_1 == NULL && next_2 == NULL) {
|
711
|
+
break;
|
712
|
+
}
|
713
|
+
|
714
|
+
gpr_mu_unlock(&pi_1->mu);
|
715
|
+
gpr_mu_unlock(&pi_2->mu);
|
716
|
+
}
|
717
|
+
|
718
|
+
*p = pi_1;
|
719
|
+
*q = pi_2;
|
720
|
+
}
|
721
|
+
|
722
|
+
static void polling_island_unlock_pair(polling_island *p, polling_island *q) {
|
723
|
+
if (p == q) {
|
724
|
+
gpr_mu_unlock(&p->mu);
|
725
|
+
} else {
|
726
|
+
gpr_mu_unlock(&p->mu);
|
727
|
+
gpr_mu_unlock(&q->mu);
|
728
|
+
}
|
729
|
+
}
|
730
|
+
|
731
|
+
static void workqueue_maybe_wakeup(polling_island *pi) {
|
732
|
+
/* If this thread is the current poller, then it may be that it's about to
|
733
|
+
decrement the current poller count, so we need to look past this thread */
|
734
|
+
bool is_current_poller = (g_current_thread_polling_island == pi);
|
735
|
+
gpr_atm min_current_pollers_for_wakeup = is_current_poller ? 1 : 0;
|
736
|
+
gpr_atm current_pollers = gpr_atm_no_barrier_load(&pi->poller_count);
|
737
|
+
/* Only issue a wakeup if it's likely that some poller could come in and take
|
738
|
+
it right now. Note that since we do an anticipatory mpscq_pop every poll
|
739
|
+
loop, it's ok if we miss the wakeup here, as we'll get the work item when
|
740
|
+
the next poller enters anyway. */
|
741
|
+
if (current_pollers > min_current_pollers_for_wakeup) {
|
742
|
+
GRPC_LOG_IF_ERROR("workqueue_wakeup_fd",
|
743
|
+
grpc_wakeup_fd_wakeup(&pi->workqueue_wakeup_fd));
|
744
|
+
}
|
745
|
+
}
|
746
|
+
|
747
|
+
static void workqueue_move_items_to_parent(polling_island *q) {
|
748
|
+
polling_island *p = (polling_island *)gpr_atm_no_barrier_load(&q->merged_to);
|
749
|
+
if (p == NULL) {
|
750
|
+
return;
|
751
|
+
}
|
752
|
+
gpr_mu_lock(&q->workqueue_read_mu);
|
753
|
+
int num_added = 0;
|
754
|
+
while (gpr_atm_no_barrier_load(&q->workqueue_item_count) > 0) {
|
755
|
+
gpr_mpscq_node *n = gpr_mpscq_pop(&q->workqueue_items);
|
756
|
+
if (n != NULL) {
|
757
|
+
gpr_atm_no_barrier_fetch_add(&q->workqueue_item_count, -1);
|
758
|
+
gpr_atm_no_barrier_fetch_add(&p->workqueue_item_count, 1);
|
759
|
+
gpr_mpscq_push(&p->workqueue_items, n);
|
760
|
+
num_added++;
|
761
|
+
}
|
762
|
+
}
|
763
|
+
gpr_mu_unlock(&q->workqueue_read_mu);
|
764
|
+
if (num_added > 0) {
|
765
|
+
workqueue_maybe_wakeup(p);
|
766
|
+
}
|
767
|
+
workqueue_move_items_to_parent(p);
|
768
|
+
}
|
769
|
+
|
770
|
+
static polling_island *polling_island_merge(polling_island *p,
|
771
|
+
polling_island *q,
|
772
|
+
grpc_error **error) {
|
773
|
+
/* Get locks on both the polling islands */
|
774
|
+
polling_island_lock_pair(&p, &q);
|
775
|
+
|
776
|
+
if (p != q) {
|
777
|
+
/* Make sure that p points to the polling island with fewer fds than q */
|
778
|
+
if (p->fd_cnt > q->fd_cnt) {
|
779
|
+
GPR_SWAP(polling_island *, p, q);
|
780
|
+
}
|
781
|
+
|
782
|
+
/* Merge p with q i.e move all the fds from p (The one with fewer fds) to q
|
783
|
+
Note that the refcounts on the fds being moved will not change here.
|
784
|
+
This is why the last param in the following two functions is 'false') */
|
785
|
+
polling_island_add_fds_locked(q, p->fds, p->fd_cnt, false, error);
|
786
|
+
polling_island_remove_all_fds_locked(p, false, error);
|
787
|
+
|
788
|
+
/* Wakeup all the pollers (if any) on p so that they pickup this change */
|
789
|
+
polling_island_add_wakeup_fd_locked(p, &polling_island_wakeup_fd, error);
|
790
|
+
|
791
|
+
/* Add the 'merged_to' link from p --> q */
|
792
|
+
gpr_atm_rel_store(&p->merged_to, (gpr_atm)q);
|
793
|
+
PI_ADD_REF(q, "pi_merge"); /* To account for the new incoming ref from p */
|
794
|
+
|
795
|
+
workqueue_move_items_to_parent(p);
|
796
|
+
}
|
797
|
+
/* else if p == q, nothing needs to be done */
|
798
|
+
|
799
|
+
polling_island_unlock_pair(p, q);
|
800
|
+
|
801
|
+
/* Return the merged polling island (Note that no merge would have happened
|
802
|
+
if p == q which is ok) */
|
803
|
+
return q;
|
804
|
+
}
|
805
|
+
|
806
|
+
static void workqueue_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
|
807
|
+
grpc_error *error) {
|
808
|
+
GPR_TIMER_BEGIN("workqueue.enqueue", 0);
|
809
|
+
grpc_workqueue *workqueue = (grpc_workqueue *)closure->scheduler;
|
810
|
+
/* take a ref to the workqueue: otherwise it can happen that whatever events
|
811
|
+
* this kicks off ends up destroying the workqueue before this function
|
812
|
+
* completes */
|
813
|
+
GRPC_WORKQUEUE_REF(workqueue, "enqueue");
|
814
|
+
polling_island *pi = (polling_island *)workqueue;
|
815
|
+
gpr_atm last = gpr_atm_no_barrier_fetch_add(&pi->workqueue_item_count, 1);
|
816
|
+
closure->error_data.error = error;
|
817
|
+
gpr_mpscq_push(&pi->workqueue_items, &closure->next_data.atm_next);
|
818
|
+
if (last == 0) {
|
819
|
+
workqueue_maybe_wakeup(pi);
|
820
|
+
}
|
821
|
+
workqueue_move_items_to_parent(pi);
|
822
|
+
GRPC_WORKQUEUE_UNREF(exec_ctx, workqueue, "enqueue");
|
823
|
+
GPR_TIMER_END("workqueue.enqueue", 0);
|
824
|
+
}
|
825
|
+
|
826
|
+
static grpc_closure_scheduler *workqueue_scheduler(grpc_workqueue *workqueue) {
|
827
|
+
polling_island *pi = (polling_island *)workqueue;
|
828
|
+
return workqueue == NULL ? grpc_schedule_on_exec_ctx
|
829
|
+
: &pi->workqueue_scheduler;
|
830
|
+
}
|
831
|
+
|
832
|
+
static grpc_error *polling_island_global_init() {
|
833
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
834
|
+
|
835
|
+
error = grpc_wakeup_fd_init(&polling_island_wakeup_fd);
|
836
|
+
if (error == GRPC_ERROR_NONE) {
|
837
|
+
error = grpc_wakeup_fd_wakeup(&polling_island_wakeup_fd);
|
838
|
+
}
|
839
|
+
|
840
|
+
return error;
|
841
|
+
}
|
842
|
+
|
843
|
+
static void polling_island_global_shutdown() {
|
844
|
+
grpc_wakeup_fd_destroy(&polling_island_wakeup_fd);
|
845
|
+
}
|
846
|
+
|
847
|
+
/*******************************************************************************
|
848
|
+
* Fd Definitions
|
849
|
+
*/
|
850
|
+
|
851
|
+
/* We need to keep a freelist not because of any concerns of malloc performance
|
852
|
+
* but instead so that implementations with multiple threads in (for example)
|
853
|
+
* epoll_wait deal with the race between pollset removal and incoming poll
|
854
|
+
* notifications.
|
855
|
+
*
|
856
|
+
* The problem is that the poller ultimately holds a reference to this
|
857
|
+
* object, so it is very difficult to know when is safe to free it, at least
|
858
|
+
* without some expensive synchronization.
|
859
|
+
*
|
860
|
+
* If we keep the object freelisted, in the worst case losing this race just
|
861
|
+
* becomes a spurious read notification on a reused fd.
|
862
|
+
*/
|
863
|
+
|
864
|
+
/* The alarm system needs to be able to wakeup 'some poller' sometimes
|
865
|
+
* (specifically when a new alarm needs to be triggered earlier than the next
|
866
|
+
* alarm 'epoch'). This wakeup_fd gives us something to alert on when such a
|
867
|
+
* case occurs. */
|
868
|
+
|
869
|
+
static grpc_fd *fd_freelist = NULL;
|
870
|
+
static gpr_mu fd_freelist_mu;
|
871
|
+
|
872
|
+
#ifdef GRPC_FD_REF_COUNT_DEBUG
|
873
|
+
#define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__)
|
874
|
+
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
|
875
|
+
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
|
876
|
+
int line) {
|
877
|
+
gpr_log(GPR_DEBUG, "FD %d %p ref %d %ld -> %ld [%s; %s:%d]", fd->fd,
|
878
|
+
(void *)fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
879
|
+
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
|
880
|
+
#else
|
881
|
+
#define REF_BY(fd, n, reason) ref_by(fd, n)
|
882
|
+
#define UNREF_BY(fd, n, reason) unref_by(fd, n)
|
883
|
+
static void ref_by(grpc_fd *fd, int n) {
|
884
|
+
#endif
|
885
|
+
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
|
886
|
+
}
|
887
|
+
|
888
|
+
#ifdef GRPC_FD_REF_COUNT_DEBUG
|
889
|
+
static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file,
|
890
|
+
int line) {
|
891
|
+
gpr_atm old;
|
892
|
+
gpr_log(GPR_DEBUG, "FD %d %p unref %d %ld -> %ld [%s; %s:%d]", fd->fd,
|
893
|
+
(void *)fd, n, gpr_atm_no_barrier_load(&fd->refst),
|
894
|
+
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
|
895
|
+
#else
|
896
|
+
static void unref_by(grpc_fd *fd, int n) {
|
897
|
+
gpr_atm old;
|
898
|
+
#endif
|
899
|
+
old = gpr_atm_full_fetch_add(&fd->refst, -n);
|
900
|
+
if (old == n) {
|
901
|
+
/* Add the fd to the freelist */
|
902
|
+
gpr_mu_lock(&fd_freelist_mu);
|
903
|
+
fd->freelist_next = fd_freelist;
|
904
|
+
fd_freelist = fd;
|
905
|
+
grpc_iomgr_unregister_object(&fd->iomgr_object);
|
906
|
+
|
907
|
+
grpc_lfev_destroy(&fd->read_closure);
|
908
|
+
grpc_lfev_destroy(&fd->write_closure);
|
909
|
+
|
910
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
911
|
+
} else {
|
912
|
+
GPR_ASSERT(old > n);
|
913
|
+
}
|
914
|
+
}
|
915
|
+
|
916
|
+
/* Increment refcount by two to avoid changing the orphan bit */
|
917
|
+
#ifdef GRPC_FD_REF_COUNT_DEBUG
|
918
|
+
static void fd_ref(grpc_fd *fd, const char *reason, const char *file,
|
919
|
+
int line) {
|
920
|
+
ref_by(fd, 2, reason, file, line);
|
921
|
+
}
|
922
|
+
|
923
|
+
static void fd_unref(grpc_fd *fd, const char *reason, const char *file,
|
924
|
+
int line) {
|
925
|
+
unref_by(fd, 2, reason, file, line);
|
926
|
+
}
|
927
|
+
#else
|
928
|
+
static void fd_ref(grpc_fd *fd) { ref_by(fd, 2); }
|
929
|
+
static void fd_unref(grpc_fd *fd) { unref_by(fd, 2); }
|
930
|
+
#endif
|
931
|
+
|
932
|
+
static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
|
933
|
+
|
934
|
+
static void fd_global_shutdown(void) {
|
935
|
+
gpr_mu_lock(&fd_freelist_mu);
|
936
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
937
|
+
while (fd_freelist != NULL) {
|
938
|
+
grpc_fd *fd = fd_freelist;
|
939
|
+
fd_freelist = fd_freelist->freelist_next;
|
940
|
+
gpr_mu_destroy(&fd->po.mu);
|
941
|
+
gpr_free(fd);
|
942
|
+
}
|
943
|
+
gpr_mu_destroy(&fd_freelist_mu);
|
944
|
+
}
|
945
|
+
|
946
|
+
static grpc_fd *fd_create(int fd, const char *name) {
|
947
|
+
grpc_fd *new_fd = NULL;
|
948
|
+
|
949
|
+
gpr_mu_lock(&fd_freelist_mu);
|
950
|
+
if (fd_freelist != NULL) {
|
951
|
+
new_fd = fd_freelist;
|
952
|
+
fd_freelist = fd_freelist->freelist_next;
|
953
|
+
}
|
954
|
+
gpr_mu_unlock(&fd_freelist_mu);
|
955
|
+
|
956
|
+
if (new_fd == NULL) {
|
957
|
+
new_fd = gpr_malloc(sizeof(grpc_fd));
|
958
|
+
gpr_mu_init(&new_fd->po.mu);
|
959
|
+
}
|
960
|
+
|
961
|
+
/* Note: It is not really needed to get the new_fd->po.mu lock here. If this
|
962
|
+
* is a newly created fd (or an fd we got from the freelist), no one else
|
963
|
+
* would be holding a lock to it anyway. */
|
964
|
+
gpr_mu_lock(&new_fd->po.mu);
|
965
|
+
new_fd->po.pi = NULL;
|
966
|
+
#ifdef PO_DEBUG
|
967
|
+
new_fd->po.obj_type = POLL_OBJ_FD;
|
968
|
+
#endif
|
969
|
+
|
970
|
+
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
|
971
|
+
new_fd->fd = fd;
|
972
|
+
new_fd->orphaned = false;
|
973
|
+
grpc_lfev_init(&new_fd->read_closure);
|
974
|
+
grpc_lfev_init(&new_fd->write_closure);
|
975
|
+
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
|
976
|
+
|
977
|
+
new_fd->freelist_next = NULL;
|
978
|
+
new_fd->on_done_closure = NULL;
|
979
|
+
|
980
|
+
gpr_mu_unlock(&new_fd->po.mu);
|
981
|
+
|
982
|
+
char *fd_name;
|
983
|
+
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
|
984
|
+
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
|
985
|
+
#ifdef GRPC_FD_REF_COUNT_DEBUG
|
986
|
+
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, (void *)new_fd, fd_name);
|
987
|
+
#endif
|
988
|
+
gpr_free(fd_name);
|
989
|
+
return new_fd;
|
990
|
+
}
|
991
|
+
|
992
|
+
static int fd_wrapped_fd(grpc_fd *fd) {
|
993
|
+
int ret_fd = -1;
|
994
|
+
gpr_mu_lock(&fd->po.mu);
|
995
|
+
if (!fd->orphaned) {
|
996
|
+
ret_fd = fd->fd;
|
997
|
+
}
|
998
|
+
gpr_mu_unlock(&fd->po.mu);
|
999
|
+
|
1000
|
+
return ret_fd;
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
static void fd_orphan(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
1004
|
+
grpc_closure *on_done, int *release_fd,
|
1005
|
+
const char *reason) {
|
1006
|
+
bool is_fd_closed = false;
|
1007
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
1008
|
+
polling_island *unref_pi = NULL;
|
1009
|
+
|
1010
|
+
gpr_mu_lock(&fd->po.mu);
|
1011
|
+
fd->on_done_closure = on_done;
|
1012
|
+
|
1013
|
+
/* If release_fd is not NULL, we should be relinquishing control of the file
|
1014
|
+
descriptor fd->fd (but we still own the grpc_fd structure). */
|
1015
|
+
if (release_fd != NULL) {
|
1016
|
+
*release_fd = fd->fd;
|
1017
|
+
} else {
|
1018
|
+
close(fd->fd);
|
1019
|
+
is_fd_closed = true;
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
fd->orphaned = true;
|
1023
|
+
|
1024
|
+
/* Remove the active status but keep referenced. We want this grpc_fd struct
|
1025
|
+
to be alive (and not added to freelist) until the end of this function */
|
1026
|
+
REF_BY(fd, 1, reason);
|
1027
|
+
|
1028
|
+
/* Remove the fd from the polling island:
|
1029
|
+
- Get a lock on the latest polling island (i.e the last island in the
|
1030
|
+
linked list pointed by fd->po.pi). This is the island that
|
1031
|
+
would actually contain the fd
|
1032
|
+
- Remove the fd from the latest polling island
|
1033
|
+
- Unlock the latest polling island
|
1034
|
+
- Set fd->po.pi to NULL (but remove the ref on the polling island
|
1035
|
+
before doing this.) */
|
1036
|
+
if (fd->po.pi != NULL) {
|
1037
|
+
polling_island *pi_latest = polling_island_lock(fd->po.pi);
|
1038
|
+
polling_island_remove_fd_locked(pi_latest, fd, is_fd_closed, &error);
|
1039
|
+
gpr_mu_unlock(&pi_latest->mu);
|
1040
|
+
|
1041
|
+
unref_pi = fd->po.pi;
|
1042
|
+
fd->po.pi = NULL;
|
1043
|
+
}
|
1044
|
+
|
1045
|
+
grpc_closure_sched(exec_ctx, fd->on_done_closure, GRPC_ERROR_REF(error));
|
1046
|
+
|
1047
|
+
gpr_mu_unlock(&fd->po.mu);
|
1048
|
+
UNREF_BY(fd, 2, reason); /* Drop the reference */
|
1049
|
+
if (unref_pi != NULL) {
|
1050
|
+
/* Unref stale polling island here, outside the fd lock above.
|
1051
|
+
The polling island owns a workqueue which owns an fd, and unreffing
|
1052
|
+
inside the lock can cause an eventual lock loop that makes TSAN very
|
1053
|
+
unhappy. */
|
1054
|
+
PI_UNREF(exec_ctx, unref_pi, "fd_orphan");
|
1055
|
+
}
|
1056
|
+
GRPC_LOG_IF_ERROR("fd_orphan", GRPC_ERROR_REF(error));
|
1057
|
+
GRPC_ERROR_UNREF(error);
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
static grpc_pollset *fd_get_read_notifier_pollset(grpc_exec_ctx *exec_ctx,
|
1061
|
+
grpc_fd *fd) {
|
1062
|
+
gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset);
|
1063
|
+
return (grpc_pollset *)notifier;
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
static bool fd_is_shutdown(grpc_fd *fd) {
|
1067
|
+
return grpc_lfev_is_shutdown(&fd->read_closure);
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
/* Might be called multiple times */
|
1071
|
+
static void fd_shutdown(grpc_exec_ctx *exec_ctx, grpc_fd *fd, grpc_error *why) {
|
1072
|
+
if (grpc_lfev_set_shutdown(exec_ctx, &fd->read_closure,
|
1073
|
+
GRPC_ERROR_REF(why))) {
|
1074
|
+
shutdown(fd->fd, SHUT_RDWR);
|
1075
|
+
grpc_lfev_set_shutdown(exec_ctx, &fd->write_closure, GRPC_ERROR_REF(why));
|
1076
|
+
}
|
1077
|
+
GRPC_ERROR_UNREF(why);
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
static void fd_notify_on_read(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
1081
|
+
grpc_closure *closure) {
|
1082
|
+
grpc_lfev_notify_on(exec_ctx, &fd->read_closure, closure);
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
static void fd_notify_on_write(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
1086
|
+
grpc_closure *closure) {
|
1087
|
+
grpc_lfev_notify_on(exec_ctx, &fd->write_closure, closure);
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
static grpc_workqueue *fd_get_workqueue(grpc_fd *fd) {
|
1091
|
+
gpr_mu_lock(&fd->po.mu);
|
1092
|
+
grpc_workqueue *workqueue =
|
1093
|
+
GRPC_WORKQUEUE_REF((grpc_workqueue *)fd->po.pi, "fd_get_workqueue");
|
1094
|
+
gpr_mu_unlock(&fd->po.mu);
|
1095
|
+
return workqueue;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
/*******************************************************************************
|
1099
|
+
* Pollset Definitions
|
1100
|
+
*/
|
1101
|
+
GPR_TLS_DECL(g_current_thread_pollset);
|
1102
|
+
GPR_TLS_DECL(g_current_thread_worker);
|
1103
|
+
static __thread bool g_initialized_sigmask;
|
1104
|
+
static __thread sigset_t g_orig_sigmask;
|
1105
|
+
|
1106
|
+
static void sig_handler(int sig_num) {
|
1107
|
+
#ifdef GRPC_EPOLL_DEBUG
|
1108
|
+
gpr_log(GPR_INFO, "Received signal %d", sig_num);
|
1109
|
+
#endif
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
static void poller_kick_init() { signal(grpc_wakeup_signal, sig_handler); }
|
1113
|
+
|
1114
|
+
/* Global state management */
|
1115
|
+
static grpc_error *pollset_global_init(void) {
|
1116
|
+
gpr_tls_init(&g_current_thread_pollset);
|
1117
|
+
gpr_tls_init(&g_current_thread_worker);
|
1118
|
+
poller_kick_init();
|
1119
|
+
return grpc_wakeup_fd_init(&global_wakeup_fd);
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
static void pollset_global_shutdown(void) {
|
1123
|
+
grpc_wakeup_fd_destroy(&global_wakeup_fd);
|
1124
|
+
gpr_tls_destroy(&g_current_thread_pollset);
|
1125
|
+
gpr_tls_destroy(&g_current_thread_worker);
|
1126
|
+
}
|
1127
|
+
|
1128
|
+
static grpc_error *pollset_worker_kick(grpc_pollset_worker *worker) {
|
1129
|
+
grpc_error *err = GRPC_ERROR_NONE;
|
1130
|
+
|
1131
|
+
/* Kick the worker only if it was not already kicked */
|
1132
|
+
if (gpr_atm_no_barrier_cas(&worker->is_kicked, (gpr_atm)0, (gpr_atm)1)) {
|
1133
|
+
GRPC_POLLING_TRACE(
|
1134
|
+
"pollset_worker_kick: Kicking worker: %p (thread id: %ld)",
|
1135
|
+
(void *)worker, (long int)worker->pt_id);
|
1136
|
+
int err_num = pthread_kill(worker->pt_id, grpc_wakeup_signal);
|
1137
|
+
if (err_num != 0) {
|
1138
|
+
err = GRPC_OS_ERROR(err_num, "pthread_kill");
|
1139
|
+
}
|
1140
|
+
}
|
1141
|
+
return err;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
/* Return 1 if the pollset has active threads in pollset_work (pollset must
|
1145
|
+
* be locked) */
|
1146
|
+
static int pollset_has_workers(grpc_pollset *p) {
|
1147
|
+
return p->root_worker.next != &p->root_worker;
|
1148
|
+
}
|
1149
|
+
|
1150
|
+
static void remove_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
1151
|
+
worker->prev->next = worker->next;
|
1152
|
+
worker->next->prev = worker->prev;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
static grpc_pollset_worker *pop_front_worker(grpc_pollset *p) {
|
1156
|
+
if (pollset_has_workers(p)) {
|
1157
|
+
grpc_pollset_worker *w = p->root_worker.next;
|
1158
|
+
remove_worker(p, w);
|
1159
|
+
return w;
|
1160
|
+
} else {
|
1161
|
+
return NULL;
|
1162
|
+
}
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
static void push_back_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
1166
|
+
worker->next = &p->root_worker;
|
1167
|
+
worker->prev = worker->next->prev;
|
1168
|
+
worker->prev->next = worker->next->prev = worker;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
static void push_front_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
1172
|
+
worker->prev = &p->root_worker;
|
1173
|
+
worker->next = worker->prev->next;
|
1174
|
+
worker->prev->next = worker->next->prev = worker;
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
/* p->mu must be held before calling this function */
|
1178
|
+
static grpc_error *pollset_kick(grpc_pollset *p,
|
1179
|
+
grpc_pollset_worker *specific_worker) {
|
1180
|
+
GPR_TIMER_BEGIN("pollset_kick", 0);
|
1181
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
1182
|
+
const char *err_desc = "Kick Failure";
|
1183
|
+
grpc_pollset_worker *worker = specific_worker;
|
1184
|
+
if (worker != NULL) {
|
1185
|
+
if (worker == GRPC_POLLSET_KICK_BROADCAST) {
|
1186
|
+
if (pollset_has_workers(p)) {
|
1187
|
+
GPR_TIMER_BEGIN("pollset_kick.broadcast", 0);
|
1188
|
+
for (worker = p->root_worker.next; worker != &p->root_worker;
|
1189
|
+
worker = worker->next) {
|
1190
|
+
if (gpr_tls_get(&g_current_thread_worker) != (intptr_t)worker) {
|
1191
|
+
append_error(&error, pollset_worker_kick(worker), err_desc);
|
1192
|
+
}
|
1193
|
+
}
|
1194
|
+
GPR_TIMER_END("pollset_kick.broadcast", 0);
|
1195
|
+
} else {
|
1196
|
+
p->kicked_without_pollers = true;
|
1197
|
+
}
|
1198
|
+
} else {
|
1199
|
+
GPR_TIMER_MARK("kicked_specifically", 0);
|
1200
|
+
if (gpr_tls_get(&g_current_thread_worker) != (intptr_t)worker) {
|
1201
|
+
append_error(&error, pollset_worker_kick(worker), err_desc);
|
1202
|
+
}
|
1203
|
+
}
|
1204
|
+
} else if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)p) {
|
1205
|
+
/* Since worker == NULL, it means that we can kick "any" worker on this
|
1206
|
+
pollset 'p'. If 'p' happens to be the same pollset this thread is
|
1207
|
+
currently polling (i.e in pollset_work() function), then there is no need
|
1208
|
+
to kick any other worker since the current thread can just absorb the
|
1209
|
+
kick. This is the reason why we enter this case only when
|
1210
|
+
g_current_thread_pollset is != p */
|
1211
|
+
|
1212
|
+
GPR_TIMER_MARK("kick_anonymous", 0);
|
1213
|
+
worker = pop_front_worker(p);
|
1214
|
+
if (worker != NULL) {
|
1215
|
+
GPR_TIMER_MARK("finally_kick", 0);
|
1216
|
+
push_back_worker(p, worker);
|
1217
|
+
append_error(&error, pollset_worker_kick(worker), err_desc);
|
1218
|
+
} else {
|
1219
|
+
GPR_TIMER_MARK("kicked_no_pollers", 0);
|
1220
|
+
p->kicked_without_pollers = true;
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
GPR_TIMER_END("pollset_kick", 0);
|
1225
|
+
GRPC_LOG_IF_ERROR("pollset_kick", GRPC_ERROR_REF(error));
|
1226
|
+
return error;
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
static grpc_error *kick_poller(void) {
|
1230
|
+
return grpc_wakeup_fd_wakeup(&global_wakeup_fd);
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
static void pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
|
1234
|
+
gpr_mu_init(&pollset->po.mu);
|
1235
|
+
*mu = &pollset->po.mu;
|
1236
|
+
pollset->po.pi = NULL;
|
1237
|
+
#ifdef PO_DEBUG
|
1238
|
+
pollset->po.obj_type = POLL_OBJ_POLLSET;
|
1239
|
+
#endif
|
1240
|
+
|
1241
|
+
pollset->root_worker.next = pollset->root_worker.prev = &pollset->root_worker;
|
1242
|
+
pollset->kicked_without_pollers = false;
|
1243
|
+
|
1244
|
+
pollset->shutting_down = false;
|
1245
|
+
pollset->finish_shutdown_called = false;
|
1246
|
+
pollset->shutdown_done = NULL;
|
1247
|
+
}
|
1248
|
+
|
1249
|
+
/* Convert a timespec to milliseconds:
|
1250
|
+
- Very small or negative poll times are clamped to zero to do a non-blocking
|
1251
|
+
poll (which becomes spin polling)
|
1252
|
+
- Other small values are rounded up to one millisecond
|
1253
|
+
- Longer than a millisecond polls are rounded up to the next nearest
|
1254
|
+
millisecond to avoid spinning
|
1255
|
+
- Infinite timeouts are converted to -1 */
|
1256
|
+
static int poll_deadline_to_millis_timeout(gpr_timespec deadline,
|
1257
|
+
gpr_timespec now) {
|
1258
|
+
gpr_timespec timeout;
|
1259
|
+
static const int64_t max_spin_polling_us = 10;
|
1260
|
+
if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) {
|
1261
|
+
return -1;
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros(
|
1265
|
+
max_spin_polling_us,
|
1266
|
+
GPR_TIMESPAN))) <= 0) {
|
1267
|
+
return 0;
|
1268
|
+
}
|
1269
|
+
timeout = gpr_time_sub(deadline, now);
|
1270
|
+
int millis = gpr_time_to_millis(gpr_time_add(
|
1271
|
+
timeout, gpr_time_from_nanos(GPR_NS_PER_MS - 1, GPR_TIMESPAN)));
|
1272
|
+
return millis >= 1 ? millis : 1;
|
1273
|
+
}
|
1274
|
+
|
1275
|
+
static void fd_become_readable(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
1276
|
+
grpc_pollset *notifier) {
|
1277
|
+
grpc_lfev_set_ready(exec_ctx, &fd->read_closure);
|
1278
|
+
|
1279
|
+
/* Note, it is possible that fd_become_readable might be called twice with
|
1280
|
+
different 'notifier's when an fd becomes readable and it is in two epoll
|
1281
|
+
sets (This can happen briefly during polling island merges). In such cases
|
1282
|
+
it does not really matter which notifer is set as the read_notifier_pollset
|
1283
|
+
(They would both point to the same polling island anyway) */
|
1284
|
+
/* Use release store to match with acquire load in fd_get_read_notifier */
|
1285
|
+
gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
static void fd_become_writable(grpc_exec_ctx *exec_ctx, grpc_fd *fd) {
|
1289
|
+
grpc_lfev_set_ready(exec_ctx, &fd->write_closure);
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
static void pollset_release_polling_island(grpc_exec_ctx *exec_ctx,
|
1293
|
+
grpc_pollset *ps, char *reason) {
|
1294
|
+
if (ps->po.pi != NULL) {
|
1295
|
+
PI_UNREF(exec_ctx, ps->po.pi, reason);
|
1296
|
+
}
|
1297
|
+
ps->po.pi = NULL;
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
static void finish_shutdown_locked(grpc_exec_ctx *exec_ctx,
|
1301
|
+
grpc_pollset *pollset) {
|
1302
|
+
/* The pollset cannot have any workers if we are at this stage */
|
1303
|
+
GPR_ASSERT(!pollset_has_workers(pollset));
|
1304
|
+
|
1305
|
+
pollset->finish_shutdown_called = true;
|
1306
|
+
|
1307
|
+
/* Release the ref and set pollset->po.pi to NULL */
|
1308
|
+
pollset_release_polling_island(exec_ctx, pollset, "ps_shutdown");
|
1309
|
+
grpc_closure_sched(exec_ctx, pollset->shutdown_done, GRPC_ERROR_NONE);
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
/* pollset->po.mu lock must be held by the caller before calling this */
|
1313
|
+
static void pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
1314
|
+
grpc_closure *closure) {
|
1315
|
+
GPR_TIMER_BEGIN("pollset_shutdown", 0);
|
1316
|
+
GPR_ASSERT(!pollset->shutting_down);
|
1317
|
+
pollset->shutting_down = true;
|
1318
|
+
pollset->shutdown_done = closure;
|
1319
|
+
pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST);
|
1320
|
+
|
1321
|
+
/* If the pollset has any workers, we cannot call finish_shutdown_locked()
|
1322
|
+
because it would release the underlying polling island. In such a case, we
|
1323
|
+
let the last worker call finish_shutdown_locked() from pollset_work() */
|
1324
|
+
if (!pollset_has_workers(pollset)) {
|
1325
|
+
GPR_ASSERT(!pollset->finish_shutdown_called);
|
1326
|
+
GPR_TIMER_MARK("pollset_shutdown.finish_shutdown_locked", 0);
|
1327
|
+
finish_shutdown_locked(exec_ctx, pollset);
|
1328
|
+
}
|
1329
|
+
GPR_TIMER_END("pollset_shutdown", 0);
|
1330
|
+
}
|
1331
|
+
|
1332
|
+
/* pollset_shutdown is guaranteed to be called before pollset_destroy. So other
|
1333
|
+
* than destroying the mutexes, there is nothing special that needs to be done
|
1334
|
+
* here */
|
1335
|
+
static void pollset_destroy(grpc_pollset *pollset) {
|
1336
|
+
GPR_ASSERT(!pollset_has_workers(pollset));
|
1337
|
+
gpr_mu_destroy(&pollset->po.mu);
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
static bool maybe_do_workqueue_work(grpc_exec_ctx *exec_ctx,
|
1341
|
+
polling_island *pi) {
|
1342
|
+
if (gpr_mu_trylock(&pi->workqueue_read_mu)) {
|
1343
|
+
gpr_mpscq_node *n = gpr_mpscq_pop(&pi->workqueue_items);
|
1344
|
+
gpr_mu_unlock(&pi->workqueue_read_mu);
|
1345
|
+
if (n != NULL) {
|
1346
|
+
if (gpr_atm_full_fetch_add(&pi->workqueue_item_count, -1) > 1) {
|
1347
|
+
workqueue_maybe_wakeup(pi);
|
1348
|
+
}
|
1349
|
+
grpc_closure *c = (grpc_closure *)n;
|
1350
|
+
grpc_error *error = c->error_data.error;
|
1351
|
+
#ifndef NDEBUG
|
1352
|
+
c->scheduled = false;
|
1353
|
+
#endif
|
1354
|
+
c->cb(exec_ctx, c->cb_arg, error);
|
1355
|
+
GRPC_ERROR_UNREF(error);
|
1356
|
+
return true;
|
1357
|
+
} else if (gpr_atm_no_barrier_load(&pi->workqueue_item_count) > 0) {
|
1358
|
+
/* n == NULL might mean there's work but it's not available to be popped
|
1359
|
+
* yet - try to ensure another workqueue wakes up to check shortly if so
|
1360
|
+
*/
|
1361
|
+
workqueue_maybe_wakeup(pi);
|
1362
|
+
}
|
1363
|
+
}
|
1364
|
+
return false;
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
#define GRPC_EPOLL_MAX_EVENTS 100
|
1368
|
+
/* Note: sig_mask contains the signal mask to use *during* epoll_wait() */
|
1369
|
+
static void pollset_work_and_unlock(grpc_exec_ctx *exec_ctx,
|
1370
|
+
grpc_pollset *pollset,
|
1371
|
+
grpc_pollset_worker *worker, int timeout_ms,
|
1372
|
+
sigset_t *sig_mask, grpc_error **error) {
|
1373
|
+
struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS];
|
1374
|
+
int epoll_fd = -1;
|
1375
|
+
int ep_rv;
|
1376
|
+
polling_island *pi = NULL;
|
1377
|
+
char *err_msg;
|
1378
|
+
const char *err_desc = "pollset_work_and_unlock";
|
1379
|
+
GPR_TIMER_BEGIN("pollset_work_and_unlock", 0);
|
1380
|
+
|
1381
|
+
/* We need to get the epoll_fd to wait on. The epoll_fd is in inside the
|
1382
|
+
latest polling island pointed by pollset->po.pi
|
1383
|
+
|
1384
|
+
Since epoll_fd is immutable, we can read it without obtaining the polling
|
1385
|
+
island lock. There is however a possibility that the polling island (from
|
1386
|
+
which we got the epoll_fd) got merged with another island while we are
|
1387
|
+
in this function. This is still okay because in such a case, we will wakeup
|
1388
|
+
right-away from epoll_wait() and pick up the latest polling_island the next
|
1389
|
+
this function (i.e pollset_work_and_unlock()) is called */
|
1390
|
+
|
1391
|
+
if (pollset->po.pi == NULL) {
|
1392
|
+
pollset->po.pi = polling_island_create(exec_ctx, NULL, error);
|
1393
|
+
if (pollset->po.pi == NULL) {
|
1394
|
+
GPR_TIMER_END("pollset_work_and_unlock", 0);
|
1395
|
+
return; /* Fatal error. We cannot continue */
|
1396
|
+
}
|
1397
|
+
|
1398
|
+
PI_ADD_REF(pollset->po.pi, "ps");
|
1399
|
+
GRPC_POLLING_TRACE("pollset_work: pollset: %p created new pi: %p",
|
1400
|
+
(void *)pollset, (void *)pollset->po.pi);
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
pi = polling_island_maybe_get_latest(pollset->po.pi);
|
1404
|
+
epoll_fd = pi->epoll_fd;
|
1405
|
+
|
1406
|
+
/* Update the pollset->po.pi since the island being pointed by
|
1407
|
+
pollset->po.pi maybe older than the one pointed by pi) */
|
1408
|
+
if (pollset->po.pi != pi) {
|
1409
|
+
/* Always do PI_ADD_REF before PI_UNREF because PI_UNREF may cause the
|
1410
|
+
polling island to be deleted */
|
1411
|
+
PI_ADD_REF(pi, "ps");
|
1412
|
+
PI_UNREF(exec_ctx, pollset->po.pi, "ps");
|
1413
|
+
pollset->po.pi = pi;
|
1414
|
+
}
|
1415
|
+
|
1416
|
+
/* Add an extra ref so that the island does not get destroyed (which means
|
1417
|
+
the epoll_fd won't be closed) while we are are doing an epoll_wait() on the
|
1418
|
+
epoll_fd */
|
1419
|
+
PI_ADD_REF(pi, "ps_work");
|
1420
|
+
gpr_mu_unlock(&pollset->po.mu);
|
1421
|
+
|
1422
|
+
/* If we get some workqueue work to do, it might end up completing an item on
|
1423
|
+
the completion queue, so there's no need to poll... so we skip that and
|
1424
|
+
redo the complete loop to verify */
|
1425
|
+
if (!maybe_do_workqueue_work(exec_ctx, pi)) {
|
1426
|
+
gpr_atm_no_barrier_fetch_add(&pi->poller_count, 1);
|
1427
|
+
g_current_thread_polling_island = pi;
|
1428
|
+
|
1429
|
+
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
1430
|
+
ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms,
|
1431
|
+
sig_mask);
|
1432
|
+
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
1433
|
+
if (ep_rv < 0) {
|
1434
|
+
if (errno != EINTR) {
|
1435
|
+
gpr_asprintf(&err_msg,
|
1436
|
+
"epoll_wait() epoll fd: %d failed with error: %d (%s)",
|
1437
|
+
epoll_fd, errno, strerror(errno));
|
1438
|
+
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc);
|
1439
|
+
} else {
|
1440
|
+
/* We were interrupted. Save an interation by doing a zero timeout
|
1441
|
+
epoll_wait to see if there are any other events of interest */
|
1442
|
+
GRPC_POLLING_TRACE(
|
1443
|
+
"pollset_work: pollset: %p, worker: %p received kick",
|
1444
|
+
(void *)pollset, (void *)worker);
|
1445
|
+
ep_rv = epoll_wait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, 0);
|
1446
|
+
}
|
1447
|
+
}
|
1448
|
+
|
1449
|
+
#ifdef GRPC_TSAN
|
1450
|
+
/* See the definition of g_poll_sync for more details */
|
1451
|
+
gpr_atm_acq_load(&g_epoll_sync);
|
1452
|
+
#endif /* defined(GRPC_TSAN) */
|
1453
|
+
|
1454
|
+
for (int i = 0; i < ep_rv; ++i) {
|
1455
|
+
void *data_ptr = ep_ev[i].data.ptr;
|
1456
|
+
if (data_ptr == &global_wakeup_fd) {
|
1457
|
+
grpc_timer_consume_kick();
|
1458
|
+
append_error(error, grpc_wakeup_fd_consume_wakeup(&global_wakeup_fd),
|
1459
|
+
err_desc);
|
1460
|
+
} else if (data_ptr == &pi->workqueue_wakeup_fd) {
|
1461
|
+
append_error(error,
|
1462
|
+
grpc_wakeup_fd_consume_wakeup(&pi->workqueue_wakeup_fd),
|
1463
|
+
err_desc);
|
1464
|
+
maybe_do_workqueue_work(exec_ctx, pi);
|
1465
|
+
} else if (data_ptr == &polling_island_wakeup_fd) {
|
1466
|
+
GRPC_POLLING_TRACE(
|
1467
|
+
"pollset_work: pollset: %p, worker: %p polling island (epoll_fd: "
|
1468
|
+
"%d) got merged",
|
1469
|
+
(void *)pollset, (void *)worker, epoll_fd);
|
1470
|
+
/* This means that our polling island is merged with a different
|
1471
|
+
island. We do not have to do anything here since the subsequent call
|
1472
|
+
to the function pollset_work_and_unlock() will pick up the correct
|
1473
|
+
epoll_fd */
|
1474
|
+
} else {
|
1475
|
+
grpc_fd *fd = data_ptr;
|
1476
|
+
int cancel = ep_ev[i].events & (EPOLLERR | EPOLLHUP);
|
1477
|
+
int read_ev = ep_ev[i].events & (EPOLLIN | EPOLLPRI);
|
1478
|
+
int write_ev = ep_ev[i].events & EPOLLOUT;
|
1479
|
+
if (read_ev || cancel) {
|
1480
|
+
fd_become_readable(exec_ctx, fd, pollset);
|
1481
|
+
}
|
1482
|
+
if (write_ev || cancel) {
|
1483
|
+
fd_become_writable(exec_ctx, fd);
|
1484
|
+
}
|
1485
|
+
}
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
g_current_thread_polling_island = NULL;
|
1489
|
+
gpr_atm_no_barrier_fetch_add(&pi->poller_count, -1);
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
GPR_ASSERT(pi != NULL);
|
1493
|
+
|
1494
|
+
/* Before leaving, release the extra ref we added to the polling island. It
|
1495
|
+
is important to use "pi" here (i.e our old copy of pollset->po.pi
|
1496
|
+
that we got before releasing the polling island lock). This is because
|
1497
|
+
pollset->po.pi pointer might get udpated in other parts of the
|
1498
|
+
code when there is an island merge while we are doing epoll_wait() above */
|
1499
|
+
PI_UNREF(exec_ctx, pi, "ps_work");
|
1500
|
+
|
1501
|
+
GPR_TIMER_END("pollset_work_and_unlock", 0);
|
1502
|
+
}
|
1503
|
+
|
1504
|
+
/* pollset->po.mu lock must be held by the caller before calling this.
|
1505
|
+
The function pollset_work() may temporarily release the lock (pollset->po.mu)
|
1506
|
+
during the course of its execution but it will always re-acquire the lock and
|
1507
|
+
ensure that it is held by the time the function returns */
|
1508
|
+
static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
1509
|
+
grpc_pollset_worker **worker_hdl,
|
1510
|
+
gpr_timespec now, gpr_timespec deadline) {
|
1511
|
+
GPR_TIMER_BEGIN("pollset_work", 0);
|
1512
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
1513
|
+
int timeout_ms = poll_deadline_to_millis_timeout(deadline, now);
|
1514
|
+
|
1515
|
+
sigset_t new_mask;
|
1516
|
+
|
1517
|
+
grpc_pollset_worker worker;
|
1518
|
+
worker.next = worker.prev = NULL;
|
1519
|
+
worker.pt_id = pthread_self();
|
1520
|
+
gpr_atm_no_barrier_store(&worker.is_kicked, (gpr_atm)0);
|
1521
|
+
|
1522
|
+
if (worker_hdl) *worker_hdl = &worker;
|
1523
|
+
|
1524
|
+
gpr_tls_set(&g_current_thread_pollset, (intptr_t)pollset);
|
1525
|
+
gpr_tls_set(&g_current_thread_worker, (intptr_t)&worker);
|
1526
|
+
|
1527
|
+
if (pollset->kicked_without_pollers) {
|
1528
|
+
/* If the pollset was kicked without pollers, pretend that the current
|
1529
|
+
worker got the kick and skip polling. A kick indicates that there is some
|
1530
|
+
work that needs attention like an event on the completion queue or an
|
1531
|
+
alarm */
|
1532
|
+
GPR_TIMER_MARK("pollset_work.kicked_without_pollers", 0);
|
1533
|
+
pollset->kicked_without_pollers = 0;
|
1534
|
+
} else if (!pollset->shutting_down) {
|
1535
|
+
/* We use the posix-signal with number 'grpc_wakeup_signal' for waking up
|
1536
|
+
(i.e 'kicking') a worker in the pollset. A 'kick' is a way to inform the
|
1537
|
+
worker that there is some pending work that needs immediate attention
|
1538
|
+
(like an event on the completion queue, or a polling island merge that
|
1539
|
+
results in a new epoll-fd to wait on) and that the worker should not
|
1540
|
+
spend time waiting in epoll_pwait().
|
1541
|
+
|
1542
|
+
A worker can be kicked anytime from the point it is added to the pollset
|
1543
|
+
via push_front_worker() (or push_back_worker()) to the point it is
|
1544
|
+
removed via remove_worker().
|
1545
|
+
If the worker is kicked before/during it calls epoll_pwait(), it should
|
1546
|
+
immediately exit from epoll_wait(). If the worker is kicked after it
|
1547
|
+
returns from epoll_wait(), then nothing really needs to be done.
|
1548
|
+
|
1549
|
+
To accomplish this, we mask 'grpc_wakeup_signal' on this thread at all
|
1550
|
+
times *except* when it is in epoll_pwait(). This way, the worker never
|
1551
|
+
misses acting on a kick */
|
1552
|
+
|
1553
|
+
if (!g_initialized_sigmask) {
|
1554
|
+
sigemptyset(&new_mask);
|
1555
|
+
sigaddset(&new_mask, grpc_wakeup_signal);
|
1556
|
+
pthread_sigmask(SIG_BLOCK, &new_mask, &g_orig_sigmask);
|
1557
|
+
sigdelset(&g_orig_sigmask, grpc_wakeup_signal);
|
1558
|
+
g_initialized_sigmask = true;
|
1559
|
+
/* new_mask: The new thread mask which blocks 'grpc_wakeup_signal'.
|
1560
|
+
This is the mask used at all times *except during
|
1561
|
+
epoll_wait()*"
|
1562
|
+
g_orig_sigmask: The thread mask which allows 'grpc_wakeup_signal' and
|
1563
|
+
this is the mask to use *during epoll_wait()*
|
1564
|
+
|
1565
|
+
The new_mask is set on the worker before it is added to the pollset
|
1566
|
+
(i.e before it can be kicked) */
|
1567
|
+
}
|
1568
|
+
|
1569
|
+
push_front_worker(pollset, &worker); /* Add worker to pollset */
|
1570
|
+
|
1571
|
+
pollset_work_and_unlock(exec_ctx, pollset, &worker, timeout_ms,
|
1572
|
+
&g_orig_sigmask, &error);
|
1573
|
+
grpc_exec_ctx_flush(exec_ctx);
|
1574
|
+
|
1575
|
+
gpr_mu_lock(&pollset->po.mu);
|
1576
|
+
|
1577
|
+
/* Note: There is no need to reset worker.is_kicked to 0 since we are no
|
1578
|
+
longer going to use this worker */
|
1579
|
+
remove_worker(pollset, &worker);
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
/* If we are the last worker on the pollset (i.e pollset_has_workers() is
|
1583
|
+
false at this point) and the pollset is shutting down, we may have to
|
1584
|
+
finish the shutdown process by calling finish_shutdown_locked().
|
1585
|
+
See pollset_shutdown() for more details.
|
1586
|
+
|
1587
|
+
Note: Continuing to access pollset here is safe; it is the caller's
|
1588
|
+
responsibility to not destroy a pollset when it has outstanding calls to
|
1589
|
+
pollset_work() */
|
1590
|
+
if (pollset->shutting_down && !pollset_has_workers(pollset) &&
|
1591
|
+
!pollset->finish_shutdown_called) {
|
1592
|
+
GPR_TIMER_MARK("pollset_work.finish_shutdown_locked", 0);
|
1593
|
+
finish_shutdown_locked(exec_ctx, pollset);
|
1594
|
+
|
1595
|
+
gpr_mu_unlock(&pollset->po.mu);
|
1596
|
+
grpc_exec_ctx_flush(exec_ctx);
|
1597
|
+
gpr_mu_lock(&pollset->po.mu);
|
1598
|
+
}
|
1599
|
+
|
1600
|
+
if (worker_hdl) *worker_hdl = NULL;
|
1601
|
+
|
1602
|
+
gpr_tls_set(&g_current_thread_pollset, (intptr_t)0);
|
1603
|
+
gpr_tls_set(&g_current_thread_worker, (intptr_t)0);
|
1604
|
+
|
1605
|
+
GPR_TIMER_END("pollset_work", 0);
|
1606
|
+
|
1607
|
+
GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error));
|
1608
|
+
return error;
|
1609
|
+
}
|
1610
|
+
|
1611
|
+
static void add_poll_object(grpc_exec_ctx *exec_ctx, poll_obj *bag,
|
1612
|
+
poll_obj_type bag_type, poll_obj *item,
|
1613
|
+
poll_obj_type item_type) {
|
1614
|
+
GPR_TIMER_BEGIN("add_poll_object", 0);
|
1615
|
+
|
1616
|
+
#ifdef PO_DEBUG
|
1617
|
+
GPR_ASSERT(item->obj_type == item_type);
|
1618
|
+
GPR_ASSERT(bag->obj_type == bag_type);
|
1619
|
+
#endif
|
1620
|
+
|
1621
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
1622
|
+
polling_island *pi_new = NULL;
|
1623
|
+
|
1624
|
+
gpr_mu_lock(&bag->mu);
|
1625
|
+
gpr_mu_lock(&item->mu);
|
1626
|
+
|
1627
|
+
retry:
|
1628
|
+
/*
|
1629
|
+
* 1) If item->pi and bag->pi are both non-NULL and equal, do nothing
|
1630
|
+
* 2) If item->pi and bag->pi are both NULL, create a new polling island (with
|
1631
|
+
* a refcount of 2) and point item->pi and bag->pi to the new island
|
1632
|
+
* 3) If exactly one of item->pi or bag->pi is NULL, update it to point to
|
1633
|
+
* the other's non-NULL pi
|
1634
|
+
* 4) Finally if item->pi and bag-pi are non-NULL and not-equal, merge the
|
1635
|
+
* polling islands and update item->pi and bag->pi to point to the new
|
1636
|
+
* island
|
1637
|
+
*/
|
1638
|
+
|
1639
|
+
/* Early out if we are trying to add an 'fd' to a 'bag' but the fd is already
|
1640
|
+
* orphaned */
|
1641
|
+
if (item_type == POLL_OBJ_FD && (FD_FROM_PO(item))->orphaned) {
|
1642
|
+
gpr_mu_unlock(&item->mu);
|
1643
|
+
gpr_mu_unlock(&bag->mu);
|
1644
|
+
return;
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
if (item->pi == bag->pi) {
|
1648
|
+
pi_new = item->pi;
|
1649
|
+
if (pi_new == NULL) {
|
1650
|
+
/* GPR_ASSERT(item->pi == bag->pi == NULL) */
|
1651
|
+
|
1652
|
+
/* If we are adding an fd to a bag (i.e pollset or pollset_set), then
|
1653
|
+
* we need to do some extra work to make TSAN happy */
|
1654
|
+
if (item_type == POLL_OBJ_FD) {
|
1655
|
+
/* Unlock before creating a new polling island: the polling island will
|
1656
|
+
create a workqueue which creates a file descriptor, and holding an fd
|
1657
|
+
lock here can eventually cause a loop to appear to TSAN (making it
|
1658
|
+
unhappy). We don't think it's a real loop (there's an epoch point
|
1659
|
+
where that loop possibility disappears), but the advantages of
|
1660
|
+
keeping TSAN happy outweigh any performance advantage we might have
|
1661
|
+
by keeping the lock held. */
|
1662
|
+
gpr_mu_unlock(&item->mu);
|
1663
|
+
pi_new = polling_island_create(exec_ctx, FD_FROM_PO(item), &error);
|
1664
|
+
gpr_mu_lock(&item->mu);
|
1665
|
+
|
1666
|
+
/* Need to reverify any assumptions made between the initial lock and
|
1667
|
+
getting to this branch: if they've changed, we need to throw away our
|
1668
|
+
work and figure things out again. */
|
1669
|
+
if (item->pi != NULL) {
|
1670
|
+
GRPC_POLLING_TRACE(
|
1671
|
+
"add_poll_object: Raced creating new polling island. pi_new: %p "
|
1672
|
+
"(fd: %d, %s: %p)",
|
1673
|
+
(void *)pi_new, FD_FROM_PO(item)->fd, poll_obj_string(bag_type),
|
1674
|
+
(void *)bag);
|
1675
|
+
/* No need to lock 'pi_new' here since this is a new polling island
|
1676
|
+
and no one has a reference to it yet */
|
1677
|
+
polling_island_remove_all_fds_locked(pi_new, true, &error);
|
1678
|
+
|
1679
|
+
/* Ref and unref so that the polling island gets deleted during unref
|
1680
|
+
*/
|
1681
|
+
PI_ADD_REF(pi_new, "dance_of_destruction");
|
1682
|
+
PI_UNREF(exec_ctx, pi_new, "dance_of_destruction");
|
1683
|
+
goto retry;
|
1684
|
+
}
|
1685
|
+
} else {
|
1686
|
+
pi_new = polling_island_create(exec_ctx, NULL, &error);
|
1687
|
+
}
|
1688
|
+
|
1689
|
+
GRPC_POLLING_TRACE(
|
1690
|
+
"add_poll_object: Created new polling island. pi_new: %p (%s: %p, "
|
1691
|
+
"%s: %p)",
|
1692
|
+
(void *)pi_new, poll_obj_string(item_type), (void *)item,
|
1693
|
+
poll_obj_string(bag_type), (void *)bag);
|
1694
|
+
} else {
|
1695
|
+
GRPC_POLLING_TRACE(
|
1696
|
+
"add_poll_object: Same polling island. pi: %p (%s, %s)",
|
1697
|
+
(void *)pi_new, poll_obj_string(item_type),
|
1698
|
+
poll_obj_string(bag_type));
|
1699
|
+
}
|
1700
|
+
} else if (item->pi == NULL) {
|
1701
|
+
/* GPR_ASSERT(bag->pi != NULL) */
|
1702
|
+
/* Make pi_new point to latest pi*/
|
1703
|
+
pi_new = polling_island_lock(bag->pi);
|
1704
|
+
|
1705
|
+
if (item_type == POLL_OBJ_FD) {
|
1706
|
+
grpc_fd *fd = FD_FROM_PO(item);
|
1707
|
+
polling_island_add_fds_locked(pi_new, &fd, 1, true, &error);
|
1708
|
+
}
|
1709
|
+
|
1710
|
+
gpr_mu_unlock(&pi_new->mu);
|
1711
|
+
GRPC_POLLING_TRACE(
|
1712
|
+
"add_poll_obj: item->pi was NULL. pi_new: %p (item(%s): %p, "
|
1713
|
+
"bag(%s): %p)",
|
1714
|
+
(void *)pi_new, poll_obj_string(item_type), (void *)item,
|
1715
|
+
poll_obj_string(bag_type), (void *)bag);
|
1716
|
+
} else if (bag->pi == NULL) {
|
1717
|
+
/* GPR_ASSERT(item->pi != NULL) */
|
1718
|
+
/* Make pi_new to point to latest pi */
|
1719
|
+
pi_new = polling_island_lock(item->pi);
|
1720
|
+
gpr_mu_unlock(&pi_new->mu);
|
1721
|
+
GRPC_POLLING_TRACE(
|
1722
|
+
"add_poll_obj: bag->pi was NULL. pi_new: %p (item(%s): %p, "
|
1723
|
+
"bag(%s): %p)",
|
1724
|
+
(void *)pi_new, poll_obj_string(item_type), (void *)item,
|
1725
|
+
poll_obj_string(bag_type), (void *)bag);
|
1726
|
+
} else {
|
1727
|
+
pi_new = polling_island_merge(item->pi, bag->pi, &error);
|
1728
|
+
GRPC_POLLING_TRACE(
|
1729
|
+
"add_poll_obj: polling islands merged. pi_new: %p (item(%s): %p, "
|
1730
|
+
"bag(%s): %p)",
|
1731
|
+
(void *)pi_new, poll_obj_string(item_type), (void *)item,
|
1732
|
+
poll_obj_string(bag_type), (void *)bag);
|
1733
|
+
}
|
1734
|
+
|
1735
|
+
/* At this point, pi_new is the polling island that both item->pi and bag->pi
|
1736
|
+
MUST be pointing to */
|
1737
|
+
|
1738
|
+
if (item->pi != pi_new) {
|
1739
|
+
PI_ADD_REF(pi_new, poll_obj_string(item_type));
|
1740
|
+
if (item->pi != NULL) {
|
1741
|
+
PI_UNREF(exec_ctx, item->pi, poll_obj_string(item_type));
|
1742
|
+
}
|
1743
|
+
item->pi = pi_new;
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
if (bag->pi != pi_new) {
|
1747
|
+
PI_ADD_REF(pi_new, poll_obj_string(bag_type));
|
1748
|
+
if (bag->pi != NULL) {
|
1749
|
+
PI_UNREF(exec_ctx, bag->pi, poll_obj_string(bag_type));
|
1750
|
+
}
|
1751
|
+
bag->pi = pi_new;
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
gpr_mu_unlock(&item->mu);
|
1755
|
+
gpr_mu_unlock(&bag->mu);
|
1756
|
+
|
1757
|
+
GRPC_LOG_IF_ERROR("add_poll_object", error);
|
1758
|
+
GPR_TIMER_END("add_poll_object", 0);
|
1759
|
+
}
|
1760
|
+
|
1761
|
+
static void pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
1762
|
+
grpc_fd *fd) {
|
1763
|
+
add_poll_object(exec_ctx, &pollset->po, POLL_OBJ_POLLSET, &fd->po,
|
1764
|
+
POLL_OBJ_FD);
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
/*******************************************************************************
|
1768
|
+
* Pollset-set Definitions
|
1769
|
+
*/
|
1770
|
+
|
1771
|
+
static grpc_pollset_set *pollset_set_create(void) {
|
1772
|
+
grpc_pollset_set *pss = gpr_malloc(sizeof(*pss));
|
1773
|
+
gpr_mu_init(&pss->po.mu);
|
1774
|
+
pss->po.pi = NULL;
|
1775
|
+
#ifdef PO_DEBUG
|
1776
|
+
pss->po.obj_type = POLL_OBJ_POLLSET_SET;
|
1777
|
+
#endif
|
1778
|
+
return pss;
|
1779
|
+
}
|
1780
|
+
|
1781
|
+
static void pollset_set_destroy(grpc_exec_ctx *exec_ctx,
|
1782
|
+
grpc_pollset_set *pss) {
|
1783
|
+
gpr_mu_destroy(&pss->po.mu);
|
1784
|
+
|
1785
|
+
if (pss->po.pi != NULL) {
|
1786
|
+
PI_UNREF(exec_ctx, pss->po.pi, "pss_destroy");
|
1787
|
+
}
|
1788
|
+
|
1789
|
+
gpr_free(pss);
|
1790
|
+
}
|
1791
|
+
|
1792
|
+
static void pollset_set_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
|
1793
|
+
grpc_fd *fd) {
|
1794
|
+
add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &fd->po,
|
1795
|
+
POLL_OBJ_FD);
|
1796
|
+
}
|
1797
|
+
|
1798
|
+
static void pollset_set_del_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
|
1799
|
+
grpc_fd *fd) {
|
1800
|
+
/* Nothing to do */
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
static void pollset_set_add_pollset(grpc_exec_ctx *exec_ctx,
|
1804
|
+
grpc_pollset_set *pss, grpc_pollset *ps) {
|
1805
|
+
add_poll_object(exec_ctx, &pss->po, POLL_OBJ_POLLSET_SET, &ps->po,
|
1806
|
+
POLL_OBJ_POLLSET);
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
static void pollset_set_del_pollset(grpc_exec_ctx *exec_ctx,
|
1810
|
+
grpc_pollset_set *pss, grpc_pollset *ps) {
|
1811
|
+
/* Nothing to do */
|
1812
|
+
}
|
1813
|
+
|
1814
|
+
static void pollset_set_add_pollset_set(grpc_exec_ctx *exec_ctx,
|
1815
|
+
grpc_pollset_set *bag,
|
1816
|
+
grpc_pollset_set *item) {
|
1817
|
+
add_poll_object(exec_ctx, &bag->po, POLL_OBJ_POLLSET_SET, &item->po,
|
1818
|
+
POLL_OBJ_POLLSET_SET);
|
1819
|
+
}
|
1820
|
+
|
1821
|
+
static void pollset_set_del_pollset_set(grpc_exec_ctx *exec_ctx,
|
1822
|
+
grpc_pollset_set *bag,
|
1823
|
+
grpc_pollset_set *item) {
|
1824
|
+
/* Nothing to do */
|
1825
|
+
}
|
1826
|
+
|
1827
|
+
/* Test helper functions
|
1828
|
+
* */
|
1829
|
+
void *grpc_fd_get_polling_island(grpc_fd *fd) {
|
1830
|
+
polling_island *pi;
|
1831
|
+
|
1832
|
+
gpr_mu_lock(&fd->po.mu);
|
1833
|
+
pi = fd->po.pi;
|
1834
|
+
gpr_mu_unlock(&fd->po.mu);
|
1835
|
+
|
1836
|
+
return pi;
|
1837
|
+
}
|
1838
|
+
|
1839
|
+
void *grpc_pollset_get_polling_island(grpc_pollset *ps) {
|
1840
|
+
polling_island *pi;
|
1841
|
+
|
1842
|
+
gpr_mu_lock(&ps->po.mu);
|
1843
|
+
pi = ps->po.pi;
|
1844
|
+
gpr_mu_unlock(&ps->po.mu);
|
1845
|
+
|
1846
|
+
return pi;
|
1847
|
+
}
|
1848
|
+
|
1849
|
+
bool grpc_are_polling_islands_equal(void *p, void *q) {
|
1850
|
+
polling_island *p1 = p;
|
1851
|
+
polling_island *p2 = q;
|
1852
|
+
|
1853
|
+
/* Note: polling_island_lock_pair() may change p1 and p2 to point to the
|
1854
|
+
latest polling islands in their respective linked lists */
|
1855
|
+
polling_island_lock_pair(&p1, &p2);
|
1856
|
+
polling_island_unlock_pair(p1, p2);
|
1857
|
+
|
1858
|
+
return p1 == p2;
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
/*******************************************************************************
|
1862
|
+
* Event engine binding
|
1863
|
+
*/
|
1864
|
+
|
1865
|
+
static void shutdown_engine(void) {
|
1866
|
+
fd_global_shutdown();
|
1867
|
+
pollset_global_shutdown();
|
1868
|
+
polling_island_global_shutdown();
|
1869
|
+
}
|
1870
|
+
|
1871
|
+
static const grpc_event_engine_vtable vtable = {
|
1872
|
+
.pollset_size = sizeof(grpc_pollset),
|
1873
|
+
|
1874
|
+
.fd_create = fd_create,
|
1875
|
+
.fd_wrapped_fd = fd_wrapped_fd,
|
1876
|
+
.fd_orphan = fd_orphan,
|
1877
|
+
.fd_shutdown = fd_shutdown,
|
1878
|
+
.fd_is_shutdown = fd_is_shutdown,
|
1879
|
+
.fd_notify_on_read = fd_notify_on_read,
|
1880
|
+
.fd_notify_on_write = fd_notify_on_write,
|
1881
|
+
.fd_get_read_notifier_pollset = fd_get_read_notifier_pollset,
|
1882
|
+
.fd_get_workqueue = fd_get_workqueue,
|
1883
|
+
|
1884
|
+
.pollset_init = pollset_init,
|
1885
|
+
.pollset_shutdown = pollset_shutdown,
|
1886
|
+
.pollset_destroy = pollset_destroy,
|
1887
|
+
.pollset_work = pollset_work,
|
1888
|
+
.pollset_kick = pollset_kick,
|
1889
|
+
.pollset_add_fd = pollset_add_fd,
|
1890
|
+
|
1891
|
+
.pollset_set_create = pollset_set_create,
|
1892
|
+
.pollset_set_destroy = pollset_set_destroy,
|
1893
|
+
.pollset_set_add_pollset = pollset_set_add_pollset,
|
1894
|
+
.pollset_set_del_pollset = pollset_set_del_pollset,
|
1895
|
+
.pollset_set_add_pollset_set = pollset_set_add_pollset_set,
|
1896
|
+
.pollset_set_del_pollset_set = pollset_set_del_pollset_set,
|
1897
|
+
.pollset_set_add_fd = pollset_set_add_fd,
|
1898
|
+
.pollset_set_del_fd = pollset_set_del_fd,
|
1899
|
+
|
1900
|
+
.kick_poller = kick_poller,
|
1901
|
+
|
1902
|
+
.workqueue_ref = workqueue_ref,
|
1903
|
+
.workqueue_unref = workqueue_unref,
|
1904
|
+
.workqueue_scheduler = workqueue_scheduler,
|
1905
|
+
|
1906
|
+
.shutdown_engine = shutdown_engine,
|
1907
|
+
};
|
1908
|
+
|
1909
|
+
/* It is possible that GLIBC has epoll but the underlying kernel doesn't.
|
1910
|
+
* Create a dummy epoll_fd to make sure epoll support is available */
|
1911
|
+
static bool is_epoll_available() {
|
1912
|
+
int fd = epoll_create1(EPOLL_CLOEXEC);
|
1913
|
+
if (fd < 0) {
|
1914
|
+
gpr_log(
|
1915
|
+
GPR_ERROR,
|
1916
|
+
"epoll_create1 failed with error: %d. Not using epoll polling engine",
|
1917
|
+
fd);
|
1918
|
+
return false;
|
1919
|
+
}
|
1920
|
+
close(fd);
|
1921
|
+
return true;
|
1922
|
+
}
|
1923
|
+
|
1924
|
+
const grpc_event_engine_vtable *grpc_init_epoll_linux(void) {
|
1925
|
+
/* If use of signals is disabled, we cannot use epoll engine*/
|
1926
|
+
if (is_grpc_wakeup_signal_initialized && grpc_wakeup_signal < 0) {
|
1927
|
+
return NULL;
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
if (!grpc_has_wakeup_fd()) {
|
1931
|
+
return NULL;
|
1932
|
+
}
|
1933
|
+
|
1934
|
+
if (!is_epoll_available()) {
|
1935
|
+
return NULL;
|
1936
|
+
}
|
1937
|
+
|
1938
|
+
if (!is_grpc_wakeup_signal_initialized) {
|
1939
|
+
grpc_use_signal(SIGRTMIN + 6);
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
fd_global_init();
|
1943
|
+
|
1944
|
+
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
|
1945
|
+
return NULL;
|
1946
|
+
}
|
1947
|
+
|
1948
|
+
if (!GRPC_LOG_IF_ERROR("polling_island_global_init",
|
1949
|
+
polling_island_global_init())) {
|
1950
|
+
return NULL;
|
1951
|
+
}
|
1952
|
+
|
1953
|
+
return &vtable;
|
1954
|
+
}
|
1955
|
+
|
1956
|
+
#else /* defined(GRPC_LINUX_EPOLL) */
|
1957
|
+
#if defined(GRPC_POSIX_SOCKET)
|
1958
|
+
#include "src/core/lib/iomgr/ev_posix.h"
|
1959
|
+
/* If GRPC_LINUX_EPOLL is not defined, it means epoll is not available. Return
|
1960
|
+
* NULL */
|
1961
|
+
const grpc_event_engine_vtable *grpc_init_epoll_linux(void) { return NULL; }
|
1962
|
+
#endif /* defined(GRPC_POSIX_SOCKET) */
|
1963
|
+
|
1964
|
+
void grpc_use_signal(int signum) {}
|
1965
|
+
#endif /* !defined(GRPC_LINUX_EPOLL) */
|