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,915 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015-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 "rb_call.h"
|
35
|
+
|
36
|
+
#include <ruby/ruby.h>
|
37
|
+
|
38
|
+
#include <grpc/grpc.h>
|
39
|
+
#include <grpc/support/alloc.h>
|
40
|
+
|
41
|
+
#include "rb_byte_buffer.h"
|
42
|
+
#include "rb_call_credentials.h"
|
43
|
+
#include "rb_completion_queue.h"
|
44
|
+
#include "rb_grpc.h"
|
45
|
+
|
46
|
+
/* grpc_rb_cCall is the Call class whose instances proxy grpc_call. */
|
47
|
+
static VALUE grpc_rb_cCall;
|
48
|
+
|
49
|
+
/* grpc_rb_eCallError is the ruby class of the exception thrown during call
|
50
|
+
operations; */
|
51
|
+
VALUE grpc_rb_eCallError = Qnil;
|
52
|
+
|
53
|
+
/* grpc_rb_eOutOfTime is the ruby class of the exception thrown to indicate
|
54
|
+
a timeout. */
|
55
|
+
static VALUE grpc_rb_eOutOfTime = Qnil;
|
56
|
+
|
57
|
+
/* grpc_rb_sBatchResult is struct class used to hold the results of a batch
|
58
|
+
* call. */
|
59
|
+
static VALUE grpc_rb_sBatchResult;
|
60
|
+
|
61
|
+
/* grpc_rb_cMdAry is the MetadataArray class whose instances proxy
|
62
|
+
* grpc_metadata_array. */
|
63
|
+
static VALUE grpc_rb_cMdAry;
|
64
|
+
|
65
|
+
/* id_cq is the name of the hidden ivar that preserves a reference to a
|
66
|
+
* completion queue */
|
67
|
+
static ID id_cq;
|
68
|
+
|
69
|
+
/* id_flags is the name of the hidden ivar that preserves the value of
|
70
|
+
* the flags used to create metadata from a Hash */
|
71
|
+
static ID id_flags;
|
72
|
+
|
73
|
+
/* id_input_md is the name of the hidden ivar that preserves the hash used to
|
74
|
+
* create metadata, so that references to the strings it contains last as long
|
75
|
+
* as the call the metadata is added to. */
|
76
|
+
static ID id_input_md;
|
77
|
+
|
78
|
+
/* id_metadata is name of the attribute used to access the metadata hash
|
79
|
+
* received by the call and subsequently saved on it. */
|
80
|
+
static ID id_metadata;
|
81
|
+
|
82
|
+
/* id_status is name of the attribute used to access the status object
|
83
|
+
* received by the call and subsequently saved on it. */
|
84
|
+
static ID id_status;
|
85
|
+
|
86
|
+
/* id_write_flag is name of the attribute used to access the write_flag
|
87
|
+
* saved on the call. */
|
88
|
+
static ID id_write_flag;
|
89
|
+
|
90
|
+
/* sym_* are the symbol for attributes of grpc_rb_sBatchResult. */
|
91
|
+
static VALUE sym_send_message;
|
92
|
+
static VALUE sym_send_metadata;
|
93
|
+
static VALUE sym_send_close;
|
94
|
+
static VALUE sym_send_status;
|
95
|
+
static VALUE sym_message;
|
96
|
+
static VALUE sym_status;
|
97
|
+
static VALUE sym_cancelled;
|
98
|
+
|
99
|
+
/* hash_all_calls is a hash of Call address -> reference count that is used to
|
100
|
+
* track the creation and destruction of rb_call instances.
|
101
|
+
*/
|
102
|
+
static VALUE hash_all_calls;
|
103
|
+
|
104
|
+
/* Destroys a Call. */
|
105
|
+
static void grpc_rb_call_destroy(void *p) {
|
106
|
+
grpc_call *call = NULL;
|
107
|
+
VALUE ref_count = Qnil;
|
108
|
+
if (p == NULL) {
|
109
|
+
return;
|
110
|
+
};
|
111
|
+
call = (grpc_call *)p;
|
112
|
+
|
113
|
+
ref_count = rb_hash_aref(hash_all_calls, OFFT2NUM((VALUE)call));
|
114
|
+
if (ref_count == Qnil) {
|
115
|
+
return; /* No longer in the hash, so already deleted */
|
116
|
+
} else if (NUM2UINT(ref_count) == 1) {
|
117
|
+
rb_hash_delete(hash_all_calls, OFFT2NUM((VALUE)call));
|
118
|
+
grpc_call_destroy(call);
|
119
|
+
} else {
|
120
|
+
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)call),
|
121
|
+
UINT2NUM(NUM2UINT(ref_count) - 1));
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
static size_t md_ary_datasize(const void *p) {
|
126
|
+
const grpc_metadata_array *const ary = (grpc_metadata_array *)p;
|
127
|
+
size_t i, datasize = sizeof(grpc_metadata_array);
|
128
|
+
for (i = 0; i < ary->count; ++i) {
|
129
|
+
const grpc_metadata *const md = &ary->metadata[i];
|
130
|
+
datasize += strlen(md->key);
|
131
|
+
datasize += md->value_length;
|
132
|
+
}
|
133
|
+
datasize += ary->capacity * sizeof(grpc_metadata);
|
134
|
+
return datasize;
|
135
|
+
}
|
136
|
+
|
137
|
+
static const rb_data_type_t grpc_rb_md_ary_data_type = {
|
138
|
+
"grpc_metadata_array",
|
139
|
+
{GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, md_ary_datasize,
|
140
|
+
{NULL, NULL}},
|
141
|
+
NULL,
|
142
|
+
NULL,
|
143
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
144
|
+
/* it is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because
|
145
|
+
* grpc_rb_call_destroy
|
146
|
+
* touches a hash object.
|
147
|
+
* TODO(yugui) Directly use st_table and call the free function earlier?
|
148
|
+
*/
|
149
|
+
0,
|
150
|
+
#endif
|
151
|
+
};
|
152
|
+
|
153
|
+
/* Describes grpc_call struct for RTypedData */
|
154
|
+
static const rb_data_type_t grpc_call_data_type = {
|
155
|
+
"grpc_call",
|
156
|
+
{GRPC_RB_GC_NOT_MARKED, grpc_rb_call_destroy, GRPC_RB_MEMSIZE_UNAVAILABLE,
|
157
|
+
{NULL, NULL}},
|
158
|
+
NULL,
|
159
|
+
NULL,
|
160
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
161
|
+
/* it is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because
|
162
|
+
* grpc_rb_call_destroy
|
163
|
+
* touches a hash object.
|
164
|
+
* TODO(yugui) Directly use st_table and call the free function earlier?
|
165
|
+
*/
|
166
|
+
0,
|
167
|
+
#endif
|
168
|
+
};
|
169
|
+
|
170
|
+
/* Error code details is a hash containing text strings describing errors */
|
171
|
+
VALUE rb_error_code_details;
|
172
|
+
|
173
|
+
/* Obtains the error detail string for given error code */
|
174
|
+
const char *grpc_call_error_detail_of(grpc_call_error err) {
|
175
|
+
VALUE detail_ref = rb_hash_aref(rb_error_code_details, UINT2NUM(err));
|
176
|
+
const char *detail = "unknown error code!";
|
177
|
+
if (detail_ref != Qnil) {
|
178
|
+
detail = StringValueCStr(detail_ref);
|
179
|
+
}
|
180
|
+
return detail;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Called by clients to cancel an RPC on the server.
|
184
|
+
Can be called multiple times, from any thread. */
|
185
|
+
static VALUE grpc_rb_call_cancel(VALUE self) {
|
186
|
+
grpc_call *call = NULL;
|
187
|
+
grpc_call_error err;
|
188
|
+
TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
|
189
|
+
err = grpc_call_cancel(call, NULL);
|
190
|
+
if (err != GRPC_CALL_OK) {
|
191
|
+
rb_raise(grpc_rb_eCallError, "cancel failed: %s (code=%d)",
|
192
|
+
grpc_call_error_detail_of(err), err);
|
193
|
+
}
|
194
|
+
|
195
|
+
return Qnil;
|
196
|
+
}
|
197
|
+
|
198
|
+
/* Called to obtain the peer that this call is connected to. */
|
199
|
+
static VALUE grpc_rb_call_get_peer(VALUE self) {
|
200
|
+
VALUE res = Qnil;
|
201
|
+
grpc_call *call = NULL;
|
202
|
+
char *peer = NULL;
|
203
|
+
TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
|
204
|
+
peer = grpc_call_get_peer(call);
|
205
|
+
res = rb_str_new2(peer);
|
206
|
+
gpr_free(peer);
|
207
|
+
|
208
|
+
return res;
|
209
|
+
}
|
210
|
+
|
211
|
+
/*
|
212
|
+
call-seq:
|
213
|
+
status = call.status
|
214
|
+
|
215
|
+
Gets the status object saved the call. */
|
216
|
+
static VALUE grpc_rb_call_get_status(VALUE self) {
|
217
|
+
return rb_ivar_get(self, id_status);
|
218
|
+
}
|
219
|
+
|
220
|
+
/*
|
221
|
+
call-seq:
|
222
|
+
call.status = status
|
223
|
+
|
224
|
+
Saves a status object on the call. */
|
225
|
+
static VALUE grpc_rb_call_set_status(VALUE self, VALUE status) {
|
226
|
+
if (!NIL_P(status) && rb_obj_class(status) != grpc_rb_sStatus) {
|
227
|
+
rb_raise(rb_eTypeError, "bad status: got:<%s> want: <Struct::Status>",
|
228
|
+
rb_obj_classname(status));
|
229
|
+
return Qnil;
|
230
|
+
}
|
231
|
+
|
232
|
+
return rb_ivar_set(self, id_status, status);
|
233
|
+
}
|
234
|
+
|
235
|
+
/*
|
236
|
+
call-seq:
|
237
|
+
metadata = call.metadata
|
238
|
+
|
239
|
+
Gets the metadata object saved the call. */
|
240
|
+
static VALUE grpc_rb_call_get_metadata(VALUE self) {
|
241
|
+
return rb_ivar_get(self, id_metadata);
|
242
|
+
}
|
243
|
+
|
244
|
+
/*
|
245
|
+
call-seq:
|
246
|
+
call.metadata = metadata
|
247
|
+
|
248
|
+
Saves the metadata hash on the call. */
|
249
|
+
static VALUE grpc_rb_call_set_metadata(VALUE self, VALUE metadata) {
|
250
|
+
if (!NIL_P(metadata) && TYPE(metadata) != T_HASH) {
|
251
|
+
rb_raise(rb_eTypeError, "bad metadata: got:<%s> want: <Hash>",
|
252
|
+
rb_obj_classname(metadata));
|
253
|
+
return Qnil;
|
254
|
+
}
|
255
|
+
|
256
|
+
return rb_ivar_set(self, id_metadata, metadata);
|
257
|
+
}
|
258
|
+
|
259
|
+
/*
|
260
|
+
call-seq:
|
261
|
+
write_flag = call.write_flag
|
262
|
+
|
263
|
+
Gets the write_flag value saved the call. */
|
264
|
+
static VALUE grpc_rb_call_get_write_flag(VALUE self) {
|
265
|
+
return rb_ivar_get(self, id_write_flag);
|
266
|
+
}
|
267
|
+
|
268
|
+
/*
|
269
|
+
call-seq:
|
270
|
+
call.write_flag = write_flag
|
271
|
+
|
272
|
+
Saves the write_flag on the call. */
|
273
|
+
static VALUE grpc_rb_call_set_write_flag(VALUE self, VALUE write_flag) {
|
274
|
+
if (!NIL_P(write_flag) && TYPE(write_flag) != T_FIXNUM) {
|
275
|
+
rb_raise(rb_eTypeError, "bad write_flag: got:<%s> want: <Fixnum>",
|
276
|
+
rb_obj_classname(write_flag));
|
277
|
+
return Qnil;
|
278
|
+
}
|
279
|
+
|
280
|
+
return rb_ivar_set(self, id_write_flag, write_flag);
|
281
|
+
}
|
282
|
+
|
283
|
+
/*
|
284
|
+
call-seq:
|
285
|
+
call.set_credentials call_credentials
|
286
|
+
|
287
|
+
Sets credentials on a call */
|
288
|
+
static VALUE grpc_rb_call_set_credentials(VALUE self, VALUE credentials) {
|
289
|
+
grpc_call *call = NULL;
|
290
|
+
grpc_call_credentials *creds;
|
291
|
+
grpc_call_error err;
|
292
|
+
TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
|
293
|
+
creds = grpc_rb_get_wrapped_call_credentials(credentials);
|
294
|
+
err = grpc_call_set_credentials(call, creds);
|
295
|
+
if (err != GRPC_CALL_OK) {
|
296
|
+
rb_raise(grpc_rb_eCallError,
|
297
|
+
"grpc_call_set_credentials failed with %s (code=%d)",
|
298
|
+
grpc_call_error_detail_of(err), err);
|
299
|
+
}
|
300
|
+
return Qnil;
|
301
|
+
}
|
302
|
+
|
303
|
+
/* grpc_rb_md_ary_fill_hash_cb is the hash iteration callback used
|
304
|
+
to fill grpc_metadata_array.
|
305
|
+
|
306
|
+
it's capacity should have been computed via a prior call to
|
307
|
+
grpc_rb_md_ary_fill_hash_cb
|
308
|
+
*/
|
309
|
+
static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
|
310
|
+
grpc_metadata_array *md_ary = NULL;
|
311
|
+
long array_length;
|
312
|
+
long i;
|
313
|
+
char *key_str;
|
314
|
+
size_t key_len;
|
315
|
+
char *value_str;
|
316
|
+
size_t value_len;
|
317
|
+
|
318
|
+
if (TYPE(key) == T_SYMBOL) {
|
319
|
+
key_str = (char *)rb_id2name(SYM2ID(key));
|
320
|
+
key_len = strlen(key_str);
|
321
|
+
} else { /* StringValueCStr does all other type exclusions for us */
|
322
|
+
key_str = StringValueCStr(key);
|
323
|
+
key_len = RSTRING_LEN(key);
|
324
|
+
}
|
325
|
+
|
326
|
+
if (!grpc_header_key_is_legal(key_str, key_len)) {
|
327
|
+
rb_raise(rb_eArgError,
|
328
|
+
"'%s' is an invalid header key, must match [a-z0-9-_.]+",
|
329
|
+
key_str);
|
330
|
+
return ST_STOP;
|
331
|
+
}
|
332
|
+
|
333
|
+
/* Construct a metadata object from key and value and add it */
|
334
|
+
TypedData_Get_Struct(md_ary_obj, grpc_metadata_array,
|
335
|
+
&grpc_rb_md_ary_data_type, md_ary);
|
336
|
+
|
337
|
+
if (TYPE(val) == T_ARRAY) {
|
338
|
+
array_length = RARRAY_LEN(val);
|
339
|
+
/* If the value is an array, add capacity for each value in the array */
|
340
|
+
for (i = 0; i < array_length; i++) {
|
341
|
+
value_str = RSTRING_PTR(rb_ary_entry(val, i));
|
342
|
+
value_len = RSTRING_LEN(rb_ary_entry(val, i));
|
343
|
+
if (!grpc_is_binary_header(key_str, key_len) &&
|
344
|
+
!grpc_header_nonbin_value_is_legal(value_str, value_len)) {
|
345
|
+
// The value has invalid characters
|
346
|
+
rb_raise(rb_eArgError,
|
347
|
+
"Header value '%s' has invalid characters", value_str);
|
348
|
+
return ST_STOP;
|
349
|
+
}
|
350
|
+
md_ary->metadata[md_ary->count].key = key_str;
|
351
|
+
md_ary->metadata[md_ary->count].value = value_str;
|
352
|
+
md_ary->metadata[md_ary->count].value_length = value_len;
|
353
|
+
md_ary->count += 1;
|
354
|
+
}
|
355
|
+
} else {
|
356
|
+
value_str = RSTRING_PTR(val);
|
357
|
+
value_len = RSTRING_LEN(val);
|
358
|
+
if (!grpc_is_binary_header(key_str, key_len) &&
|
359
|
+
!grpc_header_nonbin_value_is_legal(value_str, value_len)) {
|
360
|
+
// The value has invalid characters
|
361
|
+
rb_raise(rb_eArgError,
|
362
|
+
"Header value '%s' has invalid characters", value_str);
|
363
|
+
return ST_STOP;
|
364
|
+
}
|
365
|
+
md_ary->metadata[md_ary->count].key = key_str;
|
366
|
+
md_ary->metadata[md_ary->count].value = value_str;
|
367
|
+
md_ary->metadata[md_ary->count].value_length = value_len;
|
368
|
+
md_ary->count += 1;
|
369
|
+
}
|
370
|
+
|
371
|
+
return ST_CONTINUE;
|
372
|
+
}
|
373
|
+
|
374
|
+
/* grpc_rb_md_ary_capacity_hash_cb is the hash iteration callback used
|
375
|
+
to pre-compute the capacity a grpc_metadata_array.
|
376
|
+
*/
|
377
|
+
static int grpc_rb_md_ary_capacity_hash_cb(VALUE key, VALUE val,
|
378
|
+
VALUE md_ary_obj) {
|
379
|
+
grpc_metadata_array *md_ary = NULL;
|
380
|
+
|
381
|
+
(void)key;
|
382
|
+
|
383
|
+
/* Construct a metadata object from key and value and add it */
|
384
|
+
TypedData_Get_Struct(md_ary_obj, grpc_metadata_array,
|
385
|
+
&grpc_rb_md_ary_data_type, md_ary);
|
386
|
+
|
387
|
+
if (TYPE(val) == T_ARRAY) {
|
388
|
+
/* If the value is an array, add capacity for each value in the array */
|
389
|
+
md_ary->capacity += RARRAY_LEN(val);
|
390
|
+
} else {
|
391
|
+
md_ary->capacity += 1;
|
392
|
+
}
|
393
|
+
return ST_CONTINUE;
|
394
|
+
}
|
395
|
+
|
396
|
+
/* grpc_rb_md_ary_convert converts a ruby metadata hash into
|
397
|
+
a grpc_metadata_array.
|
398
|
+
*/
|
399
|
+
void grpc_rb_md_ary_convert(VALUE md_ary_hash,
|
400
|
+
grpc_metadata_array *md_ary) {
|
401
|
+
VALUE md_ary_obj = Qnil;
|
402
|
+
if (md_ary_hash == Qnil) {
|
403
|
+
return; /* Do nothing if the expected has value is nil */
|
404
|
+
}
|
405
|
+
if (TYPE(md_ary_hash) != T_HASH) {
|
406
|
+
rb_raise(rb_eTypeError, "md_ary_convert: got <%s>, want <Hash>",
|
407
|
+
rb_obj_classname(md_ary_hash));
|
408
|
+
return;
|
409
|
+
}
|
410
|
+
|
411
|
+
/* Initialize the array, compute it's capacity, then fill it. */
|
412
|
+
grpc_metadata_array_init(md_ary);
|
413
|
+
md_ary_obj =
|
414
|
+
TypedData_Wrap_Struct(grpc_rb_cMdAry, &grpc_rb_md_ary_data_type, md_ary);
|
415
|
+
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_capacity_hash_cb, md_ary_obj);
|
416
|
+
md_ary->metadata = gpr_malloc(md_ary->capacity * sizeof(grpc_metadata));
|
417
|
+
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_fill_hash_cb, md_ary_obj);
|
418
|
+
}
|
419
|
+
|
420
|
+
/* Converts a metadata array to a hash. */
|
421
|
+
VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary) {
|
422
|
+
VALUE key = Qnil;
|
423
|
+
VALUE new_ary = Qnil;
|
424
|
+
VALUE value = Qnil;
|
425
|
+
VALUE result = rb_hash_new();
|
426
|
+
size_t i;
|
427
|
+
|
428
|
+
for (i = 0; i < md_ary->count; i++) {
|
429
|
+
key = rb_str_new2(md_ary->metadata[i].key);
|
430
|
+
value = rb_hash_aref(result, key);
|
431
|
+
if (value == Qnil) {
|
432
|
+
value = rb_str_new(md_ary->metadata[i].value,
|
433
|
+
md_ary->metadata[i].value_length);
|
434
|
+
rb_hash_aset(result, key, value);
|
435
|
+
} else if (TYPE(value) == T_ARRAY) {
|
436
|
+
/* Add the string to the returned array */
|
437
|
+
rb_ary_push(value, rb_str_new(md_ary->metadata[i].value,
|
438
|
+
md_ary->metadata[i].value_length));
|
439
|
+
} else {
|
440
|
+
/* Add the current value with this key and the new one to an array */
|
441
|
+
new_ary = rb_ary_new();
|
442
|
+
rb_ary_push(new_ary, value);
|
443
|
+
rb_ary_push(new_ary, rb_str_new(md_ary->metadata[i].value,
|
444
|
+
md_ary->metadata[i].value_length));
|
445
|
+
rb_hash_aset(result, key, new_ary);
|
446
|
+
}
|
447
|
+
}
|
448
|
+
return result;
|
449
|
+
}
|
450
|
+
|
451
|
+
/* grpc_rb_call_check_op_keys_hash_cb is a hash iteration func that checks
|
452
|
+
each key of an ops hash is valid.
|
453
|
+
*/
|
454
|
+
static int grpc_rb_call_check_op_keys_hash_cb(VALUE key, VALUE val,
|
455
|
+
VALUE ops_ary) {
|
456
|
+
(void)val;
|
457
|
+
/* Update the capacity; the value is an array, add capacity for each value in
|
458
|
+
* the array */
|
459
|
+
if (TYPE(key) != T_FIXNUM) {
|
460
|
+
rb_raise(rb_eTypeError, "invalid operation : got <%s>, want <Fixnum>",
|
461
|
+
rb_obj_classname(key));
|
462
|
+
return ST_STOP;
|
463
|
+
}
|
464
|
+
switch (NUM2INT(key)) {
|
465
|
+
case GRPC_OP_SEND_INITIAL_METADATA:
|
466
|
+
case GRPC_OP_SEND_MESSAGE:
|
467
|
+
case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
|
468
|
+
case GRPC_OP_SEND_STATUS_FROM_SERVER:
|
469
|
+
case GRPC_OP_RECV_INITIAL_METADATA:
|
470
|
+
case GRPC_OP_RECV_MESSAGE:
|
471
|
+
case GRPC_OP_RECV_STATUS_ON_CLIENT:
|
472
|
+
case GRPC_OP_RECV_CLOSE_ON_SERVER:
|
473
|
+
rb_ary_push(ops_ary, key);
|
474
|
+
return ST_CONTINUE;
|
475
|
+
default:
|
476
|
+
rb_raise(rb_eTypeError, "invalid operation : bad value %d", NUM2INT(key));
|
477
|
+
};
|
478
|
+
return ST_STOP;
|
479
|
+
}
|
480
|
+
|
481
|
+
/* grpc_rb_op_update_status_from_server adds the values in a ruby status
|
482
|
+
struct to the 'send_status_from_server' portion of an op.
|
483
|
+
*/
|
484
|
+
static void grpc_rb_op_update_status_from_server(grpc_op *op,
|
485
|
+
grpc_metadata_array *md_ary,
|
486
|
+
VALUE status) {
|
487
|
+
VALUE code = rb_struct_aref(status, sym_code);
|
488
|
+
VALUE details = rb_struct_aref(status, sym_details);
|
489
|
+
VALUE metadata_hash = rb_struct_aref(status, sym_metadata);
|
490
|
+
|
491
|
+
/* TODO: add check to ensure status is the correct struct type */
|
492
|
+
if (TYPE(code) != T_FIXNUM) {
|
493
|
+
rb_raise(rb_eTypeError, "invalid code : got <%s>, want <Fixnum>",
|
494
|
+
rb_obj_classname(code));
|
495
|
+
return;
|
496
|
+
}
|
497
|
+
if (TYPE(details) != T_STRING) {
|
498
|
+
rb_raise(rb_eTypeError, "invalid details : got <%s>, want <String>",
|
499
|
+
rb_obj_classname(code));
|
500
|
+
return;
|
501
|
+
}
|
502
|
+
op->data.send_status_from_server.status = NUM2INT(code);
|
503
|
+
op->data.send_status_from_server.status_details = StringValueCStr(details);
|
504
|
+
grpc_rb_md_ary_convert(metadata_hash, md_ary);
|
505
|
+
op->data.send_status_from_server.trailing_metadata_count = md_ary->count;
|
506
|
+
op->data.send_status_from_server.trailing_metadata = md_ary->metadata;
|
507
|
+
}
|
508
|
+
|
509
|
+
/* run_batch_stack holds various values used by the
|
510
|
+
* grpc_rb_call_run_batch function */
|
511
|
+
typedef struct run_batch_stack {
|
512
|
+
/* The batch ops */
|
513
|
+
grpc_op ops[8]; /* 8 is the maximum number of operations */
|
514
|
+
size_t op_num; /* tracks the last added operation */
|
515
|
+
|
516
|
+
/* Data being sent */
|
517
|
+
grpc_metadata_array send_metadata;
|
518
|
+
grpc_metadata_array send_trailing_metadata;
|
519
|
+
|
520
|
+
/* Data being received */
|
521
|
+
grpc_byte_buffer *recv_message;
|
522
|
+
grpc_metadata_array recv_metadata;
|
523
|
+
grpc_metadata_array recv_trailing_metadata;
|
524
|
+
int recv_cancelled;
|
525
|
+
grpc_status_code recv_status;
|
526
|
+
char *recv_status_details;
|
527
|
+
size_t recv_status_details_capacity;
|
528
|
+
uint write_flag;
|
529
|
+
} run_batch_stack;
|
530
|
+
|
531
|
+
/* grpc_run_batch_stack_init ensures the run_batch_stack is properly
|
532
|
+
* initialized */
|
533
|
+
static void grpc_run_batch_stack_init(run_batch_stack *st, uint write_flag) {
|
534
|
+
MEMZERO(st, run_batch_stack, 1);
|
535
|
+
grpc_metadata_array_init(&st->send_metadata);
|
536
|
+
grpc_metadata_array_init(&st->send_trailing_metadata);
|
537
|
+
grpc_metadata_array_init(&st->recv_metadata);
|
538
|
+
grpc_metadata_array_init(&st->recv_trailing_metadata);
|
539
|
+
st->op_num = 0;
|
540
|
+
st->write_flag = write_flag;
|
541
|
+
}
|
542
|
+
|
543
|
+
/* grpc_run_batch_stack_cleanup ensures the run_batch_stack is properly
|
544
|
+
* cleaned up */
|
545
|
+
static void grpc_run_batch_stack_cleanup(run_batch_stack *st) {
|
546
|
+
size_t i = 0;
|
547
|
+
|
548
|
+
grpc_metadata_array_destroy(&st->send_metadata);
|
549
|
+
grpc_metadata_array_destroy(&st->send_trailing_metadata);
|
550
|
+
grpc_metadata_array_destroy(&st->recv_metadata);
|
551
|
+
grpc_metadata_array_destroy(&st->recv_trailing_metadata);
|
552
|
+
|
553
|
+
if (st->recv_status_details != NULL) {
|
554
|
+
gpr_free(st->recv_status_details);
|
555
|
+
}
|
556
|
+
|
557
|
+
grpc_byte_buffer_destroy(st->recv_message);
|
558
|
+
|
559
|
+
for (i = 0; i < st->op_num; i++) {
|
560
|
+
if (st->ops[i].op == GRPC_OP_SEND_MESSAGE) {
|
561
|
+
grpc_byte_buffer_destroy(st->ops[i].data.send_message);
|
562
|
+
}
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
/* grpc_run_batch_stack_fill_ops fills the run_batch_stack ops array from
|
567
|
+
* ops_hash */
|
568
|
+
static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) {
|
569
|
+
VALUE this_op = Qnil;
|
570
|
+
VALUE this_value = Qnil;
|
571
|
+
VALUE ops_ary = rb_ary_new();
|
572
|
+
size_t i = 0;
|
573
|
+
|
574
|
+
/* Create a ruby array with just the operation keys */
|
575
|
+
rb_hash_foreach(ops_hash, grpc_rb_call_check_op_keys_hash_cb, ops_ary);
|
576
|
+
|
577
|
+
/* Fill the ops array */
|
578
|
+
for (i = 0; i < (size_t)RARRAY_LEN(ops_ary); i++) {
|
579
|
+
this_op = rb_ary_entry(ops_ary, i);
|
580
|
+
this_value = rb_hash_aref(ops_hash, this_op);
|
581
|
+
st->ops[st->op_num].flags = 0;
|
582
|
+
switch (NUM2INT(this_op)) {
|
583
|
+
case GRPC_OP_SEND_INITIAL_METADATA:
|
584
|
+
/* N.B. later there is no need to explicitly delete the metadata keys
|
585
|
+
* and values, they are references to data in ruby objects. */
|
586
|
+
grpc_rb_md_ary_convert(this_value, &st->send_metadata);
|
587
|
+
st->ops[st->op_num].data.send_initial_metadata.count =
|
588
|
+
st->send_metadata.count;
|
589
|
+
st->ops[st->op_num].data.send_initial_metadata.metadata =
|
590
|
+
st->send_metadata.metadata;
|
591
|
+
break;
|
592
|
+
case GRPC_OP_SEND_MESSAGE:
|
593
|
+
st->ops[st->op_num].data.send_message = grpc_rb_s_to_byte_buffer(
|
594
|
+
RSTRING_PTR(this_value), RSTRING_LEN(this_value));
|
595
|
+
st->ops[st->op_num].flags = st->write_flag;
|
596
|
+
break;
|
597
|
+
case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
|
598
|
+
break;
|
599
|
+
case GRPC_OP_SEND_STATUS_FROM_SERVER:
|
600
|
+
/* N.B. later there is no need to explicitly delete the metadata keys
|
601
|
+
* and values, they are references to data in ruby objects. */
|
602
|
+
grpc_rb_op_update_status_from_server(
|
603
|
+
&st->ops[st->op_num], &st->send_trailing_metadata, this_value);
|
604
|
+
break;
|
605
|
+
case GRPC_OP_RECV_INITIAL_METADATA:
|
606
|
+
st->ops[st->op_num].data.recv_initial_metadata = &st->recv_metadata;
|
607
|
+
break;
|
608
|
+
case GRPC_OP_RECV_MESSAGE:
|
609
|
+
st->ops[st->op_num].data.recv_message = &st->recv_message;
|
610
|
+
break;
|
611
|
+
case GRPC_OP_RECV_STATUS_ON_CLIENT:
|
612
|
+
st->ops[st->op_num].data.recv_status_on_client.trailing_metadata =
|
613
|
+
&st->recv_trailing_metadata;
|
614
|
+
st->ops[st->op_num].data.recv_status_on_client.status =
|
615
|
+
&st->recv_status;
|
616
|
+
st->ops[st->op_num].data.recv_status_on_client.status_details =
|
617
|
+
&st->recv_status_details;
|
618
|
+
st->ops[st->op_num].data.recv_status_on_client.status_details_capacity =
|
619
|
+
&st->recv_status_details_capacity;
|
620
|
+
break;
|
621
|
+
case GRPC_OP_RECV_CLOSE_ON_SERVER:
|
622
|
+
st->ops[st->op_num].data.recv_close_on_server.cancelled =
|
623
|
+
&st->recv_cancelled;
|
624
|
+
break;
|
625
|
+
default:
|
626
|
+
grpc_run_batch_stack_cleanup(st);
|
627
|
+
rb_raise(rb_eTypeError, "invalid operation : bad value %d",
|
628
|
+
NUM2INT(this_op));
|
629
|
+
};
|
630
|
+
st->ops[st->op_num].op = (grpc_op_type)NUM2INT(this_op);
|
631
|
+
st->ops[st->op_num].reserved = NULL;
|
632
|
+
st->op_num++;
|
633
|
+
}
|
634
|
+
}
|
635
|
+
|
636
|
+
/* grpc_run_batch_stack_build_result fills constructs a ruby BatchResult struct
|
637
|
+
after the results have run */
|
638
|
+
static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) {
|
639
|
+
size_t i = 0;
|
640
|
+
VALUE result = rb_struct_new(grpc_rb_sBatchResult, Qnil, Qnil, Qnil, Qnil,
|
641
|
+
Qnil, Qnil, Qnil, Qnil, NULL);
|
642
|
+
for (i = 0; i < st->op_num; i++) {
|
643
|
+
switch (st->ops[i].op) {
|
644
|
+
case GRPC_OP_SEND_INITIAL_METADATA:
|
645
|
+
rb_struct_aset(result, sym_send_metadata, Qtrue);
|
646
|
+
break;
|
647
|
+
case GRPC_OP_SEND_MESSAGE:
|
648
|
+
rb_struct_aset(result, sym_send_message, Qtrue);
|
649
|
+
break;
|
650
|
+
case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
|
651
|
+
rb_struct_aset(result, sym_send_close, Qtrue);
|
652
|
+
break;
|
653
|
+
case GRPC_OP_SEND_STATUS_FROM_SERVER:
|
654
|
+
rb_struct_aset(result, sym_send_status, Qtrue);
|
655
|
+
break;
|
656
|
+
case GRPC_OP_RECV_INITIAL_METADATA:
|
657
|
+
rb_struct_aset(result, sym_metadata,
|
658
|
+
grpc_rb_md_ary_to_h(&st->recv_metadata));
|
659
|
+
case GRPC_OP_RECV_MESSAGE:
|
660
|
+
rb_struct_aset(result, sym_message,
|
661
|
+
grpc_rb_byte_buffer_to_s(st->recv_message));
|
662
|
+
break;
|
663
|
+
case GRPC_OP_RECV_STATUS_ON_CLIENT:
|
664
|
+
rb_struct_aset(
|
665
|
+
result, sym_status,
|
666
|
+
rb_struct_new(grpc_rb_sStatus, UINT2NUM(st->recv_status),
|
667
|
+
(st->recv_status_details == NULL
|
668
|
+
? Qnil
|
669
|
+
: rb_str_new2(st->recv_status_details)),
|
670
|
+
grpc_rb_md_ary_to_h(&st->recv_trailing_metadata),
|
671
|
+
NULL));
|
672
|
+
break;
|
673
|
+
case GRPC_OP_RECV_CLOSE_ON_SERVER:
|
674
|
+
rb_struct_aset(result, sym_send_close, Qtrue);
|
675
|
+
break;
|
676
|
+
default:
|
677
|
+
break;
|
678
|
+
}
|
679
|
+
}
|
680
|
+
return result;
|
681
|
+
}
|
682
|
+
|
683
|
+
/* call-seq:
|
684
|
+
cq = CompletionQueue.new
|
685
|
+
ops = {
|
686
|
+
GRPC::Core::CallOps::SEND_INITIAL_METADATA => <op_value>,
|
687
|
+
GRPC::Core::CallOps::SEND_MESSAGE => <op_value>,
|
688
|
+
...
|
689
|
+
}
|
690
|
+
tag = Object.new
|
691
|
+
timeout = 10
|
692
|
+
call.start_batch(cqueue, tag, timeout, ops)
|
693
|
+
|
694
|
+
Start a batch of operations defined in the array ops; when complete, post a
|
695
|
+
completion of type 'tag' to the completion queue bound to the call.
|
696
|
+
|
697
|
+
Also waits for the batch to complete, until timeout is reached.
|
698
|
+
The order of ops specified in the batch has no significance.
|
699
|
+
Only one operation of each type can be active at once in any given
|
700
|
+
batch */
|
701
|
+
static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
|
702
|
+
VALUE timeout, VALUE ops_hash) {
|
703
|
+
run_batch_stack st;
|
704
|
+
grpc_call *call = NULL;
|
705
|
+
grpc_event ev;
|
706
|
+
grpc_call_error err;
|
707
|
+
VALUE result = Qnil;
|
708
|
+
VALUE rb_write_flag = rb_ivar_get(self, id_write_flag);
|
709
|
+
uint write_flag = 0;
|
710
|
+
TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
|
711
|
+
|
712
|
+
/* Validate the ops args, adding them to a ruby array */
|
713
|
+
if (TYPE(ops_hash) != T_HASH) {
|
714
|
+
rb_raise(rb_eTypeError, "call#run_batch: ops hash should be a hash");
|
715
|
+
return Qnil;
|
716
|
+
}
|
717
|
+
if (rb_write_flag != Qnil) {
|
718
|
+
write_flag = NUM2UINT(rb_write_flag);
|
719
|
+
}
|
720
|
+
grpc_run_batch_stack_init(&st, write_flag);
|
721
|
+
grpc_run_batch_stack_fill_ops(&st, ops_hash);
|
722
|
+
|
723
|
+
/* call grpc_call_start_batch, then wait for it to complete using
|
724
|
+
* pluck_event */
|
725
|
+
err = grpc_call_start_batch(call, st.ops, st.op_num, ROBJECT(tag), NULL);
|
726
|
+
if (err != GRPC_CALL_OK) {
|
727
|
+
grpc_run_batch_stack_cleanup(&st);
|
728
|
+
rb_raise(grpc_rb_eCallError,
|
729
|
+
"grpc_call_start_batch failed with %s (code=%d)",
|
730
|
+
grpc_call_error_detail_of(err), err);
|
731
|
+
return Qnil;
|
732
|
+
}
|
733
|
+
ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
|
734
|
+
if (ev.type == GRPC_QUEUE_TIMEOUT) {
|
735
|
+
grpc_run_batch_stack_cleanup(&st);
|
736
|
+
rb_raise(grpc_rb_eOutOfTime, "grpc_call_start_batch timed out");
|
737
|
+
return Qnil;
|
738
|
+
}
|
739
|
+
|
740
|
+
/* Build and return the BatchResult struct result,
|
741
|
+
if there is an error, it's reflected in the status */
|
742
|
+
result = grpc_run_batch_stack_build_result(&st);
|
743
|
+
grpc_run_batch_stack_cleanup(&st);
|
744
|
+
return result;
|
745
|
+
}
|
746
|
+
|
747
|
+
static void Init_grpc_write_flags() {
|
748
|
+
/* Constants representing the write flags in grpc.h */
|
749
|
+
VALUE grpc_rb_mWriteFlags =
|
750
|
+
rb_define_module_under(grpc_rb_mGrpcCore, "WriteFlags");
|
751
|
+
rb_define_const(grpc_rb_mWriteFlags, "BUFFER_HINT",
|
752
|
+
UINT2NUM(GRPC_WRITE_BUFFER_HINT));
|
753
|
+
rb_define_const(grpc_rb_mWriteFlags, "NO_COMPRESS",
|
754
|
+
UINT2NUM(GRPC_WRITE_NO_COMPRESS));
|
755
|
+
}
|
756
|
+
|
757
|
+
static void Init_grpc_error_codes() {
|
758
|
+
/* Constants representing the error codes of grpc_call_error in grpc.h */
|
759
|
+
VALUE grpc_rb_mRpcErrors =
|
760
|
+
rb_define_module_under(grpc_rb_mGrpcCore, "RpcErrors");
|
761
|
+
rb_define_const(grpc_rb_mRpcErrors, "OK", UINT2NUM(GRPC_CALL_OK));
|
762
|
+
rb_define_const(grpc_rb_mRpcErrors, "ERROR", UINT2NUM(GRPC_CALL_ERROR));
|
763
|
+
rb_define_const(grpc_rb_mRpcErrors, "NOT_ON_SERVER",
|
764
|
+
UINT2NUM(GRPC_CALL_ERROR_NOT_ON_SERVER));
|
765
|
+
rb_define_const(grpc_rb_mRpcErrors, "NOT_ON_CLIENT",
|
766
|
+
UINT2NUM(GRPC_CALL_ERROR_NOT_ON_CLIENT));
|
767
|
+
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_ACCEPTED",
|
768
|
+
UINT2NUM(GRPC_CALL_ERROR_ALREADY_ACCEPTED));
|
769
|
+
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_INVOKED",
|
770
|
+
UINT2NUM(GRPC_CALL_ERROR_ALREADY_INVOKED));
|
771
|
+
rb_define_const(grpc_rb_mRpcErrors, "NOT_INVOKED",
|
772
|
+
UINT2NUM(GRPC_CALL_ERROR_NOT_INVOKED));
|
773
|
+
rb_define_const(grpc_rb_mRpcErrors, "ALREADY_FINISHED",
|
774
|
+
UINT2NUM(GRPC_CALL_ERROR_ALREADY_FINISHED));
|
775
|
+
rb_define_const(grpc_rb_mRpcErrors, "TOO_MANY_OPERATIONS",
|
776
|
+
UINT2NUM(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS));
|
777
|
+
rb_define_const(grpc_rb_mRpcErrors, "INVALID_FLAGS",
|
778
|
+
UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS));
|
779
|
+
|
780
|
+
/* Add the detail strings to a Hash */
|
781
|
+
rb_error_code_details = rb_hash_new();
|
782
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_OK),
|
783
|
+
rb_str_new2("ok"));
|
784
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR),
|
785
|
+
rb_str_new2("unknown error"));
|
786
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_NOT_ON_SERVER),
|
787
|
+
rb_str_new2("not available on a server"));
|
788
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_NOT_ON_CLIENT),
|
789
|
+
rb_str_new2("not available on a client"));
|
790
|
+
rb_hash_aset(rb_error_code_details,
|
791
|
+
UINT2NUM(GRPC_CALL_ERROR_ALREADY_ACCEPTED),
|
792
|
+
rb_str_new2("call is already accepted"));
|
793
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_ALREADY_INVOKED),
|
794
|
+
rb_str_new2("call is already invoked"));
|
795
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_NOT_INVOKED),
|
796
|
+
rb_str_new2("call is not yet invoked"));
|
797
|
+
rb_hash_aset(rb_error_code_details,
|
798
|
+
UINT2NUM(GRPC_CALL_ERROR_ALREADY_FINISHED),
|
799
|
+
rb_str_new2("call is already finished"));
|
800
|
+
rb_hash_aset(rb_error_code_details,
|
801
|
+
UINT2NUM(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS),
|
802
|
+
rb_str_new2("outstanding read or write present"));
|
803
|
+
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_INVALID_FLAGS),
|
804
|
+
rb_str_new2("a bad flag was given"));
|
805
|
+
rb_define_const(grpc_rb_mRpcErrors, "ErrorMessages", rb_error_code_details);
|
806
|
+
rb_obj_freeze(rb_error_code_details);
|
807
|
+
}
|
808
|
+
|
809
|
+
static void Init_grpc_op_codes() {
|
810
|
+
/* Constants representing operation type codes in grpc.h */
|
811
|
+
VALUE grpc_rb_mCallOps = rb_define_module_under(grpc_rb_mGrpcCore, "CallOps");
|
812
|
+
rb_define_const(grpc_rb_mCallOps, "SEND_INITIAL_METADATA",
|
813
|
+
UINT2NUM(GRPC_OP_SEND_INITIAL_METADATA));
|
814
|
+
rb_define_const(grpc_rb_mCallOps, "SEND_MESSAGE",
|
815
|
+
UINT2NUM(GRPC_OP_SEND_MESSAGE));
|
816
|
+
rb_define_const(grpc_rb_mCallOps, "SEND_CLOSE_FROM_CLIENT",
|
817
|
+
UINT2NUM(GRPC_OP_SEND_CLOSE_FROM_CLIENT));
|
818
|
+
rb_define_const(grpc_rb_mCallOps, "SEND_STATUS_FROM_SERVER",
|
819
|
+
UINT2NUM(GRPC_OP_SEND_STATUS_FROM_SERVER));
|
820
|
+
rb_define_const(grpc_rb_mCallOps, "RECV_INITIAL_METADATA",
|
821
|
+
UINT2NUM(GRPC_OP_RECV_INITIAL_METADATA));
|
822
|
+
rb_define_const(grpc_rb_mCallOps, "RECV_MESSAGE",
|
823
|
+
UINT2NUM(GRPC_OP_RECV_MESSAGE));
|
824
|
+
rb_define_const(grpc_rb_mCallOps, "RECV_STATUS_ON_CLIENT",
|
825
|
+
UINT2NUM(GRPC_OP_RECV_STATUS_ON_CLIENT));
|
826
|
+
rb_define_const(grpc_rb_mCallOps, "RECV_CLOSE_ON_SERVER",
|
827
|
+
UINT2NUM(GRPC_OP_RECV_CLOSE_ON_SERVER));
|
828
|
+
}
|
829
|
+
|
830
|
+
void Init_grpc_call() {
|
831
|
+
/* CallError inherits from Exception to signal that it is non-recoverable */
|
832
|
+
grpc_rb_eCallError =
|
833
|
+
rb_define_class_under(grpc_rb_mGrpcCore, "CallError", rb_eException);
|
834
|
+
grpc_rb_eOutOfTime =
|
835
|
+
rb_define_class_under(grpc_rb_mGrpcCore, "OutOfTime", rb_eException);
|
836
|
+
grpc_rb_cCall = rb_define_class_under(grpc_rb_mGrpcCore, "Call", rb_cObject);
|
837
|
+
grpc_rb_cMdAry =
|
838
|
+
rb_define_class_under(grpc_rb_mGrpcCore, "MetadataArray", rb_cObject);
|
839
|
+
|
840
|
+
/* Prevent allocation or inialization of the Call class */
|
841
|
+
rb_define_alloc_func(grpc_rb_cCall, grpc_rb_cannot_alloc);
|
842
|
+
rb_define_method(grpc_rb_cCall, "initialize", grpc_rb_cannot_init, 0);
|
843
|
+
rb_define_method(grpc_rb_cCall, "initialize_copy", grpc_rb_cannot_init_copy,
|
844
|
+
1);
|
845
|
+
|
846
|
+
/* Add ruby analogues of the Call methods. */
|
847
|
+
rb_define_method(grpc_rb_cCall, "run_batch", grpc_rb_call_run_batch, 4);
|
848
|
+
rb_define_method(grpc_rb_cCall, "cancel", grpc_rb_call_cancel, 0);
|
849
|
+
rb_define_method(grpc_rb_cCall, "peer", grpc_rb_call_get_peer, 0);
|
850
|
+
rb_define_method(grpc_rb_cCall, "status", grpc_rb_call_get_status, 0);
|
851
|
+
rb_define_method(grpc_rb_cCall, "status=", grpc_rb_call_set_status, 1);
|
852
|
+
rb_define_method(grpc_rb_cCall, "metadata", grpc_rb_call_get_metadata, 0);
|
853
|
+
rb_define_method(grpc_rb_cCall, "metadata=", grpc_rb_call_set_metadata, 1);
|
854
|
+
rb_define_method(grpc_rb_cCall, "write_flag", grpc_rb_call_get_write_flag, 0);
|
855
|
+
rb_define_method(grpc_rb_cCall, "write_flag=", grpc_rb_call_set_write_flag,
|
856
|
+
1);
|
857
|
+
rb_define_method(grpc_rb_cCall, "set_credentials!",
|
858
|
+
grpc_rb_call_set_credentials, 1);
|
859
|
+
|
860
|
+
/* Ids used to support call attributes */
|
861
|
+
id_metadata = rb_intern("metadata");
|
862
|
+
id_status = rb_intern("status");
|
863
|
+
id_write_flag = rb_intern("write_flag");
|
864
|
+
|
865
|
+
/* Ids used by the c wrapping internals. */
|
866
|
+
id_cq = rb_intern("__cq");
|
867
|
+
id_flags = rb_intern("__flags");
|
868
|
+
id_input_md = rb_intern("__input_md");
|
869
|
+
|
870
|
+
/* Ids used in constructing the batch result. */
|
871
|
+
sym_send_message = ID2SYM(rb_intern("send_message"));
|
872
|
+
sym_send_metadata = ID2SYM(rb_intern("send_metadata"));
|
873
|
+
sym_send_close = ID2SYM(rb_intern("send_close"));
|
874
|
+
sym_send_status = ID2SYM(rb_intern("send_status"));
|
875
|
+
sym_message = ID2SYM(rb_intern("message"));
|
876
|
+
sym_status = ID2SYM(rb_intern("status"));
|
877
|
+
sym_cancelled = ID2SYM(rb_intern("cancelled"));
|
878
|
+
|
879
|
+
/* The Struct used to return the run_batch result. */
|
880
|
+
grpc_rb_sBatchResult = rb_struct_define(
|
881
|
+
"BatchResult", "send_message", "send_metadata", "send_close",
|
882
|
+
"send_status", "message", "metadata", "status", "cancelled", NULL);
|
883
|
+
|
884
|
+
/* The hash for reference counting calls, to ensure they can't be destroyed
|
885
|
+
* more than once */
|
886
|
+
hash_all_calls = rb_hash_new();
|
887
|
+
rb_define_const(grpc_rb_cCall, "INTERNAL_ALL_CALLs", hash_all_calls);
|
888
|
+
|
889
|
+
Init_grpc_error_codes();
|
890
|
+
Init_grpc_op_codes();
|
891
|
+
Init_grpc_write_flags();
|
892
|
+
}
|
893
|
+
|
894
|
+
/* Gets the call from the ruby object */
|
895
|
+
grpc_call *grpc_rb_get_wrapped_call(VALUE v) {
|
896
|
+
grpc_call *c = NULL;
|
897
|
+
TypedData_Get_Struct(v, grpc_call, &grpc_call_data_type, c);
|
898
|
+
return c;
|
899
|
+
}
|
900
|
+
|
901
|
+
/* Obtains the wrapped object for a given call */
|
902
|
+
VALUE grpc_rb_wrap_call(grpc_call *c) {
|
903
|
+
VALUE obj = Qnil;
|
904
|
+
if (c == NULL) {
|
905
|
+
return Qnil;
|
906
|
+
}
|
907
|
+
obj = rb_hash_aref(hash_all_calls, OFFT2NUM((VALUE)c));
|
908
|
+
if (obj == Qnil) { /* Not in the hash add it */
|
909
|
+
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c), UINT2NUM(1));
|
910
|
+
} else {
|
911
|
+
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c),
|
912
|
+
UINT2NUM(NUM2UINT(obj) + 1));
|
913
|
+
}
|
914
|
+
return TypedData_Wrap_Struct(grpc_rb_cCall, &grpc_call_data_type, c);
|
915
|
+
}
|