grpc 1.58.3-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +40 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +208 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +875 -0
- data/src/ruby/ext/grpc/rb_channel.h +35 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +170 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +496 -0
- data/src/ruby/ext/grpc/rb_grpc.h +83 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +599 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +904 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +405 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +63 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +207 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +676 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +692 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +406 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
# Copyright 2017 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require_relative 'interceptor_registry'
|
15
|
+
|
16
|
+
# GRPC contains the General RPC module.
|
17
|
+
module GRPC
|
18
|
+
##
|
19
|
+
# Base class for interception in GRPC
|
20
|
+
#
|
21
|
+
class Interceptor
|
22
|
+
##
|
23
|
+
# @param [Hash] options A hash of options that will be used
|
24
|
+
# by the interceptor. This is an EXPERIMENTAL API.
|
25
|
+
#
|
26
|
+
def initialize(options = {})
|
27
|
+
@options = options || {}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# ClientInterceptor allows for wrapping outbound gRPC client stub requests.
|
33
|
+
# This is an EXPERIMENTAL API.
|
34
|
+
#
|
35
|
+
class ClientInterceptor < Interceptor
|
36
|
+
##
|
37
|
+
# Intercept a unary request response call
|
38
|
+
#
|
39
|
+
# @param [Object] request
|
40
|
+
# @param [GRPC::ActiveCall] call
|
41
|
+
# @param [String] method
|
42
|
+
# @param [Hash] metadata
|
43
|
+
#
|
44
|
+
def request_response(request: nil, call: nil, method: nil, metadata: nil)
|
45
|
+
GRPC.logger.debug "Intercepting request response method #{method}" \
|
46
|
+
" for request #{request} with call #{call} and metadata: #{metadata}"
|
47
|
+
yield
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Intercept a client streaming call
|
52
|
+
#
|
53
|
+
# @param [Enumerable] requests
|
54
|
+
# @param [GRPC::ActiveCall] call
|
55
|
+
# @param [String] method
|
56
|
+
# @param [Hash] metadata
|
57
|
+
#
|
58
|
+
def client_streamer(requests: nil, call: nil, method: nil, metadata: nil)
|
59
|
+
GRPC.logger.debug "Intercepting client streamer method #{method}" \
|
60
|
+
" for requests #{requests} with call #{call} and metadata: #{metadata}"
|
61
|
+
yield
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Intercept a server streaming call
|
66
|
+
#
|
67
|
+
# @param [Object] request
|
68
|
+
# @param [GRPC::ActiveCall] call
|
69
|
+
# @param [String] method
|
70
|
+
# @param [Hash] metadata
|
71
|
+
#
|
72
|
+
def server_streamer(request: nil, call: nil, method: nil, metadata: nil)
|
73
|
+
GRPC.logger.debug "Intercepting server streamer method #{method}" \
|
74
|
+
" for request #{request} with call #{call} and metadata: #{metadata}"
|
75
|
+
yield
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Intercept a BiDi streaming call
|
80
|
+
#
|
81
|
+
# @param [Enumerable] requests
|
82
|
+
# @param [GRPC::ActiveCall] call
|
83
|
+
# @param [String] method
|
84
|
+
# @param [Hash] metadata
|
85
|
+
#
|
86
|
+
def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil)
|
87
|
+
GRPC.logger.debug "Intercepting bidi streamer method #{method}" \
|
88
|
+
" for requests #{requests} with call #{call} and metadata: #{metadata}"
|
89
|
+
yield
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# ServerInterceptor allows for wrapping gRPC server execution handling.
|
95
|
+
# This is an EXPERIMENTAL API.
|
96
|
+
#
|
97
|
+
class ServerInterceptor < Interceptor
|
98
|
+
##
|
99
|
+
# Intercept a unary request response call.
|
100
|
+
#
|
101
|
+
# @param [Object] request
|
102
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
103
|
+
# @param [Method] method
|
104
|
+
#
|
105
|
+
def request_response(request: nil, call: nil, method: nil)
|
106
|
+
GRPC.logger.debug "Intercepting request response method #{method}" \
|
107
|
+
" for request #{request} with call #{call}"
|
108
|
+
yield
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Intercept a client streaming call
|
113
|
+
#
|
114
|
+
# @param [GRPC::ActiveCall::MultiReqView] call
|
115
|
+
# @param [Method] method
|
116
|
+
#
|
117
|
+
def client_streamer(call: nil, method: nil)
|
118
|
+
GRPC.logger.debug "Intercepting client streamer method #{method}" \
|
119
|
+
" with call #{call}"
|
120
|
+
yield
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Intercept a server streaming call
|
125
|
+
#
|
126
|
+
# @param [Object] request
|
127
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
128
|
+
# @param [Method] method
|
129
|
+
#
|
130
|
+
def server_streamer(request: nil, call: nil, method: nil)
|
131
|
+
GRPC.logger.debug "Intercepting server streamer method #{method}" \
|
132
|
+
" for request #{request} with call #{call}"
|
133
|
+
yield
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Intercept a BiDi streaming call
|
138
|
+
#
|
139
|
+
# @param [Enumerable<Object>] requests
|
140
|
+
# @param [GRPC::ActiveCall::MultiReqView] call
|
141
|
+
# @param [Method] method
|
142
|
+
#
|
143
|
+
def bidi_streamer(requests: nil, call: nil, method: nil)
|
144
|
+
GRPC.logger.debug "Intercepting bidi streamer method #{method}" \
|
145
|
+
" for requests #{requests} with call #{call}"
|
146
|
+
yield
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Represents the context in which an interceptor runs. Used to provide an
|
152
|
+
# injectable mechanism for handling interception. This is an EXPERIMENTAL API.
|
153
|
+
#
|
154
|
+
class InterceptionContext
|
155
|
+
##
|
156
|
+
# @param interceptors [Array<GRPC::Interceptor>]
|
157
|
+
#
|
158
|
+
def initialize(interceptors = [])
|
159
|
+
@interceptors = interceptors.dup
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Intercept the call and fire out to interceptors in a FIFO execution.
|
164
|
+
# This is an EXPERIMENTAL API.
|
165
|
+
#
|
166
|
+
# @param [Symbol] type The request type
|
167
|
+
# @param [Hash] args The arguments for the call
|
168
|
+
#
|
169
|
+
def intercept!(type, args = {})
|
170
|
+
return yield if @interceptors.none?
|
171
|
+
|
172
|
+
i = @interceptors.pop
|
173
|
+
return yield unless i
|
174
|
+
|
175
|
+
i.send(type, **args) do
|
176
|
+
if @interceptors.any?
|
177
|
+
intercept!(type, args) do
|
178
|
+
yield
|
179
|
+
end
|
180
|
+
else
|
181
|
+
yield
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative '../grpc'
|
16
|
+
|
17
|
+
# GRPC contains the General RPC module.
|
18
|
+
module GRPC
|
19
|
+
# RpcDesc is a Descriptor of an RPC method.
|
20
|
+
class RpcDesc < Struct.new(:name, :input, :output, :marshal_method,
|
21
|
+
:unmarshal_method)
|
22
|
+
include Core::StatusCodes
|
23
|
+
|
24
|
+
# Used to wrap a message class to indicate that it needs to be streamed.
|
25
|
+
class Stream
|
26
|
+
attr_accessor :type
|
27
|
+
|
28
|
+
def initialize(type)
|
29
|
+
@type = type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Proc] { |instance| marshalled(instance) }
|
34
|
+
def marshal_proc
|
35
|
+
proc { |o| o.class.send(marshal_method, o).to_s }
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [:input, :output] target determines whether to produce the an
|
39
|
+
# unmarshal Proc for the rpc input parameter or
|
40
|
+
# its output parameter
|
41
|
+
#
|
42
|
+
# @return [Proc] An unmarshal proc { |marshalled(instance)| instance }
|
43
|
+
def unmarshal_proc(target)
|
44
|
+
fail ArgumentError unless [:input, :output].include?(target)
|
45
|
+
unmarshal_class = send(target)
|
46
|
+
unmarshal_class = unmarshal_class.type if unmarshal_class.is_a? Stream
|
47
|
+
proc { |o| unmarshal_class.send(unmarshal_method, o) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def handle_request_response(active_call, mth, inter_ctx)
|
51
|
+
req = active_call.read_unary_request
|
52
|
+
call = active_call.single_req_view
|
53
|
+
|
54
|
+
inter_ctx.intercept!(
|
55
|
+
:request_response,
|
56
|
+
method: mth,
|
57
|
+
call: call,
|
58
|
+
request: req
|
59
|
+
) do
|
60
|
+
resp = mth.call(req, call)
|
61
|
+
active_call.server_unary_response(
|
62
|
+
resp,
|
63
|
+
trailing_metadata: active_call.output_metadata
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def handle_client_streamer(active_call, mth, inter_ctx)
|
69
|
+
call = active_call.multi_req_view
|
70
|
+
|
71
|
+
inter_ctx.intercept!(
|
72
|
+
:client_streamer,
|
73
|
+
method: mth,
|
74
|
+
call: call
|
75
|
+
) do
|
76
|
+
resp = mth.call(call)
|
77
|
+
active_call.server_unary_response(
|
78
|
+
resp,
|
79
|
+
trailing_metadata: active_call.output_metadata
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_server_streamer(active_call, mth, inter_ctx)
|
85
|
+
req = active_call.read_unary_request
|
86
|
+
call = active_call.single_req_view
|
87
|
+
|
88
|
+
inter_ctx.intercept!(
|
89
|
+
:server_streamer,
|
90
|
+
method: mth,
|
91
|
+
call: call,
|
92
|
+
request: req
|
93
|
+
) do
|
94
|
+
replies = mth.call(req, call)
|
95
|
+
replies.each { |r| active_call.remote_send(r) }
|
96
|
+
send_status(active_call, OK, 'OK', active_call.output_metadata)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# @param [GRPC::ActiveCall] active_call
|
102
|
+
# @param [Method] mth
|
103
|
+
# @param [Array<GRPC::InterceptionContext>] inter_ctx
|
104
|
+
#
|
105
|
+
def handle_bidi_streamer(active_call, mth, inter_ctx)
|
106
|
+
active_call.run_server_bidi(mth, inter_ctx)
|
107
|
+
send_status(active_call, OK, 'OK', active_call.output_metadata)
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# @param [GRPC::ActiveCall] active_call The current active call object
|
112
|
+
# for the request
|
113
|
+
# @param [Method] mth The current RPC method being called
|
114
|
+
# @param [GRPC::InterceptionContext] inter_ctx The interception context
|
115
|
+
# being executed
|
116
|
+
#
|
117
|
+
def run_server_method(active_call, mth, inter_ctx = InterceptionContext.new)
|
118
|
+
# While a server method is running, it might be cancelled, its deadline
|
119
|
+
# might be reached, the handler could throw an unknown error, or a
|
120
|
+
# well-behaved handler could throw a StatusError.
|
121
|
+
if request_response?
|
122
|
+
handle_request_response(active_call, mth, inter_ctx)
|
123
|
+
elsif client_streamer?
|
124
|
+
handle_client_streamer(active_call, mth, inter_ctx)
|
125
|
+
elsif server_streamer?
|
126
|
+
handle_server_streamer(active_call, mth, inter_ctx)
|
127
|
+
else # is a bidi_stream
|
128
|
+
handle_bidi_streamer(active_call, mth, inter_ctx)
|
129
|
+
end
|
130
|
+
rescue BadStatus => e
|
131
|
+
# this is raised by handlers that want GRPC to send an application error
|
132
|
+
# code and detail message and some additional app-specific metadata.
|
133
|
+
GRPC.logger.debug("app err:#{active_call}, status:#{e.code}:#{e.details}")
|
134
|
+
send_status(active_call, e.code, e.details, e.metadata)
|
135
|
+
rescue Core::CallError => e
|
136
|
+
# This is raised by GRPC internals but should rarely, if ever happen.
|
137
|
+
# Log it, but don't notify the other endpoint..
|
138
|
+
GRPC.logger.warn("failed call: #{active_call}\n#{e}")
|
139
|
+
rescue Core::OutOfTime
|
140
|
+
# This is raised when active_call#method.call exceeds the deadline
|
141
|
+
# event. Send a status of deadline exceeded
|
142
|
+
GRPC.logger.warn("late call: #{active_call}")
|
143
|
+
send_status(active_call, DEADLINE_EXCEEDED, 'late')
|
144
|
+
rescue StandardError, NotImplementedError => e
|
145
|
+
# This will usuaally be an unhandled error in the handling code.
|
146
|
+
# Send back a UNKNOWN status to the client
|
147
|
+
#
|
148
|
+
# Note: this intentionally does not map NotImplementedError to
|
149
|
+
# UNIMPLEMENTED because NotImplementedError is intended for low-level
|
150
|
+
# OS interaction (e.g. syscalls) not supported by the current OS.
|
151
|
+
GRPC.logger.warn("failed handler: #{active_call}; sending status:UNKNOWN")
|
152
|
+
GRPC.logger.warn(e)
|
153
|
+
send_status(active_call, UNKNOWN, "#{e.class}: #{e.message}")
|
154
|
+
end
|
155
|
+
|
156
|
+
def assert_arity_matches(mth)
|
157
|
+
# A bidi handler function can optionally be passed a second
|
158
|
+
# call object parameter for access to metadata, cancelling, etc.
|
159
|
+
if bidi_streamer?
|
160
|
+
if mth.arity != 2 && mth.arity != 1
|
161
|
+
fail arity_error(mth, 2, "should be #{mth.name}(req, call) or " \
|
162
|
+
"#{mth.name}(req)")
|
163
|
+
end
|
164
|
+
elsif request_response? || server_streamer?
|
165
|
+
if mth.arity != 2
|
166
|
+
fail arity_error(mth, 2, "should be #{mth.name}(req, call)")
|
167
|
+
end
|
168
|
+
else
|
169
|
+
if mth.arity != 1
|
170
|
+
fail arity_error(mth, 1, "should be #{mth.name}(call)")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def request_response?
|
176
|
+
!input.is_a?(Stream) && !output.is_a?(Stream)
|
177
|
+
end
|
178
|
+
|
179
|
+
def client_streamer?
|
180
|
+
input.is_a?(Stream) && !output.is_a?(Stream)
|
181
|
+
end
|
182
|
+
|
183
|
+
def server_streamer?
|
184
|
+
!input.is_a?(Stream) && output.is_a?(Stream)
|
185
|
+
end
|
186
|
+
|
187
|
+
def bidi_streamer?
|
188
|
+
input.is_a?(Stream) && output.is_a?(Stream)
|
189
|
+
end
|
190
|
+
|
191
|
+
def arity_error(mth, want, msg)
|
192
|
+
"##{mth.name}: bad arg count; got:#{mth.arity}, want:#{want}, #{msg}"
|
193
|
+
end
|
194
|
+
|
195
|
+
def send_status(active_client, code, details, metadata = {})
|
196
|
+
details = 'Not sure why' if details.nil?
|
197
|
+
GRPC.logger.debug("Sending status #{code}:#{details}")
|
198
|
+
active_client.send_status(code, details, code == OK, metadata: metadata)
|
199
|
+
rescue StandardError => e
|
200
|
+
GRPC.logger.warn("Could not send status #{code}:#{details}")
|
201
|
+
GRPC.logger.warn(e)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|