grpc 0.13.0.pre1.1-x64-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.

Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +5114 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
  6. data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
  7. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
  8. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
  9. data/src/ruby/bin/grpc_ruby_interop_client +33 -0
  10. data/src/ruby/bin/grpc_ruby_interop_server +33 -0
  11. data/src/ruby/bin/interop/interop_client.rb +51 -0
  12. data/src/ruby/bin/interop/interop_server.rb +50 -0
  13. data/src/ruby/bin/math.rb +32 -0
  14. data/src/ruby/bin/math_client.rb +147 -0
  15. data/src/ruby/bin/math_server.rb +206 -0
  16. data/src/ruby/bin/math_services.rb +27 -0
  17. data/src/ruby/bin/noproto_client.rb +108 -0
  18. data/src/ruby/bin/noproto_server.rb +112 -0
  19. data/src/ruby/ext/grpc/extconf.rb +129 -0
  20. data/src/ruby/ext/grpc/rb_byte_buffer.c +70 -0
  21. data/src/ruby/ext/grpc/rb_byte_buffer.h +47 -0
  22. data/src/ruby/ext/grpc/rb_call.c +908 -0
  23. data/src/ruby/ext/grpc/rb_call.h +66 -0
  24. data/src/ruby/ext/grpc/rb_call_credentials.c +319 -0
  25. data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
  26. data/src/ruby/ext/grpc/rb_channel.c +432 -0
  27. data/src/ruby/ext/grpc/rb_channel.h +47 -0
  28. data/src/ruby/ext/grpc/rb_channel_args.c +169 -0
  29. data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
  30. data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
  31. data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
  32. data/src/ruby/ext/grpc/rb_completion_queue.c +183 -0
  33. data/src/ruby/ext/grpc/rb_completion_queue.h +55 -0
  34. data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
  35. data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
  36. data/src/ruby/ext/grpc/rb_grpc.c +336 -0
  37. data/src/ruby/ext/grpc/rb_grpc.h +85 -0
  38. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +560 -0
  39. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +843 -0
  40. data/src/ruby/ext/grpc/rb_loader.c +72 -0
  41. data/src/ruby/ext/grpc/rb_loader.h +40 -0
  42. data/src/ruby/ext/grpc/rb_server.c +400 -0
  43. data/src/ruby/ext/grpc/rb_server.h +47 -0
  44. data/src/ruby/ext/grpc/rb_server_credentials.c +284 -0
  45. data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
  46. data/src/ruby/lib/grpc.rb +44 -0
  47. data/src/ruby/lib/grpc/2.0/grpc_c.so +0 -0
  48. data/src/ruby/lib/grpc/2.1/grpc_c.so +0 -0
  49. data/src/ruby/lib/grpc/2.2/grpc_c.so +0 -0
  50. data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
  51. data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
  52. data/src/ruby/lib/grpc/errors.rb +62 -0
  53. data/src/ruby/lib/grpc/generic/active_call.rb +488 -0
  54. data/src/ruby/lib/grpc/generic/bidi_call.rb +218 -0
  55. data/src/ruby/lib/grpc/generic/client_stub.rb +471 -0
  56. data/src/ruby/lib/grpc/generic/rpc_desc.rb +147 -0
  57. data/src/ruby/lib/grpc/generic/rpc_server.rb +504 -0
  58. data/src/ruby/lib/grpc/generic/service.rb +234 -0
  59. data/src/ruby/lib/grpc/grpc.rb +34 -0
  60. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  61. data/src/ruby/lib/grpc/logconfig.rb +59 -0
  62. data/src/ruby/lib/grpc/notifier.rb +60 -0
  63. data/src/ruby/lib/grpc/version.rb +33 -0
  64. data/src/ruby/pb/README.md +42 -0
  65. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  66. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  67. data/src/ruby/pb/grpc/health/v1alpha/health.rb +29 -0
  68. data/src/ruby/pb/grpc/health/v1alpha/health_services.rb +28 -0
  69. data/src/ruby/pb/test/client.rb +469 -0
  70. data/src/ruby/pb/test/proto/empty.rb +15 -0
  71. data/src/ruby/pb/test/proto/messages.rb +80 -0
  72. data/src/ruby/pb/test/proto/test.rb +14 -0
  73. data/src/ruby/pb/test/proto/test_services.rb +64 -0
  74. data/src/ruby/pb/test/server.rb +253 -0
  75. data/src/ruby/spec/call_credentials_spec.rb +57 -0
  76. data/src/ruby/spec/call_spec.rb +163 -0
  77. data/src/ruby/spec/channel_credentials_spec.rb +97 -0
  78. data/src/ruby/spec/channel_spec.rb +177 -0
  79. data/src/ruby/spec/client_server_spec.rb +475 -0
  80. data/src/ruby/spec/completion_queue_spec.rb +42 -0
  81. data/src/ruby/spec/generic/active_call_spec.rb +373 -0
  82. data/src/ruby/spec/generic/client_stub_spec.rb +476 -0
  83. data/src/ruby/spec/generic/rpc_desc_spec.rb +331 -0
  84. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +138 -0
  85. data/src/ruby/spec/generic/rpc_server_spec.rb +576 -0
  86. data/src/ruby/spec/generic/service_spec.rb +345 -0
  87. data/src/ruby/spec/pb/health/checker_spec.rb +232 -0
  88. data/src/ruby/spec/server_credentials_spec.rb +94 -0
  89. data/src/ruby/spec/server_spec.rb +209 -0
  90. data/src/ruby/spec/spec_helper.rb +69 -0
  91. data/src/ruby/spec/testdata/README +1 -0
  92. data/src/ruby/spec/testdata/ca.pem +15 -0
  93. data/src/ruby/spec/testdata/server1.key +16 -0
  94. data/src/ruby/spec/testdata/server1.pem +16 -0
  95. data/src/ruby/spec/time_consts_spec.rb +89 -0
  96. metadata +320 -0
@@ -0,0 +1,66 @@
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
+ #ifndef GRPC_RB_CALL_H_
35
+ #define GRPC_RB_CALL_H_
36
+
37
+ #include <ruby/ruby.h>
38
+
39
+ #include <grpc/grpc.h>
40
+
41
+ /* Gets the wrapped call from a VALUE. */
42
+ grpc_call* grpc_rb_get_wrapped_call(VALUE v);
43
+
44
+ /* Gets the VALUE corresponding to given grpc_call. */
45
+ VALUE grpc_rb_wrap_call(grpc_call* c);
46
+
47
+ /* Provides the details of an call error */
48
+ const char* grpc_call_error_detail_of(grpc_call_error err);
49
+
50
+ /* Converts a metadata array to a hash. */
51
+ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
52
+
53
+ /* grpc_rb_md_ary_convert converts a ruby metadata hash into
54
+ a grpc_metadata_array.
55
+ */
56
+ void grpc_rb_md_ary_convert(VALUE md_ary_hash,
57
+ grpc_metadata_array *md_ary);
58
+
59
+ /* grpc_rb_eCallError is the ruby class of the exception thrown during call
60
+ operations. */
61
+ extern VALUE grpc_rb_eCallError;
62
+
63
+ /* Initializes the Call class. */
64
+ void Init_grpc_call();
65
+
66
+ #endif /* GRPC_RB_CALL_H_ */
@@ -0,0 +1,319 @@
1
+ /*
2
+ *
3
+ * Copyright 2015-2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include <ruby/ruby.h>
35
+ #include "rb_grpc_imports.generated.h"
36
+ #include "rb_call_credentials.h"
37
+
38
+ #include <ruby/ruby.h>
39
+ #include <ruby/thread.h>
40
+
41
+ #include <grpc/grpc.h>
42
+ #include <grpc/grpc_security.h>
43
+ #include <grpc/support/alloc.h>
44
+
45
+ #include "rb_call.h"
46
+ #include "rb_event_thread.h"
47
+ #include "rb_grpc.h"
48
+
49
+ /* grpc_rb_cCallCredentials is the ruby class that proxies
50
+ * grpc_call_credentials */
51
+ static VALUE grpc_rb_cCallCredentials = Qnil;
52
+
53
+ /* grpc_rb_call_credentials wraps a grpc_call_credentials. It provides a peer
54
+ * ruby object, 'mark' to minimize copying when a credential is created from
55
+ * ruby. */
56
+ typedef struct grpc_rb_call_credentials {
57
+ /* Holder of ruby objects involved in contructing the credentials */
58
+ VALUE mark;
59
+
60
+ /* The actual credentials */
61
+ grpc_call_credentials *wrapped;
62
+ } grpc_rb_call_credentials;
63
+
64
+ typedef struct callback_params {
65
+ VALUE get_metadata;
66
+ grpc_auth_metadata_context context;
67
+ void *user_data;
68
+ grpc_credentials_plugin_metadata_cb callback;
69
+ } callback_params;
70
+
71
+ static VALUE grpc_rb_call_credentials_callback(VALUE callback_args) {
72
+ VALUE result = rb_hash_new();
73
+ VALUE metadata = rb_funcall(rb_ary_entry(callback_args, 0), rb_intern("call"),
74
+ 1, rb_ary_entry(callback_args, 1));
75
+ rb_hash_aset(result, rb_str_new2("metadata"), metadata);
76
+ rb_hash_aset(result, rb_str_new2("status"), INT2NUM(GRPC_STATUS_OK));
77
+ rb_hash_aset(result, rb_str_new2("details"), rb_str_new2(""));
78
+ return result;
79
+ }
80
+
81
+ static VALUE grpc_rb_call_credentials_callback_rescue(VALUE args,
82
+ VALUE exception_object) {
83
+ VALUE result = rb_hash_new();
84
+ (void)args;
85
+ rb_hash_aset(result, rb_str_new2("metadata"), Qnil);
86
+ /* Currently only gives the exception class name. It should be possible get
87
+ more details */
88
+ rb_hash_aset(result, rb_str_new2("status"),
89
+ INT2NUM(GRPC_STATUS_PERMISSION_DENIED));
90
+ rb_hash_aset(result, rb_str_new2("details"),
91
+ rb_str_new2(rb_obj_classname(exception_object)));
92
+ return result;
93
+ }
94
+
95
+ static void grpc_rb_call_credentials_callback_with_gil(void *param) {
96
+ callback_params *const params = (callback_params *)param;
97
+ VALUE auth_uri = rb_str_new_cstr(params->context.service_url);
98
+ /* Pass the arguments to the proc in a hash, which currently only has they key
99
+ 'auth_uri' */
100
+ VALUE callback_args = rb_ary_new();
101
+ VALUE args = rb_hash_new();
102
+ VALUE result;
103
+ grpc_metadata_array md_ary;
104
+ grpc_status_code status;
105
+ VALUE details;
106
+ char *error_details;
107
+ grpc_metadata_array_init(&md_ary);
108
+ rb_hash_aset(args, ID2SYM(rb_intern("jwt_aud_uri")), auth_uri);
109
+ rb_ary_push(callback_args, params->get_metadata);
110
+ rb_ary_push(callback_args, args);
111
+ result = rb_rescue(grpc_rb_call_credentials_callback, callback_args,
112
+ grpc_rb_call_credentials_callback_rescue, Qnil);
113
+ // Both callbacks return a hash, so result should be a hash
114
+ grpc_rb_md_ary_convert(rb_hash_aref(result, rb_str_new2("metadata")), &md_ary);
115
+ status = NUM2INT(rb_hash_aref(result, rb_str_new2("status")));
116
+ details = rb_hash_aref(result, rb_str_new2("details"));
117
+ error_details = StringValueCStr(details);
118
+ params->callback(params->user_data, md_ary.metadata, md_ary.count, status,
119
+ error_details);
120
+ grpc_metadata_array_destroy(&md_ary);
121
+ gpr_free(params);
122
+ }
123
+
124
+ static void grpc_rb_call_credentials_plugin_get_metadata(
125
+ void *state, grpc_auth_metadata_context context,
126
+ grpc_credentials_plugin_metadata_cb cb, void *user_data) {
127
+ callback_params *params = gpr_malloc(sizeof(callback_params));
128
+ params->get_metadata = (VALUE)state;
129
+ params->context = context;
130
+ params->user_data = user_data;
131
+ params->callback = cb;
132
+
133
+ grpc_rb_event_queue_enqueue(grpc_rb_call_credentials_callback_with_gil,
134
+ (void*)(params));
135
+ }
136
+
137
+ static void grpc_rb_call_credentials_plugin_destroy(void *state) {
138
+ (void)state;
139
+ // Not sure what needs to be done here
140
+ }
141
+
142
+ /* Destroys the credentials instances. */
143
+ static void grpc_rb_call_credentials_free(void *p) {
144
+ grpc_rb_call_credentials *wrapper;
145
+ if (p == NULL) {
146
+ return;
147
+ }
148
+ wrapper = (grpc_rb_call_credentials *)p;
149
+
150
+ /* Delete the wrapped object if the mark object is Qnil, which indicates that
151
+ * no other object is the actual owner. */
152
+ if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
153
+ grpc_call_credentials_release(wrapper->wrapped);
154
+ wrapper->wrapped = NULL;
155
+ }
156
+
157
+ xfree(p);
158
+ }
159
+
160
+ /* Protects the mark object from GC */
161
+ static void grpc_rb_call_credentials_mark(void *p) {
162
+ grpc_rb_call_credentials *wrapper = NULL;
163
+ if (p == NULL) {
164
+ return;
165
+ }
166
+ wrapper = (grpc_rb_call_credentials *)p;
167
+
168
+ /* If it's not already cleaned up, mark the mark object */
169
+ if (wrapper->mark != Qnil) {
170
+ rb_gc_mark(wrapper->mark);
171
+ }
172
+ }
173
+
174
+ static rb_data_type_t grpc_rb_call_credentials_data_type = {
175
+ "grpc_call_credentials",
176
+ {grpc_rb_call_credentials_mark, grpc_rb_call_credentials_free,
177
+ GRPC_RB_MEMSIZE_UNAVAILABLE, {NULL, NULL}},
178
+ NULL,
179
+ NULL,
180
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
181
+ RUBY_TYPED_FREE_IMMEDIATELY
182
+ #endif
183
+ };
184
+
185
+ /* Allocates CallCredentials instances.
186
+ Provides safe initial defaults for the instance fields. */
187
+ static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
188
+ grpc_rb_call_credentials *wrapper = ALLOC(grpc_rb_call_credentials);
189
+ wrapper->wrapped = NULL;
190
+ wrapper->mark = Qnil;
191
+ return TypedData_Wrap_Struct(cls, &grpc_rb_call_credentials_data_type, wrapper);
192
+ }
193
+
194
+ /* Creates a wrapping object for a given call credentials. This should only be
195
+ * called with grpc_call_credentials objects that are not already associated
196
+ * with any Ruby object */
197
+ VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c) {
198
+ VALUE rb_wrapper;
199
+ grpc_rb_call_credentials *wrapper;
200
+ if (c == NULL) {
201
+ return Qnil;
202
+ }
203
+ rb_wrapper = grpc_rb_call_credentials_alloc(grpc_rb_cCallCredentials);
204
+ TypedData_Get_Struct(rb_wrapper, grpc_rb_call_credentials,
205
+ &grpc_rb_call_credentials_data_type, wrapper);
206
+ wrapper->wrapped = c;
207
+ return rb_wrapper;
208
+ }
209
+
210
+ /* Clones CallCredentials instances.
211
+ Gives CallCredentials a consistent implementation of Ruby's object copy/dup
212
+ protocol. */
213
+ static VALUE grpc_rb_call_credentials_init_copy(VALUE copy, VALUE orig) {
214
+ grpc_rb_call_credentials *orig_cred = NULL;
215
+ grpc_rb_call_credentials *copy_cred = NULL;
216
+
217
+ if (copy == orig) {
218
+ return copy;
219
+ }
220
+
221
+ /* Raise an error if orig is not a credentials object or a subclass. */
222
+ if (TYPE(orig) != T_DATA ||
223
+ RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_call_credentials_free) {
224
+ rb_raise(rb_eTypeError, "not a %s",
225
+ rb_obj_classname(grpc_rb_cCallCredentials));
226
+ }
227
+
228
+ TypedData_Get_Struct(orig, grpc_rb_call_credentials,
229
+ &grpc_rb_call_credentials_data_type, orig_cred);
230
+ TypedData_Get_Struct(copy, grpc_rb_call_credentials,
231
+ &grpc_rb_call_credentials_data_type, copy_cred);
232
+
233
+ /* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
234
+ * wrapper object. */
235
+ MEMCPY(copy_cred, orig_cred, grpc_rb_call_credentials, 1);
236
+ return copy;
237
+ }
238
+
239
+ /* The attribute used on the mark object to hold the callback */
240
+ static ID id_callback;
241
+
242
+ /*
243
+ call-seq:
244
+ creds = Credentials.new auth_proc
245
+ proc: (required) Proc that generates auth metadata
246
+ Initializes CallCredential instances. */
247
+ static VALUE grpc_rb_call_credentials_init(VALUE self, VALUE proc) {
248
+ grpc_rb_call_credentials *wrapper = NULL;
249
+ grpc_call_credentials *creds = NULL;
250
+ grpc_metadata_credentials_plugin plugin;
251
+
252
+ TypedData_Get_Struct(self, grpc_rb_call_credentials,
253
+ &grpc_rb_call_credentials_data_type, wrapper);
254
+
255
+ plugin.get_metadata = grpc_rb_call_credentials_plugin_get_metadata;
256
+ plugin.destroy = grpc_rb_call_credentials_plugin_destroy;
257
+ if (!rb_obj_is_proc(proc)) {
258
+ rb_raise(rb_eTypeError, "Argument to CallCredentials#new must be a proc");
259
+ return Qnil;
260
+ }
261
+ plugin.state = (void*)proc;
262
+ plugin.type = "";
263
+
264
+ creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL);
265
+ if (creds == NULL) {
266
+ rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");
267
+ return Qnil;
268
+ }
269
+
270
+ wrapper->wrapped = creds;
271
+ rb_ivar_set(self, id_callback, proc);
272
+
273
+ return self;
274
+ }
275
+
276
+ static VALUE grpc_rb_call_credentials_compose(int argc, VALUE *argv,
277
+ VALUE self) {
278
+ grpc_call_credentials *creds;
279
+ grpc_call_credentials *other;
280
+ if (argc == 0) {
281
+ return self;
282
+ }
283
+ creds = grpc_rb_get_wrapped_call_credentials(self);
284
+ for (int i = 0; i < argc; i++) {
285
+ other = grpc_rb_get_wrapped_call_credentials(argv[i]);
286
+ creds = grpc_composite_call_credentials_create(creds, other, NULL);
287
+ }
288
+ return grpc_rb_wrap_call_credentials(creds);
289
+ }
290
+
291
+ void Init_grpc_call_credentials() {
292
+ grpc_rb_cCallCredentials =
293
+ rb_define_class_under(grpc_rb_mGrpcCore, "CallCredentials", rb_cObject);
294
+
295
+ /* Allocates an object managed by the ruby runtime */
296
+ rb_define_alloc_func(grpc_rb_cCallCredentials,
297
+ grpc_rb_call_credentials_alloc);
298
+
299
+ /* Provides a ruby constructor and support for dup/clone. */
300
+ rb_define_method(grpc_rb_cCallCredentials, "initialize",
301
+ grpc_rb_call_credentials_init, 1);
302
+ rb_define_method(grpc_rb_cCallCredentials, "initialize_copy",
303
+ grpc_rb_call_credentials_init_copy, 1);
304
+ rb_define_method(grpc_rb_cCallCredentials, "compose",
305
+ grpc_rb_call_credentials_compose, -1);
306
+
307
+ id_callback = rb_intern("__callback");
308
+
309
+ grpc_rb_event_queue_thread_start();
310
+ }
311
+
312
+ /* Gets the wrapped grpc_call_credentials from the ruby wrapper */
313
+ grpc_call_credentials *grpc_rb_get_wrapped_call_credentials(VALUE v) {
314
+ grpc_rb_call_credentials *wrapper = NULL;
315
+ TypedData_Get_Struct(v, grpc_rb_call_credentials,
316
+ &grpc_rb_call_credentials_data_type,
317
+ wrapper);
318
+ return wrapper->wrapped;
319
+ }
@@ -0,0 +1,46 @@
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
+ #ifndef GRPC_RB_CALL_CREDENTIALS_H_
35
+ #define GRPC_RB_CALL_CREDENTIALS_H_
36
+
37
+ #include <ruby/ruby.h>
38
+
39
+ #include <grpc/grpc_security.h>
40
+
41
+ /* Initializes the ruby CallCredentials class. */
42
+ void Init_grpc_call_credentials();
43
+
44
+ grpc_call_credentials* grpc_rb_get_wrapped_call_credentials(VALUE v);
45
+
46
+ #endif /* GRPC_RB_CALL_CREDENTIALS_H_ */
@@ -0,0 +1,432 @@
1
+ /*
2
+ *
3
+ * Copyright 2015-2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include <ruby/ruby.h>
35
+ #include "rb_grpc_imports.generated.h"
36
+ #include "rb_channel.h"
37
+
38
+ #include <ruby/ruby.h>
39
+
40
+ #include <grpc/grpc.h>
41
+ #include <grpc/grpc_security.h>
42
+ #include <grpc/support/alloc.h>
43
+ #include "rb_grpc.h"
44
+ #include "rb_call.h"
45
+ #include "rb_channel_args.h"
46
+ #include "rb_channel_credentials.h"
47
+ #include "rb_completion_queue.h"
48
+ #include "rb_server.h"
49
+
50
+ /* id_channel is the name of the hidden ivar that preserves a reference to the
51
+ * channel on a call, so that calls are not GCed before their channel. */
52
+ static ID id_channel;
53
+
54
+ /* id_target is the name of the hidden ivar that preserves a reference to the
55
+ * target string used to create the call, preserved so that it does not get
56
+ * GCed before the channel */
57
+ static ID id_target;
58
+
59
+ /* id_cqueue is the name of the hidden ivar that preserves a reference to the
60
+ * completion queue used to create the call, preserved so that it does not get
61
+ * GCed before the channel */
62
+ static ID id_cqueue;
63
+
64
+ /* id_insecure_channel is used to indicate that a channel is insecure */
65
+ static VALUE id_insecure_channel;
66
+
67
+ /* grpc_rb_cChannel is the ruby class that proxies grpc_channel. */
68
+ static VALUE grpc_rb_cChannel = Qnil;
69
+
70
+ /* Used during the conversion of a hash to channel args during channel setup */
71
+ static VALUE grpc_rb_cChannelArgs;
72
+
73
+ /* grpc_rb_channel wraps a grpc_channel. It provides a peer ruby object,
74
+ * 'mark' to minimize copying when a channel is created from ruby. */
75
+ typedef struct grpc_rb_channel {
76
+ /* Holder of ruby objects involved in constructing the channel */
77
+ VALUE mark;
78
+ /* The actual channel */
79
+ grpc_channel *wrapped;
80
+ } grpc_rb_channel;
81
+
82
+ /* Destroys Channel instances. */
83
+ static void grpc_rb_channel_free(void *p) {
84
+ grpc_rb_channel *ch = NULL;
85
+ if (p == NULL) {
86
+ return;
87
+ };
88
+ ch = (grpc_rb_channel *)p;
89
+
90
+ /* Deletes the wrapped object if the mark object is Qnil, which indicates
91
+ * that no other object is the actual owner. */
92
+ if (ch->wrapped != NULL && ch->mark == Qnil) {
93
+ grpc_channel_destroy(ch->wrapped);
94
+ rb_warning("channel gc: destroyed the c channel");
95
+ } else {
96
+ rb_warning("channel gc: did not destroy the c channel");
97
+ }
98
+
99
+ xfree(p);
100
+ }
101
+
102
+ /* Protects the mark object from GC */
103
+ static void grpc_rb_channel_mark(void *p) {
104
+ grpc_rb_channel *channel = NULL;
105
+ if (p == NULL) {
106
+ return;
107
+ }
108
+ channel = (grpc_rb_channel *)p;
109
+ if (channel->mark != Qnil) {
110
+ rb_gc_mark(channel->mark);
111
+ }
112
+ }
113
+
114
+ static rb_data_type_t grpc_channel_data_type = {
115
+ "grpc_channel",
116
+ {grpc_rb_channel_mark, grpc_rb_channel_free, GRPC_RB_MEMSIZE_UNAVAILABLE,
117
+ {NULL, NULL}},
118
+ NULL, NULL,
119
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
120
+ RUBY_TYPED_FREE_IMMEDIATELY
121
+ #endif
122
+ };
123
+
124
+ /* Allocates grpc_rb_channel instances. */
125
+ static VALUE grpc_rb_channel_alloc(VALUE cls) {
126
+ grpc_rb_channel *wrapper = ALLOC(grpc_rb_channel);
127
+ wrapper->wrapped = NULL;
128
+ wrapper->mark = Qnil;
129
+ return TypedData_Wrap_Struct(cls, &grpc_channel_data_type, wrapper);
130
+ }
131
+
132
+ /*
133
+ call-seq:
134
+ insecure_channel = Channel:new("myhost:8080", {'arg1': 'value1'},
135
+ :this_channel_is_insecure)
136
+ creds = ...
137
+ secure_channel = Channel:new("myhost:443", {'arg1': 'value1'}, creds)
138
+
139
+ Creates channel instances. */
140
+ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
141
+ VALUE channel_args = Qnil;
142
+ VALUE credentials = Qnil;
143
+ VALUE target = Qnil;
144
+ grpc_rb_channel *wrapper = NULL;
145
+ grpc_channel *ch = NULL;
146
+ grpc_channel_credentials *creds = NULL;
147
+ char *target_chars = NULL;
148
+ grpc_channel_args args;
149
+ MEMZERO(&args, grpc_channel_args, 1);
150
+
151
+ /* "3" == 3 mandatory args */
152
+ rb_scan_args(argc, argv, "3", &target, &channel_args, &credentials);
153
+
154
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
155
+ target_chars = StringValueCStr(target);
156
+ grpc_rb_hash_convert_to_channel_args(channel_args, &args);
157
+ if (TYPE(credentials) == T_SYMBOL) {
158
+ if (id_insecure_channel != SYM2ID(credentials)) {
159
+ rb_raise(rb_eTypeError,
160
+ "bad creds symbol, want :this_channel_is_insecure");
161
+ return Qnil;
162
+ }
163
+ ch = grpc_insecure_channel_create(target_chars, &args, NULL);
164
+ } else {
165
+ creds = grpc_rb_get_wrapped_channel_credentials(credentials);
166
+ ch = grpc_secure_channel_create(creds, target_chars, &args, NULL);
167
+ }
168
+ if (args.args != NULL) {
169
+ xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
170
+ }
171
+ if (ch == NULL) {
172
+ rb_raise(rb_eRuntimeError, "could not create an rpc channel to target:%s",
173
+ target_chars);
174
+ return Qnil;
175
+ }
176
+ rb_ivar_set(self, id_target, target);
177
+ wrapper->wrapped = ch;
178
+ return self;
179
+ }
180
+
181
+ /*
182
+ call-seq:
183
+ insecure_channel = Channel:new("myhost:8080", {'arg1': 'value1'})
184
+ creds = ...
185
+ secure_channel = Channel:new("myhost:443", {'arg1': 'value1'}, creds)
186
+
187
+ Creates channel instances. */
188
+ static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE *argv,
189
+ VALUE self) {
190
+ VALUE try_to_connect = Qfalse;
191
+ grpc_rb_channel *wrapper = NULL;
192
+ grpc_channel *ch = NULL;
193
+
194
+ /* "01" == 0 mandatory args, 1 (try_to_connect) is optional */
195
+ rb_scan_args(argc, argv, "01", try_to_connect);
196
+
197
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
198
+ ch = wrapper->wrapped;
199
+ if (ch == NULL) {
200
+ rb_raise(rb_eRuntimeError, "closed!");
201
+ return Qnil;
202
+ }
203
+ return NUM2LONG(
204
+ grpc_channel_check_connectivity_state(ch, (int)try_to_connect));
205
+ }
206
+
207
+ /* Watch for a change in connectivity state.
208
+
209
+ Once the channel connectivity state is different from the last observed
210
+ state, tag will be enqueued on cq with success=1
211
+
212
+ If deadline expires BEFORE the state is changed, tag will be enqueued on
213
+ the completion queue with success=0 */
214
+ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
215
+ VALUE last_state,
216
+ VALUE cqueue,
217
+ VALUE deadline,
218
+ VALUE tag) {
219
+ grpc_rb_channel *wrapper = NULL;
220
+ grpc_channel *ch = NULL;
221
+ grpc_completion_queue *cq = NULL;
222
+
223
+ cq = grpc_rb_get_wrapped_completion_queue(cqueue);
224
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
225
+ ch = wrapper->wrapped;
226
+ if (ch == NULL) {
227
+ rb_raise(rb_eRuntimeError, "closed!");
228
+ return Qnil;
229
+ }
230
+ grpc_channel_watch_connectivity_state(
231
+ ch,
232
+ (grpc_connectivity_state)NUM2LONG(last_state),
233
+ grpc_rb_time_timeval(deadline, /* absolute time */ 0),
234
+ cq,
235
+ ROBJECT(tag));
236
+
237
+ return Qnil;
238
+ }
239
+
240
+ /* Clones Channel instances.
241
+
242
+ Gives Channel a consistent implementation of Ruby's object copy/dup
243
+ protocol. */
244
+ static VALUE grpc_rb_channel_init_copy(VALUE copy, VALUE orig) {
245
+ grpc_rb_channel *orig_ch = NULL;
246
+ grpc_rb_channel *copy_ch = NULL;
247
+
248
+ if (copy == orig) {
249
+ return copy;
250
+ }
251
+
252
+ /* Raise an error if orig is not a channel object or a subclass. */
253
+ if (TYPE(orig) != T_DATA ||
254
+ RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_free) {
255
+ rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cChannel));
256
+ return Qnil;
257
+ }
258
+
259
+ TypedData_Get_Struct(orig, grpc_rb_channel, &grpc_channel_data_type, orig_ch);
260
+ TypedData_Get_Struct(copy, grpc_rb_channel, &grpc_channel_data_type, copy_ch);
261
+
262
+ /* use ruby's MEMCPY to make a byte-for-byte copy of the channel wrapper
263
+ * object. */
264
+ MEMCPY(copy_ch, orig_ch, grpc_rb_channel, 1);
265
+ return copy;
266
+ }
267
+
268
+ /* Create a call given a grpc_channel, in order to call method. The request
269
+ is not sent until grpc_call_invoke is called. */
270
+ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE cqueue,
271
+ VALUE parent, VALUE mask,
272
+ VALUE method, VALUE host,
273
+ VALUE deadline) {
274
+ VALUE res = Qnil;
275
+ grpc_rb_channel *wrapper = NULL;
276
+ grpc_call *call = NULL;
277
+ grpc_call *parent_call = NULL;
278
+ grpc_channel *ch = NULL;
279
+ grpc_completion_queue *cq = NULL;
280
+ int flags = GRPC_PROPAGATE_DEFAULTS;
281
+ char *method_chars = StringValueCStr(method);
282
+ char *host_chars = NULL;
283
+ if (host != Qnil) {
284
+ host_chars = StringValueCStr(host);
285
+ }
286
+ if (mask != Qnil) {
287
+ flags = NUM2UINT(mask);
288
+ }
289
+ if (parent != Qnil) {
290
+ parent_call = grpc_rb_get_wrapped_call(parent);
291
+ }
292
+
293
+ cq = grpc_rb_get_wrapped_completion_queue(cqueue);
294
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
295
+ ch = wrapper->wrapped;
296
+ if (ch == NULL) {
297
+ rb_raise(rb_eRuntimeError, "closed!");
298
+ return Qnil;
299
+ }
300
+
301
+ call = grpc_channel_create_call(ch, parent_call, flags, cq, method_chars,
302
+ host_chars, grpc_rb_time_timeval(
303
+ deadline,
304
+ /* absolute time */ 0), NULL);
305
+ if (call == NULL) {
306
+ rb_raise(rb_eRuntimeError, "cannot create call with method %s",
307
+ method_chars);
308
+ return Qnil;
309
+ }
310
+ res = grpc_rb_wrap_call(call);
311
+
312
+ /* Make this channel an instance attribute of the call so that it is not GCed
313
+ * before the call. */
314
+ rb_ivar_set(res, id_channel, self);
315
+
316
+ /* Make the completion queue an instance attribute of the call so that it is
317
+ * not GCed before the call. */
318
+ rb_ivar_set(res, id_cqueue, cqueue);
319
+ return res;
320
+ }
321
+
322
+
323
+ /* Closes the channel, calling it's destroy method */
324
+ static VALUE grpc_rb_channel_destroy(VALUE self) {
325
+ grpc_rb_channel *wrapper = NULL;
326
+ grpc_channel *ch = NULL;
327
+
328
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
329
+ ch = wrapper->wrapped;
330
+ if (ch != NULL) {
331
+ grpc_channel_destroy(ch);
332
+ wrapper->wrapped = NULL;
333
+ wrapper->mark = Qnil;
334
+ }
335
+
336
+ return Qnil;
337
+ }
338
+
339
+
340
+ /* Called to obtain the target that this channel accesses. */
341
+ static VALUE grpc_rb_channel_get_target(VALUE self) {
342
+ grpc_rb_channel *wrapper = NULL;
343
+ VALUE res = Qnil;
344
+ char* target = NULL;
345
+
346
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
347
+ target = grpc_channel_get_target(wrapper->wrapped);
348
+ res = rb_str_new2(target);
349
+ gpr_free(target);
350
+
351
+ return res;
352
+ }
353
+
354
+ static void Init_grpc_propagate_masks() {
355
+ /* Constants representing call propagation masks in grpc.h */
356
+ VALUE grpc_rb_mPropagateMasks = rb_define_module_under(
357
+ grpc_rb_mGrpcCore, "PropagateMasks");
358
+ rb_define_const(grpc_rb_mPropagateMasks, "DEADLINE",
359
+ UINT2NUM(GRPC_PROPAGATE_DEADLINE));
360
+ rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_STATS_CONTEXT",
361
+ UINT2NUM(GRPC_PROPAGATE_CENSUS_STATS_CONTEXT));
362
+ rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_TRACING_CONTEXT",
363
+ UINT2NUM(GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT));
364
+ rb_define_const(grpc_rb_mPropagateMasks, "CANCELLATION",
365
+ UINT2NUM(GRPC_PROPAGATE_CANCELLATION));
366
+ rb_define_const(grpc_rb_mPropagateMasks, "DEFAULTS",
367
+ UINT2NUM(GRPC_PROPAGATE_DEFAULTS));
368
+ }
369
+
370
+ static void Init_grpc_connectivity_states() {
371
+ /* Constants representing call propagation masks in grpc.h */
372
+ VALUE grpc_rb_mConnectivityStates = rb_define_module_under(
373
+ grpc_rb_mGrpcCore, "ConnectivityStates");
374
+ rb_define_const(grpc_rb_mConnectivityStates, "IDLE",
375
+ LONG2NUM(GRPC_CHANNEL_IDLE));
376
+ rb_define_const(grpc_rb_mConnectivityStates, "CONNECTING",
377
+ LONG2NUM(GRPC_CHANNEL_CONNECTING));
378
+ rb_define_const(grpc_rb_mConnectivityStates, "READY",
379
+ LONG2NUM(GRPC_CHANNEL_READY));
380
+ rb_define_const(grpc_rb_mConnectivityStates, "TRANSIENT_FAILURE",
381
+ LONG2NUM(GRPC_CHANNEL_TRANSIENT_FAILURE));
382
+ rb_define_const(grpc_rb_mConnectivityStates, "FATAL_FAILURE",
383
+ LONG2NUM(GRPC_CHANNEL_FATAL_FAILURE));
384
+ }
385
+
386
+ void Init_grpc_channel() {
387
+ grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
388
+ grpc_rb_cChannel =
389
+ rb_define_class_under(grpc_rb_mGrpcCore, "Channel", rb_cObject);
390
+
391
+ /* Allocates an object managed by the ruby runtime */
392
+ rb_define_alloc_func(grpc_rb_cChannel, grpc_rb_channel_alloc);
393
+
394
+ /* Provides a ruby constructor and support for dup/clone. */
395
+ rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1);
396
+ rb_define_method(grpc_rb_cChannel, "initialize_copy",
397
+ grpc_rb_channel_init_copy, 1);
398
+
399
+ /* Add ruby analogues of the Channel methods. */
400
+ rb_define_method(grpc_rb_cChannel, "connectivity_state",
401
+ grpc_rb_channel_get_connectivity_state,
402
+ -1);
403
+ rb_define_method(grpc_rb_cChannel, "watch_connectivity_state",
404
+ grpc_rb_channel_watch_connectivity_state, 4);
405
+ rb_define_method(grpc_rb_cChannel, "create_call",
406
+ grpc_rb_channel_create_call, 6);
407
+ rb_define_method(grpc_rb_cChannel, "target", grpc_rb_channel_get_target, 0);
408
+ rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0);
409
+ rb_define_alias(grpc_rb_cChannel, "close", "destroy");
410
+
411
+ id_channel = rb_intern("__channel");
412
+ id_cqueue = rb_intern("__cqueue");
413
+ id_target = rb_intern("__target");
414
+ rb_define_const(grpc_rb_cChannel, "SSL_TARGET",
415
+ ID2SYM(rb_intern(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
416
+ rb_define_const(grpc_rb_cChannel, "ENABLE_CENSUS",
417
+ ID2SYM(rb_intern(GRPC_ARG_ENABLE_CENSUS)));
418
+ rb_define_const(grpc_rb_cChannel, "MAX_CONCURRENT_STREAMS",
419
+ ID2SYM(rb_intern(GRPC_ARG_MAX_CONCURRENT_STREAMS)));
420
+ rb_define_const(grpc_rb_cChannel, "MAX_MESSAGE_LENGTH",
421
+ ID2SYM(rb_intern(GRPC_ARG_MAX_MESSAGE_LENGTH)));
422
+ id_insecure_channel = rb_intern("this_channel_is_insecure");
423
+ Init_grpc_propagate_masks();
424
+ Init_grpc_connectivity_states();
425
+ }
426
+
427
+ /* Gets the wrapped channel from the ruby wrapper */
428
+ grpc_channel *grpc_rb_get_wrapped_channel(VALUE v) {
429
+ grpc_rb_channel *wrapper = NULL;
430
+ TypedData_Get_Struct(v, grpc_rb_channel, &grpc_channel_data_type, wrapper);
431
+ return wrapper->wrapped;
432
+ }