awesome-grpc-that-works 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Makefile +29456 -0
- data/Rakefile +63 -0
- data/etc/roots.pem +5114 -0
- data/include/grpc/byte_buffer.h +120 -0
- data/include/grpc/byte_buffer_reader.h +58 -0
- data/include/grpc/census.h +488 -0
- data/include/grpc/compression.h +106 -0
- data/include/grpc/grpc.h +732 -0
- data/include/grpc/grpc_security.h +374 -0
- data/include/grpc/grpc_zookeeper.h +59 -0
- data/include/grpc/status.h +163 -0
- data/include/grpc/support/alloc.h +72 -0
- data/include/grpc/support/atm.h +92 -0
- data/include/grpc/support/atm_gcc_atomic.h +72 -0
- data/include/grpc/support/atm_gcc_sync.h +87 -0
- data/include/grpc/support/atm_win32.h +125 -0
- data/include/grpc/support/avl.h +91 -0
- data/include/grpc/support/cmdline.h +101 -0
- data/include/grpc/support/cpu.h +57 -0
- data/include/grpc/support/histogram.h +76 -0
- data/include/grpc/support/host_port.h +64 -0
- data/include/grpc/support/log.h +108 -0
- data/include/grpc/support/log_win32.h +51 -0
- data/include/grpc/support/port_platform.h +356 -0
- data/include/grpc/support/slice.h +182 -0
- data/include/grpc/support/slice_buffer.h +102 -0
- data/include/grpc/support/string_util.h +61 -0
- data/include/grpc/support/subprocess.h +57 -0
- data/include/grpc/support/sync.h +315 -0
- data/include/grpc/support/sync_generic.h +55 -0
- data/include/grpc/support/sync_posix.h +47 -0
- data/include/grpc/support/sync_win32.h +49 -0
- data/include/grpc/support/thd.h +91 -0
- data/include/grpc/support/time.h +128 -0
- data/include/grpc/support/tls.h +77 -0
- data/include/grpc/support/tls_gcc.h +56 -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 +75 -0
- data/src/core/census/aggregation.h +66 -0
- data/src/core/census/context.c +46 -0
- data/src/core/census/context.h +47 -0
- data/src/core/census/grpc_context.c +53 -0
- data/src/core/census/grpc_filter.c +184 -0
- data/src/core/census/grpc_filter.h +44 -0
- data/src/core/census/initialize.c +57 -0
- data/src/core/census/operation.c +63 -0
- data/src/core/census/rpc_metric_id.h +51 -0
- data/src/core/census/tracing.c +45 -0
- data/src/core/channel/channel_args.c +209 -0
- data/src/core/channel/channel_args.h +88 -0
- data/src/core/channel/channel_stack.c +262 -0
- data/src/core/channel/channel_stack.h +260 -0
- data/src/core/channel/client_channel.c +524 -0
- data/src/core/channel/client_channel.h +63 -0
- data/src/core/channel/client_uchannel.c +243 -0
- data/src/core/channel/client_uchannel.h +60 -0
- data/src/core/channel/compress_filter.c +297 -0
- data/src/core/channel/compress_filter.h +65 -0
- data/src/core/channel/connected_channel.c +167 -0
- data/src/core/channel/connected_channel.h +51 -0
- data/src/core/channel/context.h +49 -0
- data/src/core/channel/http_client_filter.c +248 -0
- data/src/core/channel/http_client_filter.h +44 -0
- data/src/core/channel/http_server_filter.c +233 -0
- data/src/core/channel/http_server_filter.h +42 -0
- data/src/core/channel/subchannel_call_holder.c +259 -0
- data/src/core/channel/subchannel_call_holder.h +98 -0
- data/src/core/client_config/client_config.c +72 -0
- data/src/core/client_config/client_config.h +53 -0
- data/src/core/client_config/connector.c +54 -0
- data/src/core/client_config/connector.h +95 -0
- data/src/core/client_config/default_initial_connect_string.c +39 -0
- data/src/core/client_config/initial_connect_string.c +53 -0
- data/src/core/client_config/initial_connect_string.h +50 -0
- data/src/core/client_config/lb_policies/pick_first.c +398 -0
- data/src/core/client_config/lb_policies/pick_first.h +43 -0
- data/src/core/client_config/lb_policies/round_robin.c +537 -0
- data/src/core/client_config/lb_policies/round_robin.h +46 -0
- data/src/core/client_config/lb_policy.c +134 -0
- data/src/core/client_config/lb_policy.h +143 -0
- data/src/core/client_config/lb_policy_factory.c +48 -0
- data/src/core/client_config/lb_policy_factory.h +73 -0
- data/src/core/client_config/lb_policy_registry.c +88 -0
- data/src/core/client_config/lb_policy_registry.h +54 -0
- data/src/core/client_config/resolver.c +82 -0
- data/src/core/client_config/resolver.h +94 -0
- data/src/core/client_config/resolver_factory.c +55 -0
- data/src/core/client_config/resolver_factory.h +82 -0
- data/src/core/client_config/resolver_registry.c +137 -0
- data/src/core/client_config/resolver_registry.h +65 -0
- data/src/core/client_config/resolvers/dns_resolver.c +257 -0
- data/src/core/client_config/resolvers/dns_resolver.h +42 -0
- data/src/core/client_config/resolvers/sockaddr_resolver.c +391 -0
- data/src/core/client_config/resolvers/sockaddr_resolver.h +50 -0
- data/src/core/client_config/subchannel.c +697 -0
- data/src/core/client_config/subchannel.h +165 -0
- data/src/core/client_config/subchannel_factory.c +49 -0
- data/src/core/client_config/subchannel_factory.h +66 -0
- data/src/core/client_config/uri_parser.c +242 -0
- data/src/core/client_config/uri_parser.h +51 -0
- data/src/core/compression/algorithm.c +166 -0
- data/src/core/compression/algorithm_metadata.h +53 -0
- data/src/core/compression/message_compress.c +198 -0
- data/src/core/compression/message_compress.h +52 -0
- data/src/core/debug/trace.c +136 -0
- data/src/core/debug/trace.h +43 -0
- data/src/core/httpcli/format_request.c +120 -0
- data/src/core/httpcli/format_request.h +45 -0
- data/src/core/httpcli/httpcli.c +286 -0
- data/src/core/httpcli/httpcli.h +162 -0
- data/src/core/httpcli/httpcli_security_connector.c +189 -0
- data/src/core/httpcli/parser.c +211 -0
- data/src/core/httpcli/parser.h +64 -0
- data/src/core/iomgr/closure.c +98 -0
- data/src/core/iomgr/closure.h +97 -0
- data/src/core/iomgr/endpoint.c +67 -0
- data/src/core/iomgr/endpoint.h +102 -0
- data/src/core/iomgr/endpoint_pair.h +47 -0
- data/src/core/iomgr/endpoint_pair_posix.c +82 -0
- data/src/core/iomgr/endpoint_pair_windows.c +97 -0
- data/src/core/iomgr/exec_ctx.c +72 -0
- data/src/core/iomgr/exec_ctx.h +78 -0
- data/src/core/iomgr/executor.c +143 -0
- data/src/core/iomgr/executor.h +53 -0
- data/src/core/iomgr/fd_posix.c +438 -0
- data/src/core/iomgr/fd_posix.h +189 -0
- data/src/core/iomgr/iocp_windows.c +206 -0
- data/src/core/iomgr/iocp_windows.h +56 -0
- data/src/core/iomgr/iomgr.c +156 -0
- data/src/core/iomgr/iomgr.h +43 -0
- data/src/core/iomgr/iomgr_internal.h +58 -0
- data/src/core/iomgr/iomgr_posix.c +52 -0
- data/src/core/iomgr/iomgr_posix.h +39 -0
- data/src/core/iomgr/iomgr_windows.c +73 -0
- data/src/core/iomgr/pollset.h +95 -0
- data/src/core/iomgr/pollset_multipoller_with_epoll.c +258 -0
- data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +227 -0
- data/src/core/iomgr/pollset_posix.c +638 -0
- data/src/core/iomgr/pollset_posix.h +147 -0
- data/src/core/iomgr/pollset_set.h +67 -0
- data/src/core/iomgr/pollset_set_posix.c +182 -0
- data/src/core/iomgr/pollset_set_posix.h +61 -0
- data/src/core/iomgr/pollset_set_windows.c +60 -0
- data/src/core/iomgr/pollset_set_windows.h +39 -0
- data/src/core/iomgr/pollset_windows.c +248 -0
- data/src/core/iomgr/pollset_windows.h +79 -0
- data/src/core/iomgr/resolve_address.h +72 -0
- data/src/core/iomgr/resolve_address_posix.c +183 -0
- data/src/core/iomgr/resolve_address_windows.c +166 -0
- data/src/core/iomgr/sockaddr.h +47 -0
- data/src/core/iomgr/sockaddr_posix.h +44 -0
- data/src/core/iomgr/sockaddr_utils.c +234 -0
- data/src/core/iomgr/sockaddr_utils.h +89 -0
- data/src/core/iomgr/sockaddr_win32.h +46 -0
- data/src/core/iomgr/socket_utils_common_posix.c +208 -0
- data/src/core/iomgr/socket_utils_linux.c +51 -0
- data/src/core/iomgr/socket_utils_posix.c +70 -0
- data/src/core/iomgr/socket_utils_posix.h +113 -0
- data/src/core/iomgr/socket_windows.c +98 -0
- data/src/core/iomgr/socket_windows.h +111 -0
- data/src/core/iomgr/tcp_client.h +53 -0
- data/src/core/iomgr/tcp_client_posix.c +304 -0
- data/src/core/iomgr/tcp_client_windows.c +221 -0
- data/src/core/iomgr/tcp_posix.c +485 -0
- data/src/core/iomgr/tcp_posix.h +65 -0
- data/src/core/iomgr/tcp_server.h +83 -0
- data/src/core/iomgr/tcp_server_posix.c +562 -0
- data/src/core/iomgr/tcp_server_windows.c +509 -0
- data/src/core/iomgr/tcp_windows.c +406 -0
- data/src/core/iomgr/tcp_windows.h +57 -0
- data/src/core/iomgr/time_averaged_stats.c +77 -0
- data/src/core/iomgr/time_averaged_stats.h +88 -0
- data/src/core/iomgr/timer.c +345 -0
- data/src/core/iomgr/timer.h +89 -0
- data/src/core/iomgr/timer_heap.c +148 -0
- data/src/core/iomgr/timer_heap.h +57 -0
- data/src/core/iomgr/timer_internal.h +61 -0
- data/src/core/iomgr/udp_server.c +439 -0
- data/src/core/iomgr/udp_server.h +83 -0
- data/src/core/iomgr/wakeup_fd_eventfd.c +85 -0
- data/src/core/iomgr/wakeup_fd_nospecial.c +51 -0
- data/src/core/iomgr/wakeup_fd_pipe.c +97 -0
- data/src/core/iomgr/wakeup_fd_pipe.h +41 -0
- data/src/core/iomgr/wakeup_fd_posix.c +72 -0
- data/src/core/iomgr/wakeup_fd_posix.h +101 -0
- data/src/core/iomgr/workqueue.h +85 -0
- data/src/core/iomgr/workqueue_posix.c +143 -0
- data/src/core/iomgr/workqueue_posix.h +51 -0
- data/src/core/iomgr/workqueue_windows.c +40 -0
- data/src/core/iomgr/workqueue_windows.h +37 -0
- data/src/core/json/json.c +64 -0
- data/src/core/json/json.h +88 -0
- data/src/core/json/json_common.h +49 -0
- data/src/core/json/json_reader.c +660 -0
- data/src/core/json/json_reader.h +160 -0
- data/src/core/json/json_string.c +379 -0
- data/src/core/json/json_writer.c +260 -0
- data/src/core/json/json_writer.h +97 -0
- data/src/core/profiling/basic_timers.c +274 -0
- data/src/core/profiling/stap_timers.c +65 -0
- data/src/core/profiling/timers.h +119 -0
- data/src/core/security/auth_filters.h +42 -0
- data/src/core/security/base64.c +233 -0
- data/src/core/security/base64.h +52 -0
- data/src/core/security/client_auth_filter.c +337 -0
- data/src/core/security/credentials.c +1273 -0
- data/src/core/security/credentials.h +376 -0
- data/src/core/security/credentials_metadata.c +101 -0
- data/src/core/security/credentials_posix.c +61 -0
- data/src/core/security/credentials_win32.c +61 -0
- data/src/core/security/google_default_credentials.c +260 -0
- data/src/core/security/handshake.c +327 -0
- data/src/core/security/handshake.h +50 -0
- data/src/core/security/json_token.c +405 -0
- data/src/core/security/json_token.h +118 -0
- data/src/core/security/jwt_verifier.c +842 -0
- data/src/core/security/jwt_verifier.h +136 -0
- data/src/core/security/secure_endpoint.c +383 -0
- data/src/core/security/secure_endpoint.h +49 -0
- data/src/core/security/security_connector.c +756 -0
- data/src/core/security/security_connector.h +246 -0
- data/src/core/security/security_context.c +342 -0
- data/src/core/security/security_context.h +114 -0
- data/src/core/security/server_auth_filter.c +264 -0
- data/src/core/security/server_secure_chttp2.c +268 -0
- data/src/core/statistics/census_interface.h +76 -0
- data/src/core/statistics/census_rpc_stats.h +101 -0
- data/src/core/support/alloc.c +90 -0
- data/src/core/support/avl.c +288 -0
- data/src/core/support/block_annotate.h +48 -0
- data/src/core/support/cmdline.c +347 -0
- data/src/core/support/cpu_iphone.c +49 -0
- data/src/core/support/cpu_linux.c +78 -0
- data/src/core/support/cpu_posix.c +77 -0
- data/src/core/support/cpu_windows.c +47 -0
- data/src/core/support/env.h +60 -0
- data/src/core/support/env_linux.c +62 -0
- data/src/core/support/env_posix.c +57 -0
- data/src/core/support/env_win32.c +65 -0
- data/src/core/support/file.c +91 -0
- data/src/core/support/file.h +63 -0
- data/src/core/support/file_posix.c +85 -0
- data/src/core/support/file_win32.c +84 -0
- data/src/core/support/histogram.c +244 -0
- data/src/core/support/host_port.c +110 -0
- data/src/core/support/log.c +66 -0
- data/src/core/support/log_android.c +87 -0
- data/src/core/support/log_linux.c +105 -0
- data/src/core/support/log_posix.c +102 -0
- data/src/core/support/log_win32.c +125 -0
- data/src/core/support/murmur_hash.c +96 -0
- data/src/core/support/murmur_hash.h +44 -0
- data/src/core/support/slice.c +343 -0
- data/src/core/support/slice_buffer.c +282 -0
- data/src/core/support/stack_lockfree.c +175 -0
- data/src/core/support/stack_lockfree.h +53 -0
- data/src/core/support/string.c +296 -0
- data/src/core/support/string.h +121 -0
- data/src/core/support/string_posix.c +86 -0
- data/src/core/support/string_win32.c +109 -0
- data/src/core/support/string_win32.h +47 -0
- data/src/core/support/subprocess_posix.c +112 -0
- data/src/core/support/sync.c +122 -0
- data/src/core/support/sync_posix.c +104 -0
- data/src/core/support/sync_win32.c +128 -0
- data/src/core/support/thd.c +64 -0
- data/src/core/support/thd_internal.h +39 -0
- data/src/core/support/thd_posix.c +94 -0
- data/src/core/support/thd_win32.c +117 -0
- data/src/core/support/time.c +304 -0
- data/src/core/support/time_posix.c +161 -0
- data/src/core/support/time_precise.c +89 -0
- data/src/core/support/time_precise.h +42 -0
- data/src/core/support/time_win32.c +101 -0
- data/src/core/support/tls_pthread.c +45 -0
- data/src/core/surface/api_trace.c +36 -0
- data/src/core/surface/api_trace.h +65 -0
- data/src/core/surface/byte_buffer.c +97 -0
- data/src/core/surface/byte_buffer_reader.c +123 -0
- data/src/core/surface/call.c +1424 -0
- data/src/core/surface/call.h +109 -0
- data/src/core/surface/call_details.c +50 -0
- data/src/core/surface/call_log_batch.c +118 -0
- data/src/core/surface/call_test_only.h +64 -0
- data/src/core/surface/channel.c +327 -0
- data/src/core/surface/channel.h +74 -0
- data/src/core/surface/channel_connectivity.c +220 -0
- data/src/core/surface/channel_create.c +235 -0
- data/src/core/surface/channel_ping.c +79 -0
- data/src/core/surface/completion_queue.c +481 -0
- data/src/core/surface/completion_queue.h +91 -0
- data/src/core/surface/event_string.c +81 -0
- data/src/core/surface/event_string.h +42 -0
- data/src/core/surface/init.c +168 -0
- data/src/core/surface/init.h +40 -0
- data/src/core/surface/init_secure.c +42 -0
- data/src/core/surface/lame_client.c +149 -0
- data/src/core/surface/metadata_array.c +49 -0
- data/src/core/surface/secure_channel_create.c +336 -0
- data/src/core/surface/server.c +1343 -0
- data/src/core/surface/server.h +67 -0
- data/src/core/surface/server_chttp2.c +149 -0
- data/src/core/surface/server_create.c +51 -0
- data/src/core/surface/surface_trace.h +48 -0
- data/src/core/surface/validate_metadata.c +73 -0
- data/src/core/surface/version.c +39 -0
- data/src/core/transport/byte_stream.c +76 -0
- data/src/core/transport/byte_stream.h +88 -0
- data/src/core/transport/chttp2/alpn.c +56 -0
- data/src/core/transport/chttp2/alpn.h +49 -0
- data/src/core/transport/chttp2/bin_encoder.c +285 -0
- data/src/core/transport/chttp2/bin_encoder.h +54 -0
- data/src/core/transport/chttp2/frame.h +69 -0
- data/src/core/transport/chttp2/frame_data.c +245 -0
- data/src/core/transport/chttp2/frame_data.h +101 -0
- data/src/core/transport/chttp2/frame_goaway.c +193 -0
- data/src/core/transport/chttp2/frame_goaway.h +77 -0
- data/src/core/transport/chttp2/frame_ping.c +97 -0
- data/src/core/transport/chttp2/frame_ping.h +56 -0
- data/src/core/transport/chttp2/frame_rst_stream.c +100 -0
- data/src/core/transport/chttp2/frame_rst_stream.h +55 -0
- data/src/core/transport/chttp2/frame_settings.c +259 -0
- data/src/core/transport/chttp2/frame_settings.h +103 -0
- data/src/core/transport/chttp2/frame_window_update.c +114 -0
- data/src/core/transport/chttp2/frame_window_update.h +58 -0
- data/src/core/transport/chttp2/hpack_encoder.c +572 -0
- data/src/core/transport/chttp2/hpack_encoder.h +95 -0
- data/src/core/transport/chttp2/hpack_parser.c +1449 -0
- data/src/core/transport/chttp2/hpack_parser.h +116 -0
- data/src/core/transport/chttp2/hpack_table.c +361 -0
- data/src/core/transport/chttp2/hpack_table.h +108 -0
- data/src/core/transport/chttp2/http2_errors.h +56 -0
- data/src/core/transport/chttp2/huffsyms.c +297 -0
- data/src/core/transport/chttp2/huffsyms.h +48 -0
- data/src/core/transport/chttp2/incoming_metadata.c +96 -0
- data/src/core/transport/chttp2/incoming_metadata.h +60 -0
- data/src/core/transport/chttp2/internal.h +757 -0
- data/src/core/transport/chttp2/parsing.c +866 -0
- data/src/core/transport/chttp2/status_conversion.c +109 -0
- data/src/core/transport/chttp2/status_conversion.h +50 -0
- data/src/core/transport/chttp2/stream_lists.c +401 -0
- data/src/core/transport/chttp2/stream_map.c +198 -0
- data/src/core/transport/chttp2/stream_map.h +85 -0
- data/src/core/transport/chttp2/timeout_encoding.c +185 -0
- data/src/core/transport/chttp2/timeout_encoding.h +47 -0
- data/src/core/transport/chttp2/varint.c +66 -0
- data/src/core/transport/chttp2/varint.h +76 -0
- data/src/core/transport/chttp2/writing.c +356 -0
- data/src/core/transport/chttp2_transport.c +1692 -0
- data/src/core/transport/chttp2_transport.h +51 -0
- data/src/core/transport/connectivity_state.c +164 -0
- data/src/core/transport/connectivity_state.h +85 -0
- data/src/core/transport/metadata.c +690 -0
- data/src/core/transport/metadata.h +156 -0
- data/src/core/transport/metadata_batch.c +194 -0
- data/src/core/transport/metadata_batch.h +125 -0
- data/src/core/transport/static_metadata.c +90 -0
- data/src/core/transport/static_metadata.h +408 -0
- data/src/core/transport/transport.c +183 -0
- data/src/core/transport/transport.h +222 -0
- data/src/core/transport/transport_impl.h +78 -0
- data/src/core/transport/transport_op_string.c +140 -0
- data/src/core/tsi/fake_transport_security.c +525 -0
- data/src/core/tsi/fake_transport_security.h +61 -0
- data/src/core/tsi/ssl_transport_security.c +1467 -0
- data/src/core/tsi/ssl_transport_security.h +173 -0
- data/src/core/tsi/transport_security.c +284 -0
- data/src/core/tsi/transport_security.h +111 -0
- data/src/core/tsi/transport_security_interface.h +344 -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/grpc_ruby_interop_client +33 -0
- data/src/ruby/bin/grpc_ruby_interop_server +33 -0
- data/src/ruby/bin/interop/interop_client.rb +51 -0
- data/src/ruby/bin/interop/interop_server.rb +50 -0
- data/src/ruby/bin/math.rb +32 -0
- data/src/ruby/bin/math_client.rb +147 -0
- data/src/ruby/bin/math_server.rb +206 -0
- data/src/ruby/bin/math_services.rb +27 -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 +92 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +75 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +47 -0
- data/src/ruby/ext/grpc/rb_call.c +915 -0
- data/src/ruby/ext/grpc/rb_call.h +66 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +315 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
- data/src/ruby/ext/grpc/rb_channel.c +430 -0
- data/src/ruby/ext/grpc/rb_channel.h +47 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +167 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +266 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +181 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +55 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +153 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
- data/src/ruby/ext/grpc/rb_grpc.c +328 -0
- data/src/ruby/ext/grpc/rb_grpc.h +85 -0
- data/src/ruby/ext/grpc/rb_server.c +398 -0
- data/src/ruby/ext/grpc/rb_server.h +47 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +282 -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 +62 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +488 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +218 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +471 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +147 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +504 -0
- data/src/ruby/lib/grpc/generic/service.rb +234 -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 +44 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1alpha/health.rb +29 -0
- data/src/ruby/pb/grpc/health/v1alpha/health_services.rb +28 -0
- data/src/ruby/pb/test/client.rb +469 -0
- data/src/ruby/pb/test/proto/empty.rb +15 -0
- data/src/ruby/pb/test/proto/messages.rb +80 -0
- data/src/ruby/pb/test/proto/test.rb +14 -0
- data/src/ruby/pb/test/proto/test_services.rb +64 -0
- data/src/ruby/pb/test/server.rb +253 -0
- data/src/ruby/spec/call_credentials_spec.rb +57 -0
- data/src/ruby/spec/call_spec.rb +163 -0
- data/src/ruby/spec/channel_credentials_spec.rb +97 -0
- data/src/ruby/spec/channel_spec.rb +177 -0
- data/src/ruby/spec/client_server_spec.rb +475 -0
- data/src/ruby/spec/completion_queue_spec.rb +42 -0
- data/src/ruby/spec/generic/active_call_spec.rb +373 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +476 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +331 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +138 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +576 -0
- data/src/ruby/spec/generic/service_spec.rb +345 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +232 -0
- data/src/ruby/spec/server_credentials_spec.rb +94 -0
- data/src/ruby/spec/server_spec.rb +209 -0
- data/src/ruby/spec/spec_helper.rb +69 -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
- metadata +665 -0
@@ -0,0 +1,638 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, 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 <grpc/support/port_platform.h>
|
35
|
+
|
36
|
+
#ifdef GPR_POSIX_SOCKET
|
37
|
+
|
38
|
+
#include "src/core/iomgr/pollset_posix.h"
|
39
|
+
|
40
|
+
#include <errno.h>
|
41
|
+
#include <stdlib.h>
|
42
|
+
#include <string.h>
|
43
|
+
#include <unistd.h>
|
44
|
+
|
45
|
+
#include "src/core/iomgr/timer_internal.h"
|
46
|
+
#include "src/core/iomgr/fd_posix.h"
|
47
|
+
#include "src/core/iomgr/iomgr_internal.h"
|
48
|
+
#include "src/core/iomgr/socket_utils_posix.h"
|
49
|
+
#include "src/core/profiling/timers.h"
|
50
|
+
#include "src/core/support/block_annotate.h"
|
51
|
+
#include <grpc/support/alloc.h>
|
52
|
+
#include <grpc/support/log.h>
|
53
|
+
#include <grpc/support/thd.h>
|
54
|
+
#include <grpc/support/tls.h>
|
55
|
+
#include <grpc/support/useful.h>
|
56
|
+
|
57
|
+
GPR_TLS_DECL(g_current_thread_poller);
|
58
|
+
GPR_TLS_DECL(g_current_thread_worker);
|
59
|
+
|
60
|
+
/** Default poll() function - a pointer so that it can be overridden by some
|
61
|
+
* tests */
|
62
|
+
grpc_poll_function_type grpc_poll_function = poll;
|
63
|
+
|
64
|
+
/** The alarm system needs to be able to wakeup 'some poller' sometimes
|
65
|
+
* (specifically when a new alarm needs to be triggered earlier than the next
|
66
|
+
* alarm 'epoch').
|
67
|
+
* This wakeup_fd gives us something to alert on when such a case occurs. */
|
68
|
+
grpc_wakeup_fd grpc_global_wakeup_fd;
|
69
|
+
|
70
|
+
static void remove_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
71
|
+
worker->prev->next = worker->next;
|
72
|
+
worker->next->prev = worker->prev;
|
73
|
+
}
|
74
|
+
|
75
|
+
int grpc_pollset_has_workers(grpc_pollset *p) {
|
76
|
+
return p->root_worker.next != &p->root_worker;
|
77
|
+
}
|
78
|
+
|
79
|
+
static grpc_pollset_worker *pop_front_worker(grpc_pollset *p) {
|
80
|
+
if (grpc_pollset_has_workers(p)) {
|
81
|
+
grpc_pollset_worker *w = p->root_worker.next;
|
82
|
+
remove_worker(p, w);
|
83
|
+
return w;
|
84
|
+
} else {
|
85
|
+
return NULL;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
static void push_back_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
90
|
+
worker->next = &p->root_worker;
|
91
|
+
worker->prev = worker->next->prev;
|
92
|
+
worker->prev->next = worker->next->prev = worker;
|
93
|
+
}
|
94
|
+
|
95
|
+
static void push_front_worker(grpc_pollset *p, grpc_pollset_worker *worker) {
|
96
|
+
worker->prev = &p->root_worker;
|
97
|
+
worker->next = worker->prev->next;
|
98
|
+
worker->prev->next = worker->next->prev = worker;
|
99
|
+
}
|
100
|
+
|
101
|
+
void grpc_pollset_kick_ext(grpc_pollset *p,
|
102
|
+
grpc_pollset_worker *specific_worker,
|
103
|
+
gpr_uint32 flags) {
|
104
|
+
GPR_TIMER_BEGIN("grpc_pollset_kick_ext", 0);
|
105
|
+
|
106
|
+
/* pollset->mu already held */
|
107
|
+
if (specific_worker != NULL) {
|
108
|
+
if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) {
|
109
|
+
GPR_TIMER_BEGIN("grpc_pollset_kick_ext.broadcast", 0);
|
110
|
+
GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0);
|
111
|
+
for (specific_worker = p->root_worker.next;
|
112
|
+
specific_worker != &p->root_worker;
|
113
|
+
specific_worker = specific_worker->next) {
|
114
|
+
grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd);
|
115
|
+
}
|
116
|
+
p->kicked_without_pollers = 1;
|
117
|
+
GPR_TIMER_END("grpc_pollset_kick_ext.broadcast", 0);
|
118
|
+
} else if (gpr_tls_get(&g_current_thread_worker) !=
|
119
|
+
(gpr_intptr)specific_worker) {
|
120
|
+
GPR_TIMER_MARK("different_thread_worker", 0);
|
121
|
+
if ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) != 0) {
|
122
|
+
specific_worker->reevaluate_polling_on_wakeup = 1;
|
123
|
+
}
|
124
|
+
specific_worker->kicked_specifically = 1;
|
125
|
+
grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd);
|
126
|
+
} else if ((flags & GRPC_POLLSET_CAN_KICK_SELF) != 0) {
|
127
|
+
GPR_TIMER_MARK("kick_yoself", 0);
|
128
|
+
if ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) != 0) {
|
129
|
+
specific_worker->reevaluate_polling_on_wakeup = 1;
|
130
|
+
}
|
131
|
+
specific_worker->kicked_specifically = 1;
|
132
|
+
grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd);
|
133
|
+
}
|
134
|
+
} else if (gpr_tls_get(&g_current_thread_poller) != (gpr_intptr)p) {
|
135
|
+
GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0);
|
136
|
+
GPR_TIMER_MARK("kick_anonymous", 0);
|
137
|
+
specific_worker = pop_front_worker(p);
|
138
|
+
if (specific_worker != NULL) {
|
139
|
+
if (gpr_tls_get(&g_current_thread_worker) ==
|
140
|
+
(gpr_intptr)specific_worker) {
|
141
|
+
GPR_TIMER_MARK("kick_anonymous_not_self", 0);
|
142
|
+
push_back_worker(p, specific_worker);
|
143
|
+
specific_worker = pop_front_worker(p);
|
144
|
+
if ((flags & GRPC_POLLSET_CAN_KICK_SELF) == 0 &&
|
145
|
+
gpr_tls_get(&g_current_thread_worker) ==
|
146
|
+
(gpr_intptr)specific_worker) {
|
147
|
+
push_back_worker(p, specific_worker);
|
148
|
+
specific_worker = NULL;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
if (specific_worker != NULL) {
|
152
|
+
GPR_TIMER_MARK("finally_kick", 0);
|
153
|
+
push_back_worker(p, specific_worker);
|
154
|
+
grpc_wakeup_fd_wakeup(&specific_worker->wakeup_fd->fd);
|
155
|
+
}
|
156
|
+
} else {
|
157
|
+
GPR_TIMER_MARK("kicked_no_pollers", 0);
|
158
|
+
p->kicked_without_pollers = 1;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
GPR_TIMER_END("grpc_pollset_kick_ext", 0);
|
163
|
+
}
|
164
|
+
|
165
|
+
void grpc_pollset_kick(grpc_pollset *p, grpc_pollset_worker *specific_worker) {
|
166
|
+
grpc_pollset_kick_ext(p, specific_worker, 0);
|
167
|
+
}
|
168
|
+
|
169
|
+
/* global state management */
|
170
|
+
|
171
|
+
void grpc_pollset_global_init(void) {
|
172
|
+
gpr_tls_init(&g_current_thread_poller);
|
173
|
+
gpr_tls_init(&g_current_thread_worker);
|
174
|
+
grpc_wakeup_fd_global_init();
|
175
|
+
grpc_wakeup_fd_init(&grpc_global_wakeup_fd);
|
176
|
+
}
|
177
|
+
|
178
|
+
void grpc_pollset_global_shutdown(void) {
|
179
|
+
grpc_wakeup_fd_destroy(&grpc_global_wakeup_fd);
|
180
|
+
gpr_tls_destroy(&g_current_thread_poller);
|
181
|
+
gpr_tls_destroy(&g_current_thread_worker);
|
182
|
+
grpc_wakeup_fd_global_destroy();
|
183
|
+
}
|
184
|
+
|
185
|
+
void grpc_kick_poller(void) { grpc_wakeup_fd_wakeup(&grpc_global_wakeup_fd); }
|
186
|
+
|
187
|
+
/* main interface */
|
188
|
+
|
189
|
+
static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null);
|
190
|
+
|
191
|
+
void grpc_pollset_init(grpc_pollset *pollset) {
|
192
|
+
gpr_mu_init(&pollset->mu);
|
193
|
+
pollset->root_worker.next = pollset->root_worker.prev = &pollset->root_worker;
|
194
|
+
pollset->in_flight_cbs = 0;
|
195
|
+
pollset->shutting_down = 0;
|
196
|
+
pollset->called_shutdown = 0;
|
197
|
+
pollset->kicked_without_pollers = 0;
|
198
|
+
pollset->idle_jobs.head = pollset->idle_jobs.tail = NULL;
|
199
|
+
pollset->local_wakeup_cache = NULL;
|
200
|
+
pollset->kicked_without_pollers = 0;
|
201
|
+
become_basic_pollset(pollset, NULL);
|
202
|
+
}
|
203
|
+
|
204
|
+
void grpc_pollset_destroy(grpc_pollset *pollset) {
|
205
|
+
GPR_ASSERT(pollset->in_flight_cbs == 0);
|
206
|
+
GPR_ASSERT(!grpc_pollset_has_workers(pollset));
|
207
|
+
GPR_ASSERT(pollset->idle_jobs.head == pollset->idle_jobs.tail);
|
208
|
+
pollset->vtable->destroy(pollset);
|
209
|
+
gpr_mu_destroy(&pollset->mu);
|
210
|
+
while (pollset->local_wakeup_cache) {
|
211
|
+
grpc_cached_wakeup_fd *next = pollset->local_wakeup_cache->next;
|
212
|
+
grpc_wakeup_fd_destroy(&pollset->local_wakeup_cache->fd);
|
213
|
+
gpr_free(pollset->local_wakeup_cache);
|
214
|
+
pollset->local_wakeup_cache = next;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
void grpc_pollset_reset(grpc_pollset *pollset) {
|
219
|
+
GPR_ASSERT(pollset->shutting_down);
|
220
|
+
GPR_ASSERT(pollset->in_flight_cbs == 0);
|
221
|
+
GPR_ASSERT(!grpc_pollset_has_workers(pollset));
|
222
|
+
GPR_ASSERT(pollset->idle_jobs.head == pollset->idle_jobs.tail);
|
223
|
+
pollset->vtable->destroy(pollset);
|
224
|
+
pollset->shutting_down = 0;
|
225
|
+
pollset->called_shutdown = 0;
|
226
|
+
pollset->kicked_without_pollers = 0;
|
227
|
+
become_basic_pollset(pollset, NULL);
|
228
|
+
}
|
229
|
+
|
230
|
+
void grpc_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
231
|
+
grpc_fd *fd) {
|
232
|
+
gpr_mu_lock(&pollset->mu);
|
233
|
+
pollset->vtable->add_fd(exec_ctx, pollset, fd, 1);
|
234
|
+
/* the following (enabled only in debug) will reacquire and then release
|
235
|
+
our lock - meaning that if the unlocking flag passed to add_fd above is
|
236
|
+
not respected, the code will deadlock (in a way that we have a chance of
|
237
|
+
debugging) */
|
238
|
+
#ifndef NDEBUG
|
239
|
+
gpr_mu_lock(&pollset->mu);
|
240
|
+
gpr_mu_unlock(&pollset->mu);
|
241
|
+
#endif
|
242
|
+
}
|
243
|
+
|
244
|
+
static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset) {
|
245
|
+
GPR_ASSERT(grpc_closure_list_empty(pollset->idle_jobs));
|
246
|
+
pollset->vtable->finish_shutdown(pollset);
|
247
|
+
grpc_exec_ctx_enqueue(exec_ctx, pollset->shutdown_done, 1);
|
248
|
+
}
|
249
|
+
|
250
|
+
void grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
251
|
+
grpc_pollset_worker *worker, gpr_timespec now,
|
252
|
+
gpr_timespec deadline) {
|
253
|
+
/* pollset->mu already held */
|
254
|
+
int added_worker = 0;
|
255
|
+
int locked = 1;
|
256
|
+
int queued_work = 0;
|
257
|
+
int keep_polling = 0;
|
258
|
+
GPR_TIMER_BEGIN("grpc_pollset_work", 0);
|
259
|
+
/* this must happen before we (potentially) drop pollset->mu */
|
260
|
+
worker->next = worker->prev = NULL;
|
261
|
+
worker->reevaluate_polling_on_wakeup = 0;
|
262
|
+
if (pollset->local_wakeup_cache != NULL) {
|
263
|
+
worker->wakeup_fd = pollset->local_wakeup_cache;
|
264
|
+
pollset->local_wakeup_cache = worker->wakeup_fd->next;
|
265
|
+
} else {
|
266
|
+
worker->wakeup_fd = gpr_malloc(sizeof(*worker->wakeup_fd));
|
267
|
+
grpc_wakeup_fd_init(&worker->wakeup_fd->fd);
|
268
|
+
}
|
269
|
+
worker->kicked_specifically = 0;
|
270
|
+
/* If there's work waiting for the pollset to be idle, and the
|
271
|
+
pollset is idle, then do that work */
|
272
|
+
if (!grpc_pollset_has_workers(pollset) &&
|
273
|
+
!grpc_closure_list_empty(pollset->idle_jobs)) {
|
274
|
+
GPR_TIMER_MARK("grpc_pollset_work.idle_jobs", 0);
|
275
|
+
grpc_exec_ctx_enqueue_list(exec_ctx, &pollset->idle_jobs);
|
276
|
+
goto done;
|
277
|
+
}
|
278
|
+
/* Check alarms - these are a global resource so we just ping
|
279
|
+
each time through on every pollset.
|
280
|
+
May update deadline to ensure timely wakeups.
|
281
|
+
TODO(ctiller): can this work be localized? */
|
282
|
+
if (grpc_timer_check(exec_ctx, now, &deadline)) {
|
283
|
+
GPR_TIMER_MARK("grpc_pollset_work.alarm_triggered", 0);
|
284
|
+
gpr_mu_unlock(&pollset->mu);
|
285
|
+
locked = 0;
|
286
|
+
goto done;
|
287
|
+
}
|
288
|
+
/* If we're shutting down then we don't execute any extended work */
|
289
|
+
if (pollset->shutting_down) {
|
290
|
+
GPR_TIMER_MARK("grpc_pollset_work.shutting_down", 0);
|
291
|
+
goto done;
|
292
|
+
}
|
293
|
+
/* Give do_promote priority so we don't starve it out */
|
294
|
+
if (pollset->in_flight_cbs) {
|
295
|
+
GPR_TIMER_MARK("grpc_pollset_work.in_flight_cbs", 0);
|
296
|
+
gpr_mu_unlock(&pollset->mu);
|
297
|
+
locked = 0;
|
298
|
+
goto done;
|
299
|
+
}
|
300
|
+
/* Start polling, and keep doing so while we're being asked to
|
301
|
+
re-evaluate our pollers (this allows poll() based pollers to
|
302
|
+
ensure they don't miss wakeups) */
|
303
|
+
keep_polling = 1;
|
304
|
+
while (keep_polling) {
|
305
|
+
keep_polling = 0;
|
306
|
+
if (!pollset->kicked_without_pollers) {
|
307
|
+
if (!added_worker) {
|
308
|
+
push_front_worker(pollset, worker);
|
309
|
+
added_worker = 1;
|
310
|
+
gpr_tls_set(&g_current_thread_worker, (gpr_intptr)worker);
|
311
|
+
}
|
312
|
+
gpr_tls_set(&g_current_thread_poller, (gpr_intptr)pollset);
|
313
|
+
GPR_TIMER_BEGIN("maybe_work_and_unlock", 0);
|
314
|
+
pollset->vtable->maybe_work_and_unlock(exec_ctx, pollset, worker,
|
315
|
+
deadline, now);
|
316
|
+
GPR_TIMER_END("maybe_work_and_unlock", 0);
|
317
|
+
locked = 0;
|
318
|
+
gpr_tls_set(&g_current_thread_poller, 0);
|
319
|
+
} else {
|
320
|
+
GPR_TIMER_MARK("grpc_pollset_work.kicked_without_pollers", 0);
|
321
|
+
pollset->kicked_without_pollers = 0;
|
322
|
+
}
|
323
|
+
/* Finished execution - start cleaning up.
|
324
|
+
Note that we may arrive here from outside the enclosing while() loop.
|
325
|
+
In that case we won't loop though as we haven't added worker to the
|
326
|
+
worker list, which means nobody could ask us to re-evaluate polling). */
|
327
|
+
done:
|
328
|
+
if (!locked) {
|
329
|
+
queued_work |= grpc_exec_ctx_flush(exec_ctx);
|
330
|
+
gpr_mu_lock(&pollset->mu);
|
331
|
+
locked = 1;
|
332
|
+
}
|
333
|
+
/* If we're forced to re-evaluate polling (via grpc_pollset_kick with
|
334
|
+
GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) then we land here and force
|
335
|
+
a loop */
|
336
|
+
if (worker->reevaluate_polling_on_wakeup) {
|
337
|
+
worker->reevaluate_polling_on_wakeup = 0;
|
338
|
+
pollset->kicked_without_pollers = 0;
|
339
|
+
if (queued_work || worker->kicked_specifically) {
|
340
|
+
/* If there's queued work on the list, then set the deadline to be
|
341
|
+
immediate so we get back out of the polling loop quickly */
|
342
|
+
deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC);
|
343
|
+
}
|
344
|
+
keep_polling = 1;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
if (added_worker) {
|
348
|
+
remove_worker(pollset, worker);
|
349
|
+
gpr_tls_set(&g_current_thread_worker, 0);
|
350
|
+
}
|
351
|
+
/* release wakeup fd to the local pool */
|
352
|
+
worker->wakeup_fd->next = pollset->local_wakeup_cache;
|
353
|
+
pollset->local_wakeup_cache = worker->wakeup_fd;
|
354
|
+
/* check shutdown conditions */
|
355
|
+
if (pollset->shutting_down) {
|
356
|
+
if (grpc_pollset_has_workers(pollset)) {
|
357
|
+
grpc_pollset_kick(pollset, NULL);
|
358
|
+
} else if (!pollset->called_shutdown && pollset->in_flight_cbs == 0) {
|
359
|
+
pollset->called_shutdown = 1;
|
360
|
+
gpr_mu_unlock(&pollset->mu);
|
361
|
+
finish_shutdown(exec_ctx, pollset);
|
362
|
+
grpc_exec_ctx_flush(exec_ctx);
|
363
|
+
/* Continuing to access pollset here is safe -- it is the caller's
|
364
|
+
* responsibility to not destroy when it has outstanding calls to
|
365
|
+
* grpc_pollset_work.
|
366
|
+
* TODO(dklempner): Can we refactor the shutdown logic to avoid this? */
|
367
|
+
gpr_mu_lock(&pollset->mu);
|
368
|
+
} else if (!grpc_closure_list_empty(pollset->idle_jobs)) {
|
369
|
+
grpc_exec_ctx_enqueue_list(exec_ctx, &pollset->idle_jobs);
|
370
|
+
gpr_mu_unlock(&pollset->mu);
|
371
|
+
grpc_exec_ctx_flush(exec_ctx);
|
372
|
+
gpr_mu_lock(&pollset->mu);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
GPR_TIMER_END("grpc_pollset_work", 0);
|
376
|
+
}
|
377
|
+
|
378
|
+
void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
379
|
+
grpc_closure *closure) {
|
380
|
+
GPR_ASSERT(!pollset->shutting_down);
|
381
|
+
pollset->shutting_down = 1;
|
382
|
+
pollset->shutdown_done = closure;
|
383
|
+
grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST);
|
384
|
+
if (!grpc_pollset_has_workers(pollset)) {
|
385
|
+
grpc_exec_ctx_enqueue_list(exec_ctx, &pollset->idle_jobs);
|
386
|
+
}
|
387
|
+
if (!pollset->called_shutdown && pollset->in_flight_cbs == 0 &&
|
388
|
+
!grpc_pollset_has_workers(pollset)) {
|
389
|
+
pollset->called_shutdown = 1;
|
390
|
+
finish_shutdown(exec_ctx, pollset);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
|
394
|
+
int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline,
|
395
|
+
gpr_timespec now) {
|
396
|
+
gpr_timespec timeout;
|
397
|
+
static const int max_spin_polling_us = 10;
|
398
|
+
if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) {
|
399
|
+
return -1;
|
400
|
+
}
|
401
|
+
if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros(
|
402
|
+
max_spin_polling_us,
|
403
|
+
GPR_TIMESPAN))) <= 0) {
|
404
|
+
return 0;
|
405
|
+
}
|
406
|
+
timeout = gpr_time_sub(deadline, now);
|
407
|
+
return gpr_time_to_millis(gpr_time_add(
|
408
|
+
timeout, gpr_time_from_nanos(GPR_NS_PER_MS - 1, GPR_TIMESPAN)));
|
409
|
+
}
|
410
|
+
|
411
|
+
/*
|
412
|
+
* basic_pollset - a vtable that provides polling for zero or one file
|
413
|
+
* descriptor via poll()
|
414
|
+
*/
|
415
|
+
|
416
|
+
typedef struct grpc_unary_promote_args {
|
417
|
+
const grpc_pollset_vtable *original_vtable;
|
418
|
+
grpc_pollset *pollset;
|
419
|
+
grpc_fd *fd;
|
420
|
+
grpc_closure promotion_closure;
|
421
|
+
} grpc_unary_promote_args;
|
422
|
+
|
423
|
+
static void basic_do_promote(grpc_exec_ctx *exec_ctx, void *args, int success) {
|
424
|
+
grpc_unary_promote_args *up_args = args;
|
425
|
+
const grpc_pollset_vtable *original_vtable = up_args->original_vtable;
|
426
|
+
grpc_pollset *pollset = up_args->pollset;
|
427
|
+
grpc_fd *fd = up_args->fd;
|
428
|
+
|
429
|
+
/*
|
430
|
+
* This is quite tricky. There are a number of cases to keep in mind here:
|
431
|
+
* 1. fd may have been orphaned
|
432
|
+
* 2. The pollset may no longer be a unary poller (and we can't let case #1
|
433
|
+
* leak to other pollset types!)
|
434
|
+
* 3. pollset's fd (which may have changed) may have been orphaned
|
435
|
+
* 4. The pollset may be shutting down.
|
436
|
+
*/
|
437
|
+
|
438
|
+
gpr_mu_lock(&pollset->mu);
|
439
|
+
/* First we need to ensure that nobody is polling concurrently */
|
440
|
+
GPR_ASSERT(!grpc_pollset_has_workers(pollset));
|
441
|
+
|
442
|
+
gpr_free(up_args);
|
443
|
+
/* At this point the pollset may no longer be a unary poller. In that case
|
444
|
+
* we should just call the right add function and be done. */
|
445
|
+
/* TODO(klempner): If we're not careful this could cause infinite recursion.
|
446
|
+
* That's not a problem for now because empty_pollset has a trivial poller
|
447
|
+
* and we don't have any mechanism to unbecome multipoller. */
|
448
|
+
pollset->in_flight_cbs--;
|
449
|
+
if (pollset->shutting_down) {
|
450
|
+
/* We don't care about this pollset anymore. */
|
451
|
+
if (pollset->in_flight_cbs == 0 && !pollset->called_shutdown) {
|
452
|
+
pollset->called_shutdown = 1;
|
453
|
+
finish_shutdown(exec_ctx, pollset);
|
454
|
+
}
|
455
|
+
} else if (grpc_fd_is_orphaned(fd)) {
|
456
|
+
/* Don't try to add it to anything, we'll drop our ref on it below */
|
457
|
+
} else if (pollset->vtable != original_vtable) {
|
458
|
+
pollset->vtable->add_fd(exec_ctx, pollset, fd, 0);
|
459
|
+
} else if (fd != pollset->data.ptr) {
|
460
|
+
grpc_fd *fds[2];
|
461
|
+
fds[0] = pollset->data.ptr;
|
462
|
+
fds[1] = fd;
|
463
|
+
|
464
|
+
if (fds[0] && !grpc_fd_is_orphaned(fds[0])) {
|
465
|
+
grpc_platform_become_multipoller(exec_ctx, pollset, fds,
|
466
|
+
GPR_ARRAY_SIZE(fds));
|
467
|
+
GRPC_FD_UNREF(fds[0], "basicpoll");
|
468
|
+
} else {
|
469
|
+
/* old fd is orphaned and we haven't cleaned it up until now, so remain a
|
470
|
+
* unary poller */
|
471
|
+
/* Note that it is possible that fds[1] is also orphaned at this point.
|
472
|
+
* That's okay, we'll correct it at the next add or poll. */
|
473
|
+
if (fds[0]) GRPC_FD_UNREF(fds[0], "basicpoll");
|
474
|
+
pollset->data.ptr = fd;
|
475
|
+
GRPC_FD_REF(fd, "basicpoll");
|
476
|
+
}
|
477
|
+
}
|
478
|
+
|
479
|
+
gpr_mu_unlock(&pollset->mu);
|
480
|
+
|
481
|
+
/* Matching ref in basic_pollset_add_fd */
|
482
|
+
GRPC_FD_UNREF(fd, "basicpoll_add");
|
483
|
+
}
|
484
|
+
|
485
|
+
static void basic_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
|
486
|
+
grpc_fd *fd, int and_unlock_pollset) {
|
487
|
+
grpc_unary_promote_args *up_args;
|
488
|
+
GPR_ASSERT(fd);
|
489
|
+
if (fd == pollset->data.ptr) goto exit;
|
490
|
+
|
491
|
+
if (!grpc_pollset_has_workers(pollset)) {
|
492
|
+
/* Fast path -- no in flight cbs */
|
493
|
+
/* TODO(klempner): Comment this out and fix any test failures or establish
|
494
|
+
* they are due to timing issues */
|
495
|
+
grpc_fd *fds[2];
|
496
|
+
fds[0] = pollset->data.ptr;
|
497
|
+
fds[1] = fd;
|
498
|
+
|
499
|
+
if (fds[0] == NULL) {
|
500
|
+
pollset->data.ptr = fd;
|
501
|
+
GRPC_FD_REF(fd, "basicpoll");
|
502
|
+
} else if (!grpc_fd_is_orphaned(fds[0])) {
|
503
|
+
grpc_platform_become_multipoller(exec_ctx, pollset, fds,
|
504
|
+
GPR_ARRAY_SIZE(fds));
|
505
|
+
GRPC_FD_UNREF(fds[0], "basicpoll");
|
506
|
+
} else {
|
507
|
+
/* old fd is orphaned and we haven't cleaned it up until now, so remain a
|
508
|
+
* unary poller */
|
509
|
+
GRPC_FD_UNREF(fds[0], "basicpoll");
|
510
|
+
pollset->data.ptr = fd;
|
511
|
+
GRPC_FD_REF(fd, "basicpoll");
|
512
|
+
}
|
513
|
+
goto exit;
|
514
|
+
}
|
515
|
+
|
516
|
+
/* Now we need to promote. This needs to happen when we're not polling. Since
|
517
|
+
* this may be called from poll, the wait needs to happen asynchronously. */
|
518
|
+
GRPC_FD_REF(fd, "basicpoll_add");
|
519
|
+
pollset->in_flight_cbs++;
|
520
|
+
up_args = gpr_malloc(sizeof(*up_args));
|
521
|
+
up_args->fd = fd;
|
522
|
+
up_args->original_vtable = pollset->vtable;
|
523
|
+
up_args->pollset = pollset;
|
524
|
+
up_args->promotion_closure.cb = basic_do_promote;
|
525
|
+
up_args->promotion_closure.cb_arg = up_args;
|
526
|
+
|
527
|
+
grpc_closure_list_add(&pollset->idle_jobs, &up_args->promotion_closure, 1);
|
528
|
+
grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST);
|
529
|
+
|
530
|
+
exit:
|
531
|
+
if (and_unlock_pollset) {
|
532
|
+
gpr_mu_unlock(&pollset->mu);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
|
536
|
+
static void basic_pollset_maybe_work_and_unlock(grpc_exec_ctx *exec_ctx,
|
537
|
+
grpc_pollset *pollset,
|
538
|
+
grpc_pollset_worker *worker,
|
539
|
+
gpr_timespec deadline,
|
540
|
+
gpr_timespec now) {
|
541
|
+
#define POLLOUT_CHECK (POLLOUT | POLLHUP | POLLERR)
|
542
|
+
#define POLLIN_CHECK (POLLIN | POLLHUP | POLLERR)
|
543
|
+
|
544
|
+
struct pollfd pfd[3];
|
545
|
+
grpc_fd *fd;
|
546
|
+
grpc_fd_watcher fd_watcher;
|
547
|
+
int timeout;
|
548
|
+
int r;
|
549
|
+
nfds_t nfds;
|
550
|
+
|
551
|
+
fd = pollset->data.ptr;
|
552
|
+
if (fd && grpc_fd_is_orphaned(fd)) {
|
553
|
+
GRPC_FD_UNREF(fd, "basicpoll");
|
554
|
+
fd = pollset->data.ptr = NULL;
|
555
|
+
}
|
556
|
+
timeout = grpc_poll_deadline_to_millis_timeout(deadline, now);
|
557
|
+
pfd[0].fd = GRPC_WAKEUP_FD_GET_READ_FD(&grpc_global_wakeup_fd);
|
558
|
+
pfd[0].events = POLLIN;
|
559
|
+
pfd[0].revents = 0;
|
560
|
+
pfd[1].fd = GRPC_WAKEUP_FD_GET_READ_FD(&worker->wakeup_fd->fd);
|
561
|
+
pfd[1].events = POLLIN;
|
562
|
+
pfd[1].revents = 0;
|
563
|
+
nfds = 2;
|
564
|
+
if (fd) {
|
565
|
+
pfd[2].fd = fd->fd;
|
566
|
+
pfd[2].revents = 0;
|
567
|
+
GRPC_FD_REF(fd, "basicpoll_begin");
|
568
|
+
gpr_mu_unlock(&pollset->mu);
|
569
|
+
pfd[2].events = (short)grpc_fd_begin_poll(fd, pollset, worker, POLLIN,
|
570
|
+
POLLOUT, &fd_watcher);
|
571
|
+
if (pfd[2].events != 0) {
|
572
|
+
nfds++;
|
573
|
+
}
|
574
|
+
} else {
|
575
|
+
gpr_mu_unlock(&pollset->mu);
|
576
|
+
}
|
577
|
+
|
578
|
+
/* TODO(vpai): Consider first doing a 0 timeout poll here to avoid
|
579
|
+
even going into the blocking annotation if possible */
|
580
|
+
/* poll fd count (argument 2) is shortened by one if we have no events
|
581
|
+
to poll on - such that it only includes the kicker */
|
582
|
+
GPR_TIMER_BEGIN("poll", 0);
|
583
|
+
GRPC_SCHEDULING_START_BLOCKING_REGION;
|
584
|
+
r = grpc_poll_function(pfd, nfds, timeout);
|
585
|
+
GRPC_SCHEDULING_END_BLOCKING_REGION;
|
586
|
+
GPR_TIMER_END("poll", 0);
|
587
|
+
|
588
|
+
if (r < 0) {
|
589
|
+
if (errno != EINTR) {
|
590
|
+
gpr_log(GPR_ERROR, "poll() failed: %s", strerror(errno));
|
591
|
+
}
|
592
|
+
if (fd) {
|
593
|
+
grpc_fd_end_poll(exec_ctx, &fd_watcher, 0, 0);
|
594
|
+
}
|
595
|
+
} else if (r == 0) {
|
596
|
+
if (fd) {
|
597
|
+
grpc_fd_end_poll(exec_ctx, &fd_watcher, 0, 0);
|
598
|
+
}
|
599
|
+
} else {
|
600
|
+
if (pfd[0].revents & POLLIN_CHECK) {
|
601
|
+
grpc_wakeup_fd_consume_wakeup(&grpc_global_wakeup_fd);
|
602
|
+
}
|
603
|
+
if (pfd[1].revents & POLLIN_CHECK) {
|
604
|
+
grpc_wakeup_fd_consume_wakeup(&worker->wakeup_fd->fd);
|
605
|
+
}
|
606
|
+
if (nfds > 2) {
|
607
|
+
grpc_fd_end_poll(exec_ctx, &fd_watcher, pfd[2].revents & POLLIN_CHECK,
|
608
|
+
pfd[2].revents & POLLOUT_CHECK);
|
609
|
+
} else if (fd) {
|
610
|
+
grpc_fd_end_poll(exec_ctx, &fd_watcher, 0, 0);
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
if (fd) {
|
615
|
+
GRPC_FD_UNREF(fd, "basicpoll_begin");
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
619
|
+
static void basic_pollset_destroy(grpc_pollset *pollset) {
|
620
|
+
if (pollset->data.ptr != NULL) {
|
621
|
+
GRPC_FD_UNREF(pollset->data.ptr, "basicpoll");
|
622
|
+
pollset->data.ptr = NULL;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
|
626
|
+
static const grpc_pollset_vtable basic_pollset = {
|
627
|
+
basic_pollset_add_fd, basic_pollset_maybe_work_and_unlock,
|
628
|
+
basic_pollset_destroy, basic_pollset_destroy};
|
629
|
+
|
630
|
+
static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null) {
|
631
|
+
pollset->vtable = &basic_pollset;
|
632
|
+
pollset->data.ptr = fd_or_null;
|
633
|
+
if (fd_or_null != NULL) {
|
634
|
+
GRPC_FD_REF(fd_or_null, "basicpoll");
|
635
|
+
}
|
636
|
+
}
|
637
|
+
|
638
|
+
#endif /* GPR_POSIX_POLLSET */
|