grpc 0.6.0 → 0.6.1

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.rubocop_todo.yml +12 -20
  4. data/CHANGELOG.md +11 -0
  5. data/Rakefile +1 -0
  6. data/bin/apis/pubsub_demo.rb +3 -6
  7. data/bin/interop/interop_client.rb +43 -3
  8. data/bin/interop/interop_server.rb +1 -1
  9. data/bin/math_server.rb +1 -1
  10. data/bin/noproto_server.rb +1 -1
  11. data/ext/grpc/rb_byte_buffer.c +15 -189
  12. data/ext/grpc/rb_byte_buffer.h +4 -12
  13. data/ext/grpc/rb_call.c +514 -307
  14. data/ext/grpc/rb_call.h +4 -4
  15. data/ext/grpc/rb_channel.c +58 -34
  16. data/ext/grpc/rb_channel.h +0 -3
  17. data/ext/grpc/rb_channel_args.c +13 -4
  18. data/ext/grpc/rb_completion_queue.c +50 -23
  19. data/ext/grpc/rb_completion_queue.h +7 -3
  20. data/ext/grpc/rb_credentials.c +40 -28
  21. data/ext/grpc/rb_credentials.h +0 -4
  22. data/ext/grpc/rb_grpc.c +86 -67
  23. data/ext/grpc/rb_grpc.h +20 -10
  24. data/ext/grpc/rb_server.c +119 -26
  25. data/ext/grpc/rb_server.h +0 -4
  26. data/ext/grpc/rb_server_credentials.c +29 -16
  27. data/ext/grpc/rb_server_credentials.h +0 -4
  28. data/grpc.gemspec +11 -8
  29. data/lib/grpc.rb +1 -1
  30. data/lib/grpc/errors.rb +8 -7
  31. data/lib/grpc/generic/active_call.rb +104 -171
  32. data/lib/grpc/generic/bidi_call.rb +32 -60
  33. data/lib/grpc/generic/client_stub.rb +42 -31
  34. data/lib/grpc/generic/rpc_desc.rb +7 -12
  35. data/lib/grpc/generic/rpc_server.rb +253 -170
  36. data/lib/grpc/{core/event.rb → notifier.rb} +25 -9
  37. data/lib/grpc/version.rb +1 -1
  38. data/spec/call_spec.rb +23 -40
  39. data/spec/channel_spec.rb +11 -20
  40. data/spec/client_server_spec.rb +193 -175
  41. data/spec/credentials_spec.rb +2 -2
  42. data/spec/generic/active_call_spec.rb +59 -85
  43. data/spec/generic/client_stub_spec.rb +46 -64
  44. data/spec/generic/rpc_desc_spec.rb +50 -80
  45. data/spec/generic/rpc_server_pool_spec.rb +2 -3
  46. data/spec/generic/rpc_server_spec.rb +158 -29
  47. data/spec/server_spec.rb +1 -1
  48. data/spec/spec_helper.rb +8 -4
  49. metadata +27 -37
  50. data/ext/grpc/rb_event.c +0 -361
  51. data/ext/grpc/rb_event.h +0 -53
  52. data/ext/grpc/rb_metadata.c +0 -215
  53. data/ext/grpc/rb_metadata.h +0 -53
  54. data/spec/alloc_spec.rb +0 -44
  55. data/spec/byte_buffer_spec.rb +0 -67
  56. data/spec/event_spec.rb +0 -53
  57. data/spec/metadata_spec.rb +0 -64
@@ -152,7 +152,7 @@ describe Server do
152
152
  it 'does not take a hash with bad values as channel args' do
153
153
  blk = construct_with_args(symbol: Object.new)
154
154
  expect(&blk).to raise_error TypeError
155
- blk = construct_with_args('1' => Hash.new)
155
+ blk = construct_with_args('1' => {})
156
156
  expect(&blk).to raise_error TypeError
157
157
  end
158
158
 
@@ -35,14 +35,18 @@ $LOAD_PATH.unshift(spec_dir)
35
35
  $LOAD_PATH.unshift(lib_dir)
36
36
  $LOAD_PATH.uniq!
37
37
 
38
- require 'faraday'
38
+ # set up coverage
39
+ require 'simplecov'
40
+ SimpleCov.start do
41
+ add_filter 'spec'
42
+ add_filter 'bin'
43
+ SimpleCov.command_name ENV['COVERAGE_NAME']
44
+ end if ENV['COVERAGE_NAME']
45
+
39
46
  require 'rspec'
40
47
  require 'logging'
41
48
  require 'rspec/logging_helper'
42
49
 
43
- # Allow Faraday to support test stubs
44
- Faraday::Adapter.load_middleware(:test)
45
-
46
50
  # Configure RSpec to capture log messages for each test. The output from the
47
51
  # logs will be stored in the @log_output variable. It is a StringIO instance.
48
52
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gRPC Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: logging
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.8'
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.8'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,89 +67,89 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.4'
69
69
  - !ruby/object:Gem::Dependency
70
- name: xray
70
+ name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
76
- type: :runtime
75
+ version: '0.9'
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: '0.9'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.7'
89
+ version: '1.9'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.7'
96
+ version: '1.9'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: '10.4'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: '10.4'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake-compiler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '0.9'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '0.9'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubocop
126
+ name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.28.0
131
+ version: '3.2'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.28.0
138
+ version: '3.2'
139
139
  - !ruby/object:Gem::Dependency
140
- name: rspec
140
+ name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '3.0'
145
+ version: '0.30'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '3.0'
152
+ version: '0.30'
153
153
  description: Send RPCs from Ruby using GRPC
154
154
  email: temiola@google.com
155
155
  executables:
@@ -167,6 +167,7 @@ files:
167
167
  - ".rspec"
168
168
  - ".rubocop.yml"
169
169
  - ".rubocop_todo.yml"
170
+ - CHANGELOG.md
170
171
  - Gemfile
171
172
  - README.md
172
173
  - Rakefile
@@ -201,19 +202,14 @@ files:
201
202
  - ext/grpc/rb_completion_queue.h
202
203
  - ext/grpc/rb_credentials.c
203
204
  - ext/grpc/rb_credentials.h
204
- - ext/grpc/rb_event.c
205
- - ext/grpc/rb_event.h
206
205
  - ext/grpc/rb_grpc.c
207
206
  - ext/grpc/rb_grpc.h
208
- - ext/grpc/rb_metadata.c
209
- - ext/grpc/rb_metadata.h
210
207
  - ext/grpc/rb_server.c
211
208
  - ext/grpc/rb_server.h
212
209
  - ext/grpc/rb_server_credentials.c
213
210
  - ext/grpc/rb_server_credentials.h
214
211
  - grpc.gemspec
215
212
  - lib/grpc.rb
216
- - lib/grpc/core/event.rb
217
213
  - lib/grpc/core/time_consts.rb
218
214
  - lib/grpc/errors.rb
219
215
  - lib/grpc/generic/active_call.rb
@@ -223,22 +219,19 @@ files:
223
219
  - lib/grpc/generic/rpc_server.rb
224
220
  - lib/grpc/generic/service.rb
225
221
  - lib/grpc/logconfig.rb
222
+ - lib/grpc/notifier.rb
226
223
  - lib/grpc/version.rb
227
- - spec/alloc_spec.rb
228
- - spec/byte_buffer_spec.rb
229
224
  - spec/call_spec.rb
230
225
  - spec/channel_spec.rb
231
226
  - spec/client_server_spec.rb
232
227
  - spec/completion_queue_spec.rb
233
228
  - spec/credentials_spec.rb
234
- - spec/event_spec.rb
235
229
  - spec/generic/active_call_spec.rb
236
230
  - spec/generic/client_stub_spec.rb
237
231
  - spec/generic/rpc_desc_spec.rb
238
232
  - spec/generic/rpc_server_pool_spec.rb
239
233
  - spec/generic/rpc_server_spec.rb
240
234
  - spec/generic/service_spec.rb
241
- - spec/metadata_spec.rb
242
235
  - spec/server_credentials_spec.rb
243
236
  - spec/server_spec.rb
244
237
  - spec/spec_helper.rb
@@ -259,34 +252,31 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
252
  requirements:
260
253
  - - ">="
261
254
  - !ruby/object:Gem::Version
262
- version: '0'
255
+ version: 2.0.0
263
256
  required_rubygems_version: !ruby/object:Gem::Requirement
264
257
  requirements:
265
258
  - - ">="
266
259
  - !ruby/object:Gem::Version
267
260
  version: '0'
268
- requirements: []
261
+ requirements:
262
+ - libgrpc ~> 0.6.0 needs to be installed
269
263
  rubyforge_project:
270
264
  rubygems_version: 2.4.3
271
265
  signing_key:
272
266
  specification_version: 4
273
267
  summary: GRPC system in Ruby
274
268
  test_files:
275
- - spec/alloc_spec.rb
276
- - spec/byte_buffer_spec.rb
277
269
  - spec/call_spec.rb
278
270
  - spec/channel_spec.rb
279
271
  - spec/client_server_spec.rb
280
272
  - spec/completion_queue_spec.rb
281
273
  - spec/credentials_spec.rb
282
- - spec/event_spec.rb
283
274
  - spec/generic/active_call_spec.rb
284
275
  - spec/generic/client_stub_spec.rb
285
276
  - spec/generic/rpc_desc_spec.rb
286
277
  - spec/generic/rpc_server_pool_spec.rb
287
278
  - spec/generic/rpc_server_spec.rb
288
279
  - spec/generic/service_spec.rb
289
- - spec/metadata_spec.rb
290
280
  - spec/server_credentials_spec.rb
291
281
  - spec/server_spec.rb
292
282
  - spec/spec_helper.rb
@@ -1,361 +0,0 @@
1
- /*
2
- *
3
- * Copyright 2015, Google Inc.
4
- * All rights reserved.
5
- *
6
- * Redistribution and use in source and binary forms, with or without
7
- * modification, are permitted provided that the following conditions are
8
- * met:
9
- *
10
- * * Redistributions of source code must retain the above copyright
11
- * notice, this list of conditions and the following disclaimer.
12
- * * Redistributions in binary form must reproduce the above
13
- * copyright notice, this list of conditions and the following disclaimer
14
- * in the documentation and/or other materials provided with the
15
- * distribution.
16
- * * Neither the name of Google Inc. nor the names of its
17
- * contributors may be used to endorse or promote products derived from
18
- * this software without specific prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- *
32
- */
33
-
34
- #include "rb_event.h"
35
-
36
- #include <ruby.h>
37
-
38
- #include <grpc/grpc.h>
39
- #include "rb_grpc.h"
40
- #include "rb_byte_buffer.h"
41
- #include "rb_call.h"
42
- #include "rb_metadata.h"
43
-
44
- /* grpc_rb_event wraps a grpc_event. It provides a peer ruby object,
45
- * 'mark' to minimize copying when an event is created from ruby. */
46
- typedef struct grpc_rb_event {
47
- /* Holder of ruby objects involved in constructing the channel */
48
- VALUE mark;
49
- /* The actual event */
50
- grpc_event *wrapped;
51
- } grpc_rb_event;
52
-
53
- /* rb_mCompletionType is a ruby module that holds the completion type values */
54
- VALUE rb_mCompletionType = Qnil;
55
-
56
- /* Destroys Event instances. */
57
- static void grpc_rb_event_free(void *p) {
58
- grpc_rb_event *ev = NULL;
59
- if (p == NULL) {
60
- return;
61
- };
62
- ev = (grpc_rb_event *)p;
63
-
64
- /* Deletes the wrapped object if the mark object is Qnil, which indicates
65
- * that no other object is the actual owner. */
66
- if (ev->wrapped != NULL && ev->mark == Qnil) {
67
- grpc_event_finish(ev->wrapped);
68
- rb_warning("event gc: destroyed the c event");
69
- } else {
70
- rb_warning("event gc: did not destroy the c event");
71
- }
72
-
73
- xfree(p);
74
- }
75
-
76
- /* Protects the mark object from GC */
77
- static void grpc_rb_event_mark(void *p) {
78
- grpc_rb_event *event = NULL;
79
- if (p == NULL) {
80
- return;
81
- }
82
- event = (grpc_rb_event *)p;
83
- if (event->mark != Qnil) {
84
- rb_gc_mark(event->mark);
85
- }
86
- }
87
-
88
- static VALUE grpc_rb_event_result(VALUE self);
89
-
90
- /* Obtains the type of an event. */
91
- static VALUE grpc_rb_event_type(VALUE self) {
92
- grpc_event *event = NULL;
93
- grpc_rb_event *wrapper = NULL;
94
- Data_Get_Struct(self, grpc_rb_event, wrapper);
95
- if (wrapper->wrapped == NULL) {
96
- rb_raise(rb_eRuntimeError, "finished!");
97
- return Qnil;
98
- }
99
-
100
- event = wrapper->wrapped;
101
- switch (event->type) {
102
- case GRPC_QUEUE_SHUTDOWN:
103
- return rb_const_get(rb_mCompletionType, rb_intern("QUEUE_SHUTDOWN"));
104
-
105
- case GRPC_READ:
106
- return rb_const_get(rb_mCompletionType, rb_intern("READ"));
107
-
108
- case GRPC_WRITE_ACCEPTED:
109
- grpc_rb_event_result(self); /* validates the result */
110
- return rb_const_get(rb_mCompletionType, rb_intern("WRITE_ACCEPTED"));
111
-
112
- case GRPC_FINISH_ACCEPTED:
113
- grpc_rb_event_result(self); /* validates the result */
114
- return rb_const_get(rb_mCompletionType, rb_intern("FINISH_ACCEPTED"));
115
-
116
- case GRPC_CLIENT_METADATA_READ:
117
- return rb_const_get(rb_mCompletionType,
118
- rb_intern("CLIENT_METADATA_READ"));
119
-
120
- case GRPC_FINISHED:
121
- return rb_const_get(rb_mCompletionType, rb_intern("FINISHED"));
122
-
123
- case GRPC_SERVER_RPC_NEW:
124
- return rb_const_get(rb_mCompletionType, rb_intern("SERVER_RPC_NEW"));
125
-
126
- default:
127
- rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
128
- event->type);
129
- }
130
- return Qnil; /* should not be reached */
131
- }
132
-
133
- /* Obtains the tag associated with an event. */
134
- static VALUE grpc_rb_event_tag(VALUE self) {
135
- grpc_event *event = NULL;
136
- grpc_rb_event *wrapper = NULL;
137
- Data_Get_Struct(self, grpc_rb_event, wrapper);
138
- if (wrapper->wrapped == NULL) {
139
- rb_raise(rb_eRuntimeError, "finished!");
140
- return Qnil;
141
- }
142
-
143
- event = wrapper->wrapped;
144
- if (event->tag == NULL) {
145
- return Qnil;
146
- }
147
- return (VALUE)event->tag;
148
- }
149
-
150
- /* Obtains the call associated with an event. */
151
- static VALUE grpc_rb_event_call(VALUE self) {
152
- grpc_event *event = NULL;
153
- grpc_rb_event *wrapper = NULL;
154
- Data_Get_Struct(self, grpc_rb_event, wrapper);
155
- if (wrapper->wrapped == NULL) {
156
- rb_raise(rb_eRuntimeError, "finished!");
157
- return Qnil;
158
- }
159
-
160
- event = wrapper->wrapped;
161
- if (event->call != NULL) {
162
- return grpc_rb_wrap_call(event->call);
163
- }
164
- return Qnil;
165
- }
166
-
167
- /* Obtains the metadata associated with an event. */
168
- static VALUE grpc_rb_event_metadata(VALUE self) {
169
- grpc_event *event = NULL;
170
- grpc_rb_event *wrapper = NULL;
171
- grpc_metadata *metadata = NULL;
172
- VALUE key = Qnil;
173
- VALUE new_ary = Qnil;
174
- VALUE result = Qnil;
175
- VALUE value = Qnil;
176
- size_t count = 0;
177
- size_t i = 0;
178
- Data_Get_Struct(self, grpc_rb_event, wrapper);
179
- if (wrapper->wrapped == NULL) {
180
- rb_raise(rb_eRuntimeError, "finished!");
181
- return Qnil;
182
- }
183
-
184
- /* Figure out which metadata to read. */
185
- event = wrapper->wrapped;
186
- switch (event->type) {
187
- case GRPC_CLIENT_METADATA_READ:
188
- count = event->data.client_metadata_read.count;
189
- metadata = event->data.client_metadata_read.elements;
190
- break;
191
-
192
- case GRPC_FINISHED:
193
- count = event->data.finished.metadata_count;
194
- metadata = event->data.finished.metadata_elements;
195
- break;
196
-
197
- case GRPC_SERVER_RPC_NEW:
198
- count = event->data.server_rpc_new.metadata_count;
199
- metadata = event->data.server_rpc_new.metadata_elements;
200
- break;
201
-
202
- default:
203
- rb_raise(rb_eRuntimeError,
204
- "bug: bad event type metadata. got %d; want %d|%d:%d",
205
- event->type, GRPC_CLIENT_METADATA_READ, GRPC_FINISHED,
206
- GRPC_SERVER_RPC_NEW);
207
- return Qnil;
208
- }
209
-
210
- result = rb_hash_new();
211
- for (i = 0; i < count; i++) {
212
- key = rb_str_new2(metadata[i].key);
213
- value = rb_hash_aref(result, key);
214
- if (value == Qnil) {
215
- value = rb_str_new(metadata[i].value, metadata[i].value_length);
216
- rb_hash_aset(result, key, value);
217
- } else if (TYPE(value) == T_ARRAY) {
218
- /* Add the string to the returned array */
219
- rb_ary_push(value,
220
- rb_str_new(metadata[i].value, metadata[i].value_length));
221
- } else {
222
- /* Add the current value with this key and the new one to an array */
223
- new_ary = rb_ary_new();
224
- rb_ary_push(new_ary, value);
225
- rb_ary_push(new_ary,
226
- rb_str_new(metadata[i].value, metadata[i].value_length));
227
- rb_hash_aset(result, key, new_ary);
228
- }
229
- }
230
- return result;
231
- }
232
-
233
- /* Obtains the data associated with an event. */
234
- static VALUE grpc_rb_event_result(VALUE self) {
235
- grpc_event *event = NULL;
236
- grpc_rb_event *wrapper = NULL;
237
- Data_Get_Struct(self, grpc_rb_event, wrapper);
238
- if (wrapper->wrapped == NULL) {
239
- rb_raise(rb_eRuntimeError, "finished!");
240
- return Qnil;
241
- }
242
- event = wrapper->wrapped;
243
-
244
- switch (event->type) {
245
- case GRPC_QUEUE_SHUTDOWN:
246
- return Qnil;
247
-
248
- case GRPC_READ:
249
- return grpc_rb_byte_buffer_create_with_mark(self, event->data.read);
250
-
251
- case GRPC_FINISH_ACCEPTED:
252
- if (event->data.finish_accepted == GRPC_OP_OK) {
253
- return Qnil;
254
- }
255
- rb_raise(rb_eEventError, "finish failed, not sure why (code=%d)",
256
- event->data.finish_accepted);
257
- break;
258
-
259
- case GRPC_WRITE_ACCEPTED:
260
- if (event->data.write_accepted == GRPC_OP_OK) {
261
- return Qnil;
262
- }
263
- rb_raise(rb_eEventError, "write failed, not sure why (code=%d)",
264
- event->data.write_accepted);
265
- break;
266
-
267
- case GRPC_CLIENT_METADATA_READ:
268
- return grpc_rb_event_metadata(self);
269
-
270
- case GRPC_FINISHED:
271
- return rb_struct_new(rb_sStatus, UINT2NUM(event->data.finished.status),
272
- (event->data.finished.details == NULL
273
- ? Qnil
274
- : rb_str_new2(event->data.finished.details)),
275
- grpc_rb_event_metadata(self), NULL);
276
- break;
277
-
278
- case GRPC_SERVER_RPC_NEW:
279
- return rb_struct_new(
280
- rb_sNewServerRpc, rb_str_new2(event->data.server_rpc_new.method),
281
- rb_str_new2(event->data.server_rpc_new.host),
282
- Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
283
- (void *)&event->data.server_rpc_new.deadline),
284
- grpc_rb_event_metadata(self), NULL);
285
-
286
- default:
287
- rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
288
- event->type);
289
- }
290
-
291
- return Qfalse;
292
- }
293
-
294
- static VALUE grpc_rb_event_finish(VALUE self) {
295
- grpc_event *event = NULL;
296
- grpc_rb_event *wrapper = NULL;
297
- Data_Get_Struct(self, grpc_rb_event, wrapper);
298
- if (wrapper->wrapped == NULL) { /* already closed */
299
- return Qnil;
300
- }
301
- event = wrapper->wrapped;
302
- grpc_event_finish(event);
303
- wrapper->wrapped = NULL;
304
- wrapper->mark = Qnil;
305
- return Qnil;
306
- }
307
-
308
- /* rb_cEvent is the Event class whose instances proxy grpc_event */
309
- VALUE rb_cEvent = Qnil;
310
-
311
- /* rb_eEventError is the ruby class of the exception thrown on failures during
312
- rpc event processing. */
313
- VALUE rb_eEventError = Qnil;
314
-
315
- void Init_grpc_event() {
316
- rb_eEventError =
317
- rb_define_class_under(rb_mGrpcCore, "EventError", rb_eStandardError);
318
- rb_cEvent = rb_define_class_under(rb_mGrpcCore, "Event", rb_cObject);
319
-
320
- /* Prevent allocation or inialization from ruby. */
321
- rb_define_alloc_func(rb_cEvent, grpc_rb_cannot_alloc);
322
- rb_define_method(rb_cEvent, "initialize", grpc_rb_cannot_init, 0);
323
- rb_define_method(rb_cEvent, "initialize_copy", grpc_rb_cannot_init_copy, 1);
324
-
325
- /* Accessors for the data available in an event. */
326
- rb_define_method(rb_cEvent, "call", grpc_rb_event_call, 0);
327
- rb_define_method(rb_cEvent, "result", grpc_rb_event_result, 0);
328
- rb_define_method(rb_cEvent, "tag", grpc_rb_event_tag, 0);
329
- rb_define_method(rb_cEvent, "type", grpc_rb_event_type, 0);
330
- rb_define_method(rb_cEvent, "finish", grpc_rb_event_finish, 0);
331
- rb_define_alias(rb_cEvent, "close", "finish");
332
-
333
- /* Constants representing the completion types */
334
- rb_mCompletionType =
335
- rb_define_module_under(rb_mGrpcCore, "CompletionType");
336
- rb_define_const(rb_mCompletionType, "QUEUE_SHUTDOWN",
337
- INT2NUM(GRPC_QUEUE_SHUTDOWN));
338
- rb_define_const(rb_mCompletionType, "OP_COMPLETE", INT2NUM(GRPC_OP_COMPLETE));
339
- rb_define_const(rb_mCompletionType, "READ", INT2NUM(GRPC_READ));
340
- rb_define_const(rb_mCompletionType, "WRITE_ACCEPTED",
341
- INT2NUM(GRPC_WRITE_ACCEPTED));
342
- rb_define_const(rb_mCompletionType, "FINISH_ACCEPTED",
343
- INT2NUM(GRPC_FINISH_ACCEPTED));
344
- rb_define_const(rb_mCompletionType, "CLIENT_METADATA_READ",
345
- INT2NUM(GRPC_CLIENT_METADATA_READ));
346
- rb_define_const(rb_mCompletionType, "FINISHED", INT2NUM(GRPC_FINISHED));
347
- rb_define_const(rb_mCompletionType, "SERVER_RPC_NEW",
348
- INT2NUM(GRPC_SERVER_RPC_NEW));
349
- rb_define_const(rb_mCompletionType, "SERVER_SHUTDOWN",
350
- INT2NUM(GRPC_SERVER_SHUTDOWN));
351
- rb_define_const(rb_mCompletionType, "RESERVED",
352
- INT2NUM(GRPC_COMPLETION_DO_NOT_USE));
353
- }
354
-
355
- VALUE grpc_rb_new_event(grpc_event *ev) {
356
- grpc_rb_event *wrapper = ALLOC(grpc_rb_event);
357
- wrapper->wrapped = ev;
358
- wrapper->mark = Qnil;
359
- return Data_Wrap_Struct(rb_cEvent, grpc_rb_event_mark, grpc_rb_event_free,
360
- wrapper);
361
- }