grpc 0.6.1 → 0.9.2

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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +3 -3
  3. data/README.md +41 -39
  4. data/bin/apis/pubsub_demo.rb +2 -2
  5. data/bin/interop/interop_client.rb +6 -4
  6. data/bin/interop/interop_server.rb +7 -4
  7. data/bin/math.proto +7 -7
  8. data/bin/math_client.rb +22 -22
  9. data/bin/math_server.rb +6 -6
  10. data/bin/noproto_client.rb +4 -4
  11. data/bin/noproto_server.rb +3 -3
  12. data/ext/grpc/extconf.rb +20 -5
  13. data/ext/grpc/rb_byte_buffer.c +5 -4
  14. data/ext/grpc/rb_byte_buffer.h +2 -1
  15. data/ext/grpc/rb_call.c +5 -6
  16. data/ext/grpc/rb_call.h +2 -1
  17. data/ext/grpc/rb_channel.c +1 -1
  18. data/ext/grpc/rb_channel.h +2 -1
  19. data/ext/grpc/rb_channel_args.c +2 -1
  20. data/ext/grpc/rb_channel_args.h +2 -1
  21. data/ext/grpc/rb_completion_queue.c +7 -49
  22. data/ext/grpc/rb_completion_queue.h +4 -3
  23. data/ext/grpc/rb_credentials.c +1 -1
  24. data/ext/grpc/rb_credentials.h +2 -1
  25. data/ext/grpc/rb_grpc.h +2 -1
  26. data/ext/grpc/rb_server.c +10 -11
  27. data/ext/grpc/rb_server.h +2 -1
  28. data/ext/grpc/rb_server_credentials.c +1 -1
  29. data/ext/grpc/rb_server_credentials.h +2 -1
  30. data/grpc.gemspec +1 -1
  31. data/lib/grpc/core/time_consts.rb +1 -1
  32. data/lib/grpc/generic/active_call.rb +13 -9
  33. data/lib/grpc/generic/bidi_call.rb +37 -41
  34. data/lib/grpc/generic/rpc_desc.rb +8 -7
  35. data/lib/grpc/generic/rpc_server.rb +55 -42
  36. data/lib/grpc/generic/service.rb +22 -24
  37. data/lib/grpc/logconfig.rb +4 -1
  38. data/lib/grpc/version.rb +1 -1
  39. data/spec/completion_queue_spec.rb +0 -32
  40. data/spec/generic/rpc_server_pool_spec.rb +2 -2
  41. data/spec/generic/rpc_server_spec.rb +34 -12
  42. data/spec/generic/service_spec.rb +9 -9
  43. metadata +4 -4
data/ext/grpc/extconf.rb CHANGED
@@ -34,13 +34,25 @@ INCLUDEDIR = RbConfig::CONFIG['includedir']
34
34
 
35
35
  if ENV.key? 'GRPC_ROOT'
36
36
  GRPC_ROOT = ENV['GRPC_ROOT']
37
- if ENV.key? 'GRPC_LIB_DIR'
38
- GRPC_LIB_DIR = ENV['GRPC_LIB_DIR']
37
+ else
38
+ grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
39
+ if File.exist?(File.join(grpc_root, 'include/grpc/grpc.h'))
40
+ GRPC_ROOT = grpc_root
39
41
  else
40
- GRPC_LIB_DIR = 'libs/opt'
42
+ GRPC_ROOT = nil
41
43
  end
44
+ end
45
+
46
+ if ENV.key? 'CONFIG'
47
+ GRPC_CONFIG = ENV['CONFIG']
42
48
  else
43
- GRPC_ROOT = nil
49
+ GRPC_CONFIG = 'opt'
50
+ end
51
+
52
+ if (ENV.key? 'GRPC_LIB_DIR') && (!GRPC_ROOT.nil?)
53
+ GRPC_LIB_DIR = File.join(GRPC_ROOT, ENV['GRPC_LIB_DIR'])
54
+ else
55
+ GRPC_LIB_DIR = File.join(File.join(GRPC_ROOT, 'libs'), GRPC_CONFIG)
44
56
  end
45
57
 
46
58
  HEADER_DIRS = [
@@ -67,7 +79,10 @@ LIB_DIRS = [
67
79
 
68
80
  unless GRPC_ROOT.nil?
69
81
  HEADER_DIRS.unshift File.join(GRPC_ROOT, 'include')
70
- LIB_DIRS.unshift File.join(GRPC_ROOT, GRPC_LIB_DIR)
82
+ LIB_DIRS.unshift GRPC_LIB_DIR
83
+ unless File.exist?(File.join(GRPC_LIB_DIR, 'libgrpc.a'))
84
+ system("make -C #{GRPC_ROOT} static_c CONFIG=#{GRPC_CONFIG}")
85
+ end
71
86
  end
72
87
 
73
88
  def crash(msg)
@@ -33,9 +33,10 @@
33
33
 
34
34
  #include "rb_byte_buffer.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
+ #include <grpc/byte_buffer_reader.h>
39
40
  #include <grpc/support/slice.h>
40
41
  #include "rb_grpc.h"
41
42
 
@@ -50,7 +51,7 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) {
50
51
  size_t length = 0;
51
52
  char *string = NULL;
52
53
  size_t offset = 0;
53
- grpc_byte_buffer_reader *reader = NULL;
54
+ grpc_byte_buffer_reader reader;
54
55
  gpr_slice next;
55
56
  if (buffer == NULL) {
56
57
  return Qnil;
@@ -58,8 +59,8 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) {
58
59
  }
59
60
  length = grpc_byte_buffer_length(buffer);
60
61
  string = xmalloc(length + 1);
61
- reader = grpc_byte_buffer_reader_create(buffer);
62
- while (grpc_byte_buffer_reader_next(reader, &next) != 0) {
62
+ grpc_byte_buffer_reader_init(&reader, buffer);
63
+ while (grpc_byte_buffer_reader_next(&reader, &next) != 0) {
63
64
  memcpy(string + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
64
65
  offset += GPR_SLICE_LENGTH(next);
65
66
  }
@@ -34,8 +34,9 @@
34
34
  #ifndef GRPC_RB_BYTE_BUFFER_H_
35
35
  #define GRPC_RB_BYTE_BUFFER_H_
36
36
 
37
+ #include <ruby/ruby.h>
38
+
37
39
  #include <grpc/grpc.h>
38
- #include <ruby.h>
39
40
 
40
41
  /* Converts a char* with a length to a grpc_byte_buffer */
41
42
  grpc_byte_buffer *grpc_rb_s_to_byte_buffer(char *string, size_t length);
data/ext/grpc/rb_call.c CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  #include "rb_call.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
39
  #include <grpc/support/alloc.h>
@@ -581,7 +581,7 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
581
581
  VALUE timeout, VALUE ops_hash) {
582
582
  run_batch_stack st;
583
583
  grpc_call *call = NULL;
584
- grpc_event *ev = NULL;
584
+ grpc_event ev;
585
585
  grpc_call_error err;
586
586
  VALUE result = Qnil;
587
587
  TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
@@ -605,15 +605,14 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
605
605
  return Qnil;
606
606
  }
607
607
  ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
608
- if (ev == NULL) {
608
+ if (ev.type == GRPC_QUEUE_TIMEOUT) {
609
609
  grpc_run_batch_stack_cleanup(&st);
610
610
  rb_raise(grpc_rb_eOutOfTime, "grpc_call_start_batch timed out");
611
611
  return Qnil;
612
612
  }
613
- if (ev->data.op_complete != GRPC_OP_OK) {
613
+ if (!ev.success) {
614
614
  grpc_run_batch_stack_cleanup(&st);
615
- rb_raise(grpc_rb_eCallError, "start_batch completion failed, (code=%d)",
616
- ev->data.op_complete);
615
+ rb_raise(grpc_rb_eCallError, "start_batch completion failed");
617
616
  return Qnil;
618
617
  }
619
618
 
data/ext/grpc/rb_call.h CHANGED
@@ -34,8 +34,9 @@
34
34
  #ifndef GRPC_RB_CALL_H_
35
35
  #define GRPC_RB_CALL_H_
36
36
 
37
+ #include <ruby/ruby.h>
38
+
37
39
  #include <grpc/grpc.h>
38
- #include <ruby.h>
39
40
 
40
41
  /* Gets the wrapped call from a VALUE. */
41
42
  grpc_call* grpc_rb_get_wrapped_call(VALUE v);
@@ -33,7 +33,7 @@
33
33
 
34
34
  #include "rb_channel.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
39
  #include <grpc/grpc_security.h>
@@ -34,7 +34,8 @@
34
34
  #ifndef GRPC_RB_CHANNEL_H_
35
35
  #define GRPC_RB_CHANNEL_H_
36
36
 
37
- #include <ruby.h>
37
+ #include <ruby/ruby.h>
38
+
38
39
  #include <grpc/grpc.h>
39
40
 
40
41
  /* Initializes the Channel class. */
@@ -33,7 +33,8 @@
33
33
 
34
34
  #include "rb_channel_args.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
+
37
38
  #include <grpc/grpc.h>
38
39
 
39
40
  #include "rb_grpc.h"
@@ -34,7 +34,8 @@
34
34
  #ifndef GRPC_RB_CHANNEL_ARGS_H_
35
35
  #define GRPC_RB_CHANNEL_ARGS_H_
36
36
 
37
- #include <ruby.h>
37
+ #include <ruby/ruby.h>
38
+
38
39
  #include <grpc/grpc.h>
39
40
 
40
41
  /* Converts a hash object containing channel args to a channel args instance.
@@ -47,7 +47,7 @@ static VALUE grpc_rb_cCompletionQueue = Qnil;
47
47
  /* Used to allow grpc_completion_queue_next call to release the GIL */
48
48
  typedef struct next_call_stack {
49
49
  grpc_completion_queue *cq;
50
- grpc_event *event;
50
+ grpc_event event;
51
51
  gpr_timespec timeout;
52
52
  void *tag;
53
53
  } next_call_stack;
@@ -80,7 +80,7 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) {
80
80
 
81
81
  grpc_completion_queue_shutdown(cq);
82
82
  next_call.cq = cq;
83
- next_call.event = NULL;
83
+ next_call.event.type = GRPC_QUEUE_TIMEOUT;
84
84
  /* TODO: the timeout should be a module level constant that defaults
85
85
  * to gpr_inf_future.
86
86
  *
@@ -95,16 +95,12 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) {
95
95
  do {
96
96
  rb_thread_call_without_gvl(grpc_rb_completion_queue_next_no_gil,
97
97
  (void *)&next_call, NULL, NULL);
98
- if (next_call.event == NULL) {
99
- break;
100
- }
101
- type = next_call.event->type;
98
+ type = next_call.event.type;
99
+ if (type == GRPC_QUEUE_TIMEOUT) break;
102
100
  if (type != GRPC_QUEUE_SHUTDOWN) {
103
101
  ++drained;
104
102
  rb_warning("completion queue shutdown: %d undrained events", drained);
105
103
  }
106
- grpc_event_finish(next_call.event);
107
- next_call.event = NULL;
108
104
  } while (type != GRPC_QUEUE_SHUTDOWN);
109
105
  }
110
106
 
@@ -138,49 +134,19 @@ static VALUE grpc_rb_completion_queue_alloc(VALUE cls) {
138
134
  return TypedData_Wrap_Struct(cls, &grpc_rb_completion_queue_data_type, cq);
139
135
  }
140
136
 
141
- /* Blocks until the next event is available, and returns the event. */
142
- static VALUE grpc_rb_completion_queue_next(VALUE self, VALUE timeout) {
143
- next_call_stack next_call;
144
- MEMZERO(&next_call, next_call_stack, 1);
145
- TypedData_Get_Struct(self, grpc_completion_queue,
146
- &grpc_rb_completion_queue_data_type, next_call.cq);
147
- next_call.timeout = grpc_rb_time_timeval(timeout, /* absolute time*/ 0);
148
- next_call.event = NULL;
149
- rb_thread_call_without_gvl(grpc_rb_completion_queue_next_no_gil,
150
- (void *)&next_call, NULL, NULL);
151
- if (next_call.event == NULL) {
152
- return Qnil;
153
- }
154
- return grpc_rb_new_event(next_call.event);
155
- }
156
-
157
137
  /* Blocks until the next event for given tag is available, and returns the
158
138
  * event. */
159
- VALUE grpc_rb_completion_queue_pluck(VALUE self, VALUE tag,
160
- VALUE timeout) {
161
- grpc_event *ev = grpc_rb_completion_queue_pluck_event(self, tag, timeout);
162
- if (ev == NULL) {
163
- return Qnil;
164
- }
165
- return grpc_rb_new_event(ev);
166
- }
167
-
168
- /* Blocks until the next event for given tag is available, and returns the
169
- * event. */
170
- grpc_event* grpc_rb_completion_queue_pluck_event(VALUE self, VALUE tag,
171
- VALUE timeout) {
139
+ grpc_event grpc_rb_completion_queue_pluck_event(VALUE self, VALUE tag,
140
+ VALUE timeout) {
172
141
  next_call_stack next_call;
173
142
  MEMZERO(&next_call, next_call_stack, 1);
174
143
  TypedData_Get_Struct(self, grpc_completion_queue,
175
144
  &grpc_rb_completion_queue_data_type, next_call.cq);
176
145
  next_call.timeout = grpc_rb_time_timeval(timeout, /* absolute time*/ 0);
177
146
  next_call.tag = ROBJECT(tag);
178
- next_call.event = NULL;
147
+ next_call.event.type = GRPC_QUEUE_TIMEOUT;
179
148
  rb_thread_call_without_gvl(grpc_rb_completion_queue_pluck_no_gil,
180
149
  (void *)&next_call, NULL, NULL);
181
- if (next_call.event == NULL) {
182
- return NULL;
183
- }
184
150
  return next_call.event;
185
151
  }
186
152
 
@@ -193,14 +159,6 @@ void Init_grpc_completion_queue() {
193
159
  this func, so no separate initialization step is necessary. */
194
160
  rb_define_alloc_func(grpc_rb_cCompletionQueue,
195
161
  grpc_rb_completion_queue_alloc);
196
-
197
- /* Add the next method that waits for the next event. */
198
- rb_define_method(grpc_rb_cCompletionQueue, "next",
199
- grpc_rb_completion_queue_next, 1);
200
-
201
- /* Add the pluck method that waits for the next event of given tag */
202
- rb_define_method(grpc_rb_cCompletionQueue, "pluck",
203
- grpc_rb_completion_queue_pluck, 2);
204
162
  }
205
163
 
206
164
  /* Gets the wrapped completion queue from the ruby wrapper */
@@ -34,8 +34,9 @@
34
34
  #ifndef GRPC_RB_COMPLETION_QUEUE_H_
35
35
  #define GRPC_RB_COMPLETION_QUEUE_H_
36
36
 
37
+ #include <ruby/ruby.h>
38
+
37
39
  #include <grpc/grpc.h>
38
- #include <ruby.h>
39
40
 
40
41
  /* Gets the wrapped completion queue from the ruby wrapper */
41
42
  grpc_completion_queue *grpc_rb_get_wrapped_completion_queue(VALUE v);
@@ -45,8 +46,8 @@ grpc_completion_queue *grpc_rb_get_wrapped_completion_queue(VALUE v);
45
46
  *
46
47
  * This avoids having code that holds the GIL repeated at multiple sites.
47
48
  */
48
- grpc_event* grpc_rb_completion_queue_pluck_event(VALUE cqueue, VALUE tag,
49
- VALUE timeout);
49
+ grpc_event grpc_rb_completion_queue_pluck_event(VALUE cqueue, VALUE tag,
50
+ VALUE timeout);
50
51
 
51
52
  /* Initializes the CompletionQueue class. */
52
53
  void Init_grpc_completion_queue();
@@ -33,7 +33,7 @@
33
33
 
34
34
  #include "rb_credentials.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
39
  #include <grpc/grpc_security.h>
@@ -34,7 +34,8 @@
34
34
  #ifndef GRPC_RB_CREDENTIALS_H_
35
35
  #define GRPC_RB_CREDENTIALS_H_
36
36
 
37
- #include <ruby.h>
37
+ #include <ruby/ruby.h>
38
+
38
39
  #include <grpc/grpc_security.h>
39
40
 
40
41
  /* Initializes the ruby Credentials class. */
data/ext/grpc/rb_grpc.h CHANGED
@@ -35,7 +35,8 @@
35
35
  #define GRPC_RB_H_
36
36
 
37
37
  #include <sys/time.h>
38
- #include <ruby.h>
38
+ #include <ruby/ruby.h>
39
+
39
40
  #include <grpc/support/time.h>
40
41
 
41
42
  /* grpc_rb_mGrpcCore is the module containing the ruby wrapper GRPC classes. */
data/ext/grpc/rb_server.c CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  #include "rb_server.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
39
  #include <grpc/grpc_security.h>
@@ -123,7 +123,7 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
123
123
  TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type,
124
124
  wrapper);
125
125
  grpc_rb_hash_convert_to_channel_args(channel_args, &args);
126
- srv = grpc_server_create(cq, &args);
126
+ srv = grpc_server_create(&args);
127
127
 
128
128
  if (args.args != NULL) {
129
129
  xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
@@ -131,6 +131,7 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
131
131
  if (srv == NULL) {
132
132
  rb_raise(rb_eRuntimeError, "could not create a gRPC server, not sure why");
133
133
  }
134
+ grpc_server_register_completion_queue(srv, cq);
134
135
  wrapper->wrapped = srv;
135
136
 
136
137
  /* Add the cq as the server's mark object. This ensures the ruby cq can't be
@@ -203,7 +204,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
203
204
  VALUE tag_new, VALUE timeout) {
204
205
  grpc_rb_server *s = NULL;
205
206
  grpc_call *call = NULL;
206
- grpc_event *ev = NULL;
207
+ grpc_event ev;
207
208
  grpc_call_error err;
208
209
  request_call_stack st;
209
210
  VALUE result;
@@ -218,6 +219,7 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
218
219
  err = grpc_server_request_call(
219
220
  s->wrapped, &call, &st.details, &st.md_ary,
220
221
  grpc_rb_get_wrapped_completion_queue(cqueue),
222
+ grpc_rb_get_wrapped_completion_queue(cqueue),
221
223
  ROBJECT(tag_new));
222
224
  if (err != GRPC_CALL_OK) {
223
225
  grpc_request_call_stack_cleanup(&st);
@@ -227,15 +229,13 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
227
229
  return Qnil;
228
230
  }
229
231
  ev = grpc_rb_completion_queue_pluck_event(cqueue, tag_new, timeout);
230
- if (ev == NULL) {
232
+ if (ev.type == GRPC_QUEUE_TIMEOUT) {
231
233
  grpc_request_call_stack_cleanup(&st);
232
234
  return Qnil;
233
235
  }
234
- if (ev->data.op_complete != GRPC_OP_OK) {
236
+ if (!ev.success) {
235
237
  grpc_request_call_stack_cleanup(&st);
236
- grpc_event_finish(ev);
237
- rb_raise(grpc_rb_eCallError, "request_call completion failed: (code=%d)",
238
- ev->data.op_complete);
238
+ rb_raise(grpc_rb_eCallError, "request_call completion failed");
239
239
  return Qnil;
240
240
  }
241
241
 
@@ -249,7 +249,6 @@ static VALUE grpc_rb_server_request_call(VALUE self, VALUE cqueue,
249
249
  grpc_rb_md_ary_to_h(&st.md_ary),
250
250
  grpc_rb_wrap_call(call),
251
251
  NULL);
252
- grpc_event_finish(ev);
253
252
  grpc_request_call_stack_cleanup(&st);
254
253
  return result;
255
254
  }
@@ -283,12 +282,12 @@ static VALUE grpc_rb_server_destroy(VALUE self) {
283
282
  call-seq:
284
283
  // insecure port
285
284
  insecure_server = Server.new(cq, {'arg1': 'value1'})
286
- insecure_server.add_http2_port('mydomain:7575')
285
+ insecure_server.add_http2_port('mydomain:50051')
287
286
 
288
287
  // secure port
289
288
  server_creds = ...
290
289
  secure_server = Server.new(cq, {'arg1': 'value1'})
291
- secure_server.add_http_port('mydomain:7575', server_creds)
290
+ secure_server.add_http_port('mydomain:50051', server_creds)
292
291
 
293
292
  Adds a http2 port to server */
294
293
  static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) {
data/ext/grpc/rb_server.h CHANGED
@@ -34,7 +34,8 @@
34
34
  #ifndef GRPC_RB_SERVER_H_
35
35
  #define GRPC_RB_SERVER_H_
36
36
 
37
- #include <ruby.h>
37
+ #include <ruby/ruby.h>
38
+
38
39
  #include <grpc/grpc.h>
39
40
 
40
41
  /* Initializes the Server class. */
@@ -33,7 +33,7 @@
33
33
 
34
34
  #include "rb_server_credentials.h"
35
35
 
36
- #include <ruby.h>
36
+ #include <ruby/ruby.h>
37
37
 
38
38
  #include <grpc/grpc.h>
39
39
  #include <grpc/grpc_security.h>
@@ -34,7 +34,8 @@
34
34
  #ifndef GRPC_RB_SERVER_CREDENTIALS_H_
35
35
  #define GRPC_RB_SERVER_CREDENTIALS_H_
36
36
 
37
- #include <ruby.h>
37
+ #include <ruby/ruby.h>
38
+
38
39
  #include <grpc/grpc_security.h>
39
40
 
40
41
  /* Initializes the ruby ServerCredentials class. */