grpc 0.14.1-x86-mingw32 → 0.15.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/math_services.rb +41 -2
- data/src/ruby/ext/grpc/rb_call.c +42 -40
- data/src/ruby/ext/grpc/rb_channel.c +1 -1
- data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
- data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -3
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
- data/src/ruby/ext/grpc/rb_loader.c +1 -1
- data/src/ruby/ext/grpc/rb_server.c +5 -3
- data/src/ruby/lib/grpc.rb +0 -3
- data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/errors.rb +3 -2
- data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
- data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
- data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
- data/src/ruby/lib/grpc/generic/service.rb +8 -8
- data/src/ruby/lib/grpc/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
- data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
- data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
- data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
- data/src/ruby/pb/test/client.rb +5 -2
- data/src/ruby/spec/generic/active_call_spec.rb +3 -2
- data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
- data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
- data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
- data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
- metadata +6 -5
- data/src/ruby/ext/grpc/rb_signal.c +0 -70
- data/src/ruby/ext/grpc/rb_signal.h +0 -39
- data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -36,13 +36,14 @@
|
|
36
36
|
|
37
37
|
#include <grpc/support/port_platform.h>
|
38
38
|
|
39
|
-
#ifdef
|
39
|
+
#ifdef GPR_WINDOWS
|
40
40
|
|
41
41
|
#include <windows.h>
|
42
42
|
|
43
43
|
#include <grpc/census.h>
|
44
44
|
#include <grpc/compression.h>
|
45
45
|
#include <grpc/grpc.h>
|
46
|
+
#include <grpc/grpc_posix.h>
|
46
47
|
#include <grpc/grpc_security.h>
|
47
48
|
#include <grpc/impl/codegen/alloc.h>
|
48
49
|
#include <grpc/impl/codegen/byte_buffer.h>
|
@@ -56,7 +57,7 @@
|
|
56
57
|
#include <grpc/support/cpu.h>
|
57
58
|
#include <grpc/support/histogram.h>
|
58
59
|
#include <grpc/support/host_port.h>
|
59
|
-
#include <grpc/support/
|
60
|
+
#include <grpc/support/log_windows.h>
|
60
61
|
#include <grpc/support/string_util.h>
|
61
62
|
#include <grpc/support/subprocess.h>
|
62
63
|
#include <grpc/support/thd.h>
|
@@ -295,6 +296,9 @@ extern grpc_server_create_type grpc_server_create_import;
|
|
295
296
|
typedef void(*grpc_server_register_completion_queue_type)(grpc_server *server, grpc_completion_queue *cq, void *reserved);
|
296
297
|
extern grpc_server_register_completion_queue_type grpc_server_register_completion_queue_import;
|
297
298
|
#define grpc_server_register_completion_queue grpc_server_register_completion_queue_import
|
299
|
+
typedef void(*grpc_server_register_non_listening_completion_queue_type)(grpc_server *server, grpc_completion_queue *q, void *reserved);
|
300
|
+
extern grpc_server_register_non_listening_completion_queue_type grpc_server_register_non_listening_completion_queue_import;
|
301
|
+
#define grpc_server_register_non_listening_completion_queue grpc_server_register_non_listening_completion_queue_import
|
298
302
|
typedef int(*grpc_server_add_insecure_http2_port_type)(grpc_server *server, const char *addr);
|
299
303
|
extern grpc_server_add_insecure_http2_port_type grpc_server_add_insecure_http2_port_import;
|
300
304
|
#define grpc_server_add_insecure_http2_port grpc_server_add_insecure_http2_port_import
|
@@ -325,6 +329,12 @@ extern grpc_is_binary_header_type grpc_is_binary_header_import;
|
|
325
329
|
typedef const char *(*grpc_call_error_to_string_type)(grpc_call_error error);
|
326
330
|
extern grpc_call_error_to_string_type grpc_call_error_to_string_import;
|
327
331
|
#define grpc_call_error_to_string grpc_call_error_to_string_import
|
332
|
+
typedef grpc_channel *(*grpc_insecure_channel_create_from_fd_type)(const char *target, int fd, const grpc_channel_args *args);
|
333
|
+
extern grpc_insecure_channel_create_from_fd_type grpc_insecure_channel_create_from_fd_import;
|
334
|
+
#define grpc_insecure_channel_create_from_fd grpc_insecure_channel_create_from_fd_import
|
335
|
+
typedef void(*grpc_server_add_insecure_channel_from_fd_type)(grpc_server *server, grpc_completion_queue *cq, int fd);
|
336
|
+
extern grpc_server_add_insecure_channel_from_fd_type grpc_server_add_insecure_channel_from_fd_import;
|
337
|
+
#define grpc_server_add_insecure_channel_from_fd grpc_server_add_insecure_channel_from_fd_import
|
328
338
|
typedef const grpc_auth_property *(*grpc_auth_property_iterator_next_type)(grpc_auth_property_iterator *it);
|
329
339
|
extern grpc_auth_property_iterator_next_type grpc_auth_property_iterator_next_import;
|
330
340
|
#define grpc_auth_property_iterator_next grpc_auth_property_iterator_next_import
|
@@ -472,7 +482,7 @@ extern grpc_byte_buffer_reader_readall_type grpc_byte_buffer_reader_readall_impo
|
|
472
482
|
typedef grpc_byte_buffer *(*grpc_raw_byte_buffer_from_reader_type)(grpc_byte_buffer_reader *reader);
|
473
483
|
extern grpc_raw_byte_buffer_from_reader_type grpc_raw_byte_buffer_from_reader_import;
|
474
484
|
#define grpc_raw_byte_buffer_from_reader grpc_raw_byte_buffer_from_reader_import
|
475
|
-
typedef void(*gpr_log_type)(const char *file, int line, gpr_log_severity severity, const char *format, ...);
|
485
|
+
typedef void(*gpr_log_type)(const char *file, int line, gpr_log_severity severity, const char *format, ...) GPRC_PRINT_FORMAT_CHECK(4, 5);
|
476
486
|
extern gpr_log_type gpr_log_import;
|
477
487
|
#define gpr_log gpr_log_import
|
478
488
|
typedef void(*gpr_log_message_type)(const char *file, int line, gpr_log_severity severity, const char *message);
|
@@ -721,6 +731,12 @@ extern gpr_avl_remove_type gpr_avl_remove_import;
|
|
721
731
|
typedef void *(*gpr_avl_get_type)(gpr_avl avl, void *key);
|
722
732
|
extern gpr_avl_get_type gpr_avl_get_import;
|
723
733
|
#define gpr_avl_get gpr_avl_get_import
|
734
|
+
typedef int(*gpr_avl_maybe_get_type)(gpr_avl avl, void *key, void **value);
|
735
|
+
extern gpr_avl_maybe_get_type gpr_avl_maybe_get_import;
|
736
|
+
#define gpr_avl_maybe_get gpr_avl_maybe_get_import
|
737
|
+
typedef int(*gpr_avl_is_empty_type)(gpr_avl avl);
|
738
|
+
extern gpr_avl_is_empty_type gpr_avl_is_empty_import;
|
739
|
+
#define gpr_avl_is_empty gpr_avl_is_empty_import
|
724
740
|
typedef gpr_cmdline *(*gpr_cmdline_create_type)(const char *description);
|
725
741
|
extern gpr_cmdline_create_type gpr_cmdline_create_import;
|
726
742
|
#define gpr_cmdline_create gpr_cmdline_create_import
|
@@ -811,7 +827,7 @@ extern gpr_format_message_type gpr_format_message_import;
|
|
811
827
|
typedef char *(*gpr_strdup_type)(const char *src);
|
812
828
|
extern gpr_strdup_type gpr_strdup_import;
|
813
829
|
#define gpr_strdup gpr_strdup_import
|
814
|
-
typedef int(*gpr_asprintf_type)(char **strp, const char *format, ...);
|
830
|
+
typedef int(*gpr_asprintf_type)(char **strp, const char *format, ...) GPRC_PRINT_FORMAT_CHECK(2, 3);
|
815
831
|
extern gpr_asprintf_type gpr_asprintf_import;
|
816
832
|
#define gpr_asprintf gpr_asprintf_import
|
817
833
|
typedef const char *(*gpr_subprocess_binary_extension_type)();
|
@@ -856,6 +872,6 @@ extern gpr_thd_join_type gpr_thd_join_import;
|
|
856
872
|
|
857
873
|
void grpc_rb_load_imports(HMODULE library);
|
858
874
|
|
859
|
-
#endif /*
|
875
|
+
#endif /* GPR_WINDOWS */
|
860
876
|
|
861
877
|
#endif
|
@@ -60,6 +60,7 @@ typedef struct grpc_rb_server {
|
|
60
60
|
VALUE mark;
|
61
61
|
/* The actual server */
|
62
62
|
grpc_server *wrapped;
|
63
|
+
grpc_completion_queue *queue;
|
63
64
|
} grpc_rb_server;
|
64
65
|
|
65
66
|
/* Destroys server instances. */
|
@@ -145,6 +146,7 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
|
|
145
146
|
}
|
146
147
|
grpc_server_register_completion_queue(srv, cq, NULL);
|
147
148
|
wrapper->wrapped = srv;
|
149
|
+
wrapper->queue = cq;
|
148
150
|
|
149
151
|
/* Add the cq as the server's mark object. This ensures the ruby cq can't be
|
150
152
|
GCed before the server */
|
@@ -232,7 +234,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
|
|
232
234
|
err = grpc_server_request_call(
|
233
235
|
s->wrapped, &call, &st.details, &st.md_ary,
|
234
236
|
grpc_rb_get_wrapped_completion_queue(cqueue),
|
235
|
-
grpc_rb_get_wrapped_completion_queue(
|
237
|
+
grpc_rb_get_wrapped_completion_queue(s->mark),
|
236
238
|
ROBJECT(tag_new));
|
237
239
|
if (err != GRPC_CALL_OK) {
|
238
240
|
grpc_request_call_stack_cleanup(&st);
|
@@ -242,7 +244,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
|
|
242
244
|
return Qnil;
|
243
245
|
}
|
244
246
|
|
245
|
-
ev = grpc_rb_completion_queue_pluck_event(
|
247
|
+
ev = grpc_rb_completion_queue_pluck_event(s->mark, tag_new, timeout);
|
246
248
|
if (ev.type == GRPC_QUEUE_TIMEOUT) {
|
247
249
|
grpc_request_call_stack_cleanup(&st);
|
248
250
|
return Qnil;
|
@@ -260,7 +262,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
|
|
260
262
|
rb_str_new2(st.details.host),
|
261
263
|
rb_funcall(rb_cTime, id_at, 2, INT2NUM(deadline.tv_sec),
|
262
264
|
INT2NUM(deadline.tv_nsec)),
|
263
|
-
grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call), NULL);
|
265
|
+
grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call), cqueue, NULL);
|
264
266
|
grpc_request_call_stack_cleanup(&st);
|
265
267
|
return result;
|
266
268
|
}
|
data/src/ruby/lib/grpc.rb
CHANGED
@@ -33,7 +33,6 @@ require_relative 'grpc/errors'
|
|
33
33
|
require_relative 'grpc/grpc'
|
34
34
|
require_relative 'grpc/logconfig'
|
35
35
|
require_relative 'grpc/notifier'
|
36
|
-
require_relative 'grpc/signals'
|
37
36
|
require_relative 'grpc/version'
|
38
37
|
require_relative 'grpc/core/time_consts'
|
39
38
|
require_relative 'grpc/generic/active_call'
|
@@ -48,5 +47,3 @@ begin
|
|
48
47
|
ensure
|
49
48
|
file.close
|
50
49
|
end
|
51
|
-
|
52
|
-
GRPC::Signals.wait_for_signals
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/src/ruby/lib/grpc/errors.rb
CHANGED
@@ -40,11 +40,12 @@ module GRPC
|
|
40
40
|
|
41
41
|
# @param code [Numeric] the status code
|
42
42
|
# @param details [String] the details of the exception
|
43
|
-
|
43
|
+
# @param metadata [Hash] the error's metadata
|
44
|
+
def initialize(code, details = 'unknown cause', metadata = {})
|
44
45
|
super("#{code}:#{details}")
|
45
46
|
@code = code
|
46
47
|
@details = details
|
47
|
-
@metadata =
|
48
|
+
@metadata = metadata
|
48
49
|
end
|
49
50
|
|
50
51
|
# Converts the exception to a GRPC::Status for use in the networking
|
@@ -30,7 +30,6 @@
|
|
30
30
|
require 'forwardable'
|
31
31
|
require 'weakref'
|
32
32
|
require_relative 'bidi_call'
|
33
|
-
require_relative '../signals'
|
34
33
|
|
35
34
|
class Struct
|
36
35
|
# BatchResult is the struct returned by calls to call#start_batch.
|
@@ -45,7 +44,7 @@ class Struct
|
|
45
44
|
# raise BadStatus, propagating the metadata if present.
|
46
45
|
md = status.metadata
|
47
46
|
with_sym_keys = Hash[md.each_pair.collect { |x, y| [x.to_sym, y] }]
|
48
|
-
fail GRPC::BadStatus.new(status.code, status.details,
|
47
|
+
fail GRPC::BadStatus.new(status.code, status.details, with_sym_keys)
|
49
48
|
end
|
50
49
|
status
|
51
50
|
end
|
@@ -77,14 +76,15 @@ module GRPC
|
|
77
76
|
#
|
78
77
|
# @param call [Call] a call on which to start and invocation
|
79
78
|
# @param q [CompletionQueue] the completion queue
|
80
|
-
|
79
|
+
# @param metadata [Hash] the metadata
|
80
|
+
def self.client_invoke(call, q, metadata = {})
|
81
81
|
fail(TypeError, '!Core::Call') unless call.is_a? Core::Call
|
82
82
|
unless q.is_a? Core::CompletionQueue
|
83
83
|
fail(TypeError, '!Core::CompletionQueue')
|
84
84
|
end
|
85
85
|
metadata_tag = Object.new
|
86
86
|
call.run_batch(q, metadata_tag, INFINITE_FUTURE,
|
87
|
-
SEND_INITIAL_METADATA =>
|
87
|
+
SEND_INITIAL_METADATA => metadata)
|
88
88
|
metadata_tag
|
89
89
|
end
|
90
90
|
|
@@ -103,7 +103,7 @@ module GRPC
|
|
103
103
|
#
|
104
104
|
# @param call [Call] the call used by the ActiveCall
|
105
105
|
# @param q [CompletionQueue] the completion queue used to accept
|
106
|
-
# the call
|
106
|
+
# the call. This queue will be closed on call completion.
|
107
107
|
# @param marshal [Function] f(obj)->string that marshal requests
|
108
108
|
# @param unmarshal [Function] f(string)->obj that unmarshals responses
|
109
109
|
# @param deadline [Fixnum] the deadline for the call to complete
|
@@ -123,10 +123,6 @@ module GRPC
|
|
123
123
|
@unmarshal = unmarshal
|
124
124
|
@metadata_tag = metadata_tag
|
125
125
|
@op_notifier = nil
|
126
|
-
weak_self = WeakRef.new(self)
|
127
|
-
remove_handler = GRPC::Signals.register_handler(&weak_self
|
128
|
-
.method(:cancel))
|
129
|
-
ObjectSpace.define_finalizer(self, remove_handler)
|
130
126
|
end
|
131
127
|
|
132
128
|
# output_metadata are provides access to hash that can be used to
|
@@ -195,6 +191,8 @@ module GRPC
|
|
195
191
|
@call.status = batch_result.status
|
196
192
|
op_is_done
|
197
193
|
batch_result.check_status
|
194
|
+
@call.close
|
195
|
+
@cq.close
|
198
196
|
end
|
199
197
|
|
200
198
|
# remote_send sends a request to the remote endpoint.
|
@@ -216,13 +214,12 @@ module GRPC
|
|
216
214
|
# @param details [String] details
|
217
215
|
# @param assert_finished [true, false] when true(default), waits for
|
218
216
|
# FINISHED.
|
219
|
-
#
|
220
|
-
#
|
221
|
-
|
222
|
-
|
223
|
-
def send_status(code = OK, details = '', assert_finished = false, **kw)
|
217
|
+
# @param metadata [Hash] metadata to send to the server. If a value is a
|
218
|
+
# list, mulitple metadata for its key are sent
|
219
|
+
def send_status(code = OK, details = '', assert_finished = false,
|
220
|
+
metadata: {})
|
224
221
|
ops = {
|
225
|
-
SEND_STATUS_FROM_SERVER => Struct::Status.new(code, details,
|
222
|
+
SEND_STATUS_FROM_SERVER => Struct::Status.new(code, details, metadata)
|
226
223
|
}
|
227
224
|
ops[RECV_CLOSE_ON_SERVER] = nil if assert_finished
|
228
225
|
@call.run_batch(@cq, self, INFINITE_FUTURE, ops)
|
@@ -316,14 +313,12 @@ module GRPC
|
|
316
313
|
# request_response sends a request to a GRPC server, and returns the
|
317
314
|
# response.
|
318
315
|
#
|
319
|
-
# == Keyword Arguments ==
|
320
|
-
# any keyword arguments are treated as metadata to be sent to the server
|
321
|
-
# if a keyword value is a list, multiple metadata for it's key are sent
|
322
|
-
#
|
323
316
|
# @param req [Object] the request sent to the server
|
317
|
+
# @param metadata [Hash] metadata to be sent to the server. If a value is
|
318
|
+
# a list, multiple metadata for its key are sent
|
324
319
|
# @return [Object] the response received from the server
|
325
|
-
def request_response(req,
|
326
|
-
start_call(
|
320
|
+
def request_response(req, metadata: {})
|
321
|
+
start_call(metadata) unless @started
|
327
322
|
remote_send(req)
|
328
323
|
writes_done(false)
|
329
324
|
response = remote_read
|
@@ -342,14 +337,12 @@ module GRPC
|
|
342
337
|
# array of marshallable objects; in typical case it will be an Enumerable
|
343
338
|
# that allows dynamic construction of the marshallable objects.
|
344
339
|
#
|
345
|
-
# == Keyword Arguments ==
|
346
|
-
# any keyword arguments are treated as metadata to be sent to the server
|
347
|
-
# if a keyword value is a list, multiple metadata for it's key are sent
|
348
|
-
#
|
349
340
|
# @param requests [Object] an Enumerable of requests to send
|
341
|
+
# @param metadata [Hash] metadata to be sent to the server. If a value is
|
342
|
+
# a list, multiple metadata for its key are sent
|
350
343
|
# @return [Object] the response received from the server
|
351
|
-
def client_streamer(requests,
|
352
|
-
start_call(
|
344
|
+
def client_streamer(requests, metadata: {})
|
345
|
+
start_call(metadata) unless @started
|
353
346
|
requests.each { |r| remote_send(r) }
|
354
347
|
writes_done(false)
|
355
348
|
response = remote_read
|
@@ -370,15 +363,12 @@ module GRPC
|
|
370
363
|
# it is executed with each response as the argument and no result is
|
371
364
|
# returned.
|
372
365
|
#
|
373
|
-
# == Keyword Arguments ==
|
374
|
-
# any keyword arguments are treated as metadata to be sent to the server
|
375
|
-
# if a keyword value is a list, multiple metadata for it's key are sent
|
376
|
-
# any keyword arguments are treated as metadata to be sent to the server.
|
377
|
-
#
|
378
366
|
# @param req [Object] the request sent to the server
|
367
|
+
# @param metadata [Hash] metadata to be sent to the server. If a value is
|
368
|
+
# a list, multiple metadata for its key are sent
|
379
369
|
# @return [Enumerator|nil] a response Enumerator
|
380
|
-
def server_streamer(req,
|
381
|
-
start_call(
|
370
|
+
def server_streamer(req, metadata: {})
|
371
|
+
start_call(metadata) unless @started
|
382
372
|
remote_send(req)
|
383
373
|
writes_done(false)
|
384
374
|
replies = enum_for(:each_remote_read_then_finish)
|
@@ -412,14 +402,12 @@ module GRPC
|
|
412
402
|
# the_call#writes_done has been called, otherwise the block will loop
|
413
403
|
# forever.
|
414
404
|
#
|
415
|
-
# == Keyword Arguments ==
|
416
|
-
# any keyword arguments are treated as metadata to be sent to the server
|
417
|
-
# if a keyword value is a list, multiple metadata for it's key are sent
|
418
|
-
#
|
419
405
|
# @param requests [Object] an Enumerable of requests to send
|
406
|
+
# @param metadata [Hash] metadata to be sent to the server. If a value is
|
407
|
+
# a list, multiple metadata for its key are sent
|
420
408
|
# @return [Enumerator, nil] a response Enumerator
|
421
|
-
def bidi_streamer(requests,
|
422
|
-
start_call(
|
409
|
+
def bidi_streamer(requests, metadata: {}, &blk)
|
410
|
+
start_call(metadata) unless @started
|
423
411
|
bd = BidiCall.new(@call, @cq, @marshal, @unmarshal,
|
424
412
|
metadata_tag: @metadata_tag)
|
425
413
|
@metadata_tag = nil # run_on_client ensures metadata is read
|
@@ -458,9 +446,11 @@ module GRPC
|
|
458
446
|
private
|
459
447
|
|
460
448
|
# Starts the call if not already started
|
461
|
-
|
449
|
+
# @param metadata [Hash] metadata to be sent to the server. If a value is
|
450
|
+
# a list, multiple metadata for its key are sent
|
451
|
+
def start_call(metadata = {})
|
462
452
|
return if @started
|
463
|
-
@metadata_tag = ActiveCall.client_invoke(@call, @cq,
|
453
|
+
@metadata_tag = ActiveCall.client_invoke(@call, @cq, metadata)
|
464
454
|
@started = true
|
465
455
|
end
|
466
456
|
|
@@ -69,6 +69,10 @@ module GRPC
|
|
69
69
|
@readq = Queue.new
|
70
70
|
@unmarshal = unmarshal
|
71
71
|
@metadata_tag = metadata_tag
|
72
|
+
@reads_complete = false
|
73
|
+
@writes_complete = false
|
74
|
+
@complete = false
|
75
|
+
@done_mutex = Mutex.new
|
72
76
|
end
|
73
77
|
|
74
78
|
# Begins orchestration of the Bidi stream for a client sending requests.
|
@@ -115,6 +119,16 @@ module GRPC
|
|
115
119
|
@op_notifier.notify(self)
|
116
120
|
end
|
117
121
|
|
122
|
+
# signals that a bidi operation is complete (read + write)
|
123
|
+
def finished
|
124
|
+
@done_mutex.synchronize do
|
125
|
+
return unless @reads_complete && @writes_complete && !@complete
|
126
|
+
@call.close
|
127
|
+
@cq.close
|
128
|
+
@complete = true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
118
132
|
# performs a read using @call.run_batch, ensures metadata is set up
|
119
133
|
def read_using_run_batch
|
120
134
|
ops = { RECV_MESSAGE => nil }
|
@@ -163,12 +177,16 @@ module GRPC
|
|
163
177
|
SEND_CLOSE_FROM_CLIENT => nil)
|
164
178
|
GRPC.logger.debug('bidi-write-loop: done')
|
165
179
|
notify_done
|
180
|
+
@writes_complete = true
|
181
|
+
finished
|
166
182
|
end
|
167
183
|
GRPC.logger.debug('bidi-write-loop: finished')
|
168
184
|
rescue StandardError => e
|
169
185
|
GRPC.logger.warn('bidi-write-loop: failed')
|
170
186
|
GRPC.logger.warn(e)
|
171
187
|
notify_done
|
188
|
+
@writes_complete = true
|
189
|
+
finished
|
172
190
|
raise e
|
173
191
|
end
|
174
192
|
|
@@ -212,6 +230,8 @@ module GRPC
|
|
212
230
|
@readq.push(e) # let each_queued_msg terminate with this error
|
213
231
|
end
|
214
232
|
GRPC.logger.debug('bidi-read-loop: finished')
|
233
|
+
@reads_complete = true
|
234
|
+
finished
|
215
235
|
end
|
216
236
|
end
|
217
237
|
end
|
@@ -44,21 +44,21 @@ module GRPC
|
|
44
44
|
|
45
45
|
# setup_channel is used by #initialize to constuct a channel from its
|
46
46
|
# arguments.
|
47
|
-
def self.setup_channel(alt_chan, host, creds,
|
47
|
+
def self.setup_channel(alt_chan, host, creds, channel_args = {})
|
48
48
|
unless alt_chan.nil?
|
49
49
|
fail(TypeError, '!Channel') unless alt_chan.is_a?(Core::Channel)
|
50
50
|
return alt_chan
|
51
51
|
end
|
52
|
-
if
|
53
|
-
|
52
|
+
if channel_args['grpc.primary_user_agent'].nil?
|
53
|
+
channel_args['grpc.primary_user_agent'] = ''
|
54
54
|
else
|
55
|
-
|
55
|
+
channel_args['grpc.primary_user_agent'] += ' '
|
56
56
|
end
|
57
|
-
|
57
|
+
channel_args['grpc.primary_user_agent'] += "grpc-ruby/#{VERSION}"
|
58
58
|
unless creds.is_a?(Core::ChannelCredentials) || creds.is_a?(Symbol)
|
59
59
|
fail(TypeError, '!ChannelCredentials or Symbol')
|
60
60
|
end
|
61
|
-
Core::Channel.new(host,
|
61
|
+
Core::Channel.new(host, channel_args, creds)
|
62
62
|
end
|
63
63
|
|
64
64
|
# Allows users of the stub to modify the propagate mask.
|
@@ -96,15 +96,16 @@ module GRPC
|
|
96
96
|
# :this_channel_is_insecure
|
97
97
|
# @param channel_override [Core::Channel] a pre-created channel
|
98
98
|
# @param timeout [Number] the default timeout to use in requests
|
99
|
-
# @param
|
99
|
+
# @param channel_args [Hash] the channel arguments
|
100
100
|
def initialize(host, q, creds,
|
101
101
|
channel_override: nil,
|
102
102
|
timeout: nil,
|
103
103
|
propagate_mask: nil,
|
104
|
-
|
104
|
+
channel_args: {})
|
105
105
|
fail(TypeError, '!CompletionQueue') unless q.is_a?(Core::CompletionQueue)
|
106
|
-
@ch = ClientStub.setup_channel(channel_override, host, creds,
|
107
|
-
|
106
|
+
@ch = ClientStub.setup_channel(channel_override, host, creds,
|
107
|
+
channel_args)
|
108
|
+
alt_host = channel_args[Core::Channel::SSL_TARGET]
|
108
109
|
@host = alt_host.nil? ? host : alt_host
|
109
110
|
@propagate_mask = propagate_mask
|
110
111
|
@timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout
|
@@ -135,42 +136,35 @@ module GRPC
|
|
135
136
|
# If return_op is true, the call returns an Operation, calling execute
|
136
137
|
# on the Operation returns the response.
|
137
138
|
#
|
138
|
-
# == Keyword Args ==
|
139
|
-
#
|
140
|
-
# Unspecified keyword arguments are treated as metadata to be sent to the
|
141
|
-
# server.
|
142
|
-
#
|
143
139
|
# @param method [String] the RPC method to call on the GRPC server
|
144
140
|
# @param req [Object] the request sent to the server
|
145
141
|
# @param marshal [Function] f(obj)->string that marshals requests
|
146
142
|
# @param unmarshal [Function] f(string)->obj that unmarshals responses
|
147
|
-
# @param timeout [Numeric] (optional) the max completion time in seconds
|
148
143
|
# @param deadline [Time] (optional) the time the request should complete
|
144
|
+
# @param return_op [true|false] return an Operation if true
|
149
145
|
# @param parent [Core::Call] a prior call whose reserved metadata
|
150
146
|
# will be propagated by this one.
|
151
147
|
# @param credentials [Core::CallCredentials] credentials to use when making
|
152
148
|
# the call
|
153
|
-
# @param
|
149
|
+
# @param metadata [Hash] metadata to be sent to the server
|
154
150
|
# @return [Object] the response received from the server
|
155
151
|
def request_response(method, req, marshal, unmarshal,
|
156
152
|
deadline: nil,
|
157
|
-
timeout: nil,
|
158
153
|
return_op: false,
|
159
154
|
parent: nil,
|
160
155
|
credentials: nil,
|
161
|
-
|
156
|
+
metadata: {})
|
162
157
|
c = new_active_call(method, marshal, unmarshal,
|
163
158
|
deadline: deadline,
|
164
|
-
timeout: timeout,
|
165
159
|
parent: parent,
|
166
160
|
credentials: credentials)
|
167
|
-
return c.request_response(req,
|
161
|
+
return c.request_response(req, metadata: metadata) unless return_op
|
168
162
|
|
169
163
|
# return the operation view of the active_call; define #execute as a
|
170
164
|
# new method for this instance that invokes #request_response.
|
171
165
|
op = c.operation
|
172
166
|
op.define_singleton_method(:execute) do
|
173
|
-
c.request_response(req,
|
167
|
+
c.request_response(req, metadata: metadata)
|
174
168
|
end
|
175
169
|
op
|
176
170
|
end
|
@@ -205,42 +199,35 @@ module GRPC
|
|
205
199
|
#
|
206
200
|
# If return_op is true, the call returns the response.
|
207
201
|
#
|
208
|
-
# == Keyword Args ==
|
209
|
-
#
|
210
|
-
# Unspecified keyword arguments are treated as metadata to be sent to the
|
211
|
-
# server.
|
212
|
-
#
|
213
202
|
# @param method [String] the RPC method to call on the GRPC server
|
214
203
|
# @param requests [Object] an Enumerable of requests to send
|
215
204
|
# @param marshal [Function] f(obj)->string that marshals requests
|
216
205
|
# @param unmarshal [Function] f(string)->obj that unmarshals responses
|
217
|
-
# @param timeout [Numeric] (optional) the max completion time in seconds
|
218
206
|
# @param deadline [Time] (optional) the time the request should complete
|
219
207
|
# @param return_op [true|false] return an Operation if true
|
220
208
|
# @param parent [Core::Call] a prior call whose reserved metadata
|
221
209
|
# will be propagated by this one.
|
222
210
|
# @param credentials [Core::CallCredentials] credentials to use when making
|
223
211
|
# the call
|
212
|
+
# @param metadata [Hash] metadata to be sent to the server
|
224
213
|
# @return [Object|Operation] the response received from the server
|
225
214
|
def client_streamer(method, requests, marshal, unmarshal,
|
226
215
|
deadline: nil,
|
227
|
-
timeout: nil,
|
228
216
|
return_op: false,
|
229
217
|
parent: nil,
|
230
218
|
credentials: nil,
|
231
|
-
|
219
|
+
metadata: {})
|
232
220
|
c = new_active_call(method, marshal, unmarshal,
|
233
221
|
deadline: deadline,
|
234
|
-
timeout: timeout,
|
235
222
|
parent: parent,
|
236
223
|
credentials: credentials)
|
237
|
-
return c.client_streamer(requests,
|
224
|
+
return c.client_streamer(requests, metadata: metadata) unless return_op
|
238
225
|
|
239
226
|
# return the operation view of the active_call; define #execute as a
|
240
227
|
# new method for this instance that invokes #client_streamer.
|
241
228
|
op = c.operation
|
242
229
|
op.define_singleton_method(:execute) do
|
243
|
-
c.client_streamer(requests,
|
230
|
+
c.client_streamer(requests, metadata: metadata)
|
244
231
|
end
|
245
232
|
op
|
246
233
|
end
|
@@ -292,35 +279,33 @@ module GRPC
|
|
292
279
|
# @param req [Object] the request sent to the server
|
293
280
|
# @param marshal [Function] f(obj)->string that marshals requests
|
294
281
|
# @param unmarshal [Function] f(string)->obj that unmarshals responses
|
295
|
-
# @param timeout [Numeric] (optional) the max completion time in seconds
|
296
282
|
# @param deadline [Time] (optional) the time the request should complete
|
297
283
|
# @param return_op [true|false]return an Operation if true
|
298
284
|
# @param parent [Core::Call] a prior call whose reserved metadata
|
299
285
|
# will be propagated by this one.
|
300
286
|
# @param credentials [Core::CallCredentials] credentials to use when making
|
301
287
|
# the call
|
288
|
+
# @param metadata [Hash] metadata to be sent to the server
|
302
289
|
# @param blk [Block] when provided, is executed for each response
|
303
290
|
# @return [Enumerator|Operation|nil] as discussed above
|
304
291
|
def server_streamer(method, req, marshal, unmarshal,
|
305
292
|
deadline: nil,
|
306
|
-
timeout: nil,
|
307
293
|
return_op: false,
|
308
294
|
parent: nil,
|
309
295
|
credentials: nil,
|
310
|
-
|
296
|
+
metadata: {},
|
311
297
|
&blk)
|
312
298
|
c = new_active_call(method, marshal, unmarshal,
|
313
299
|
deadline: deadline,
|
314
|
-
timeout: timeout,
|
315
300
|
parent: parent,
|
316
301
|
credentials: credentials)
|
317
|
-
return c.server_streamer(req,
|
302
|
+
return c.server_streamer(req, metadata: metadata, &blk) unless return_op
|
318
303
|
|
319
304
|
# return the operation view of the active_call; define #execute
|
320
305
|
# as a new method for this instance that invokes #server_streamer
|
321
306
|
op = c.operation
|
322
307
|
op.define_singleton_method(:execute) do
|
323
|
-
c.server_streamer(req,
|
308
|
+
c.server_streamer(req, metadata: metadata, &blk)
|
324
309
|
end
|
325
310
|
op
|
326
311
|
end
|
@@ -391,11 +376,6 @@ module GRPC
|
|
391
376
|
# * the deadline is exceeded
|
392
377
|
#
|
393
378
|
#
|
394
|
-
# == Keyword Args ==
|
395
|
-
#
|
396
|
-
# Unspecified keyword arguments are treated as metadata to be sent to the
|
397
|
-
# server.
|
398
|
-
#
|
399
379
|
# == Return Value ==
|
400
380
|
#
|
401
381
|
# if the return_op is false, the return value is an Enumerator of the
|
@@ -411,36 +391,35 @@ module GRPC
|
|
411
391
|
# @param requests [Object] an Enumerable of requests to send
|
412
392
|
# @param marshal [Function] f(obj)->string that marshals requests
|
413
393
|
# @param unmarshal [Function] f(string)->obj that unmarshals responses
|
414
|
-
# @param timeout [Numeric] (optional) the max completion time in seconds
|
415
394
|
# @param deadline [Time] (optional) the time the request should complete
|
416
395
|
# @param parent [Core::Call] a prior call whose reserved metadata
|
417
396
|
# will be propagated by this one.
|
418
397
|
# @param credentials [Core::CallCredentials] credentials to use when making
|
419
398
|
# the call
|
420
399
|
# @param return_op [true|false] return an Operation if true
|
400
|
+
# @param metadata [Hash] metadata to be sent to the server
|
421
401
|
# @param blk [Block] when provided, is executed for each response
|
422
402
|
# @return [Enumerator|nil|Operation] as discussed above
|
423
403
|
def bidi_streamer(method, requests, marshal, unmarshal,
|
424
404
|
deadline: nil,
|
425
|
-
timeout: nil,
|
426
405
|
return_op: false,
|
427
406
|
parent: nil,
|
428
407
|
credentials: nil,
|
429
|
-
|
408
|
+
metadata: {},
|
430
409
|
&blk)
|
431
410
|
c = new_active_call(method, marshal, unmarshal,
|
432
411
|
deadline: deadline,
|
433
|
-
timeout: timeout,
|
434
412
|
parent: parent,
|
435
413
|
credentials: credentials)
|
436
414
|
|
437
|
-
return c.bidi_streamer(requests,
|
415
|
+
return c.bidi_streamer(requests, metadata: metadata,
|
416
|
+
&blk) unless return_op
|
438
417
|
|
439
418
|
# return the operation view of the active_call; define #execute
|
440
419
|
# as a new method for this instance that invokes #bidi_streamer
|
441
420
|
op = c.operation
|
442
421
|
op.define_singleton_method(:execute) do
|
443
|
-
c.bidi_streamer(requests,
|
422
|
+
c.bidi_streamer(requests, metadata: metadata, &blk)
|
444
423
|
end
|
445
424
|
op
|
446
425
|
end
|
@@ -457,12 +436,10 @@ module GRPC
|
|
457
436
|
# @param timeout [TimeConst]
|
458
437
|
def new_active_call(method, marshal, unmarshal,
|
459
438
|
deadline: nil,
|
460
|
-
timeout: nil,
|
461
439
|
parent: nil,
|
462
440
|
credentials: nil)
|
463
|
-
|
464
|
-
|
465
|
-
end
|
441
|
+
|
442
|
+
deadline = from_relative_time(@timeout) if deadline.nil?
|
466
443
|
# Provide each new client call with its own completion queue
|
467
444
|
call_queue = Core::CompletionQueue.new
|
468
445
|
call = @ch.create_call(call_queue,
|