grpc 1.42.0.pre1-x86_64-darwin

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 (128) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +123 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  17. data/src/ruby/ext/grpc/rb_call.h +57 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +846 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +605 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +913 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +385 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  43. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  44. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  45. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  46. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  47. data/src/ruby/lib/grpc/2.4/grpc_c.bundle +0 -0
  48. data/src/ruby/lib/grpc/2.5/grpc_c.bundle +0 -0
  49. data/src/ruby/lib/grpc/2.6/grpc_c.bundle +0 -0
  50. data/src/ruby/lib/grpc/2.7/grpc_c.bundle +0 -0
  51. data/src/ruby/lib/grpc/3.0/grpc_c.bundle +0 -0
  52. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  53. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  54. data/src/ruby/lib/grpc/errors.rb +277 -0
  55. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  56. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  57. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  58. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  59. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  60. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  61. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  62. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  63. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  64. data/src/ruby/lib/grpc/grpc.rb +24 -0
  65. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  66. data/src/ruby/lib/grpc/notifier.rb +45 -0
  67. data/src/ruby/lib/grpc/structs.rb +15 -0
  68. data/src/ruby/lib/grpc/version.rb +18 -0
  69. data/src/ruby/lib/grpc.rb +37 -0
  70. data/src/ruby/pb/README.md +42 -0
  71. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  72. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  73. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  74. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  75. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  76. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  77. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +145 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  82. data/src/ruby/pb/test/client.rb +769 -0
  83. data/src/ruby/pb/test/server.rb +252 -0
  84. data/src/ruby/pb/test/xds_client.rb +415 -0
  85. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  86. data/src/ruby/spec/call_spec.rb +180 -0
  87. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  88. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  89. data/src/ruby/spec/channel_spec.rb +245 -0
  90. data/src/ruby/spec/client_auth_spec.rb +152 -0
  91. data/src/ruby/spec/client_server_spec.rb +664 -0
  92. data/src/ruby/spec/compression_options_spec.rb +149 -0
  93. data/src/ruby/spec/debug_message_spec.rb +134 -0
  94. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  95. data/src/ruby/spec/errors_spec.rb +142 -0
  96. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  97. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  98. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  99. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  100. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  101. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  102. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  103. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  104. data/src/ruby/spec/generic/service_spec.rb +263 -0
  105. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  112. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  113. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  114. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  115. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  116. data/src/ruby/spec/server_spec.rb +231 -0
  117. data/src/ruby/spec/spec_helper.rb +61 -0
  118. data/src/ruby/spec/support/helpers.rb +107 -0
  119. data/src/ruby/spec/support/services.rb +160 -0
  120. data/src/ruby/spec/testdata/README +1 -0
  121. data/src/ruby/spec/testdata/ca.pem +20 -0
  122. data/src/ruby/spec/testdata/client.key +28 -0
  123. data/src/ruby/spec/testdata/client.pem +20 -0
  124. data/src/ruby/spec/testdata/server1.key +28 -0
  125. data/src/ruby/spec/testdata/server1.pem +22 -0
  126. data/src/ruby/spec/time_consts_spec.rb +74 -0
  127. data/src/ruby/spec/user_agent_spec.rb +74 -0
  128. metadata +404 -0
@@ -0,0 +1,846 @@
1
+ /*
2
+ *
3
+ * Copyright 2015 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <ruby/ruby.h>
20
+
21
+ #include "rb_channel.h"
22
+
23
+ #include <ruby/thread.h>
24
+
25
+ #include "rb_byte_buffer.h"
26
+ #include "rb_call.h"
27
+ #include "rb_channel_args.h"
28
+ #include "rb_channel_credentials.h"
29
+ #include "rb_completion_queue.h"
30
+ #include "rb_grpc.h"
31
+ #include "rb_grpc_imports.generated.h"
32
+ #include "rb_server.h"
33
+ #include "rb_xds_channel_credentials.h"
34
+
35
+ #include <grpc/grpc.h>
36
+ #include <grpc/grpc_security.h>
37
+ #include <grpc/support/alloc.h>
38
+ #include <grpc/support/log.h>
39
+ #include <grpc/support/time.h>
40
+
41
+ /* id_channel is the name of the hidden ivar that preserves a reference to the
42
+ * channel on a call, so that calls are not GCed before their channel. */
43
+ static ID id_channel;
44
+
45
+ /* id_target is the name of the hidden ivar that preserves a reference to the
46
+ * target string used to create the call, preserved so that it does not get
47
+ * GCed before the channel */
48
+ static ID id_target;
49
+
50
+ /* id_insecure_channel is used to indicate that a channel is insecure */
51
+ static VALUE id_insecure_channel;
52
+
53
+ /* grpc_rb_cChannel is the ruby class that proxies grpc_channel. */
54
+ static VALUE grpc_rb_cChannel = Qnil;
55
+
56
+ /* Used during the conversion of a hash to channel args during channel setup */
57
+ static VALUE grpc_rb_cChannelArgs;
58
+
59
+ typedef struct bg_watched_channel {
60
+ grpc_channel* channel;
61
+ // these fields must only be accessed under global_connection_polling_mu
62
+ struct bg_watched_channel* next;
63
+ int channel_destroyed;
64
+ int refcount;
65
+ } bg_watched_channel;
66
+
67
+ /* grpc_rb_channel wraps a grpc_channel. */
68
+ typedef struct grpc_rb_channel {
69
+ VALUE credentials;
70
+
71
+ /* The actual channel (protected in a wrapper to tell when it's safe to
72
+ * destroy) */
73
+ bg_watched_channel* bg_wrapped;
74
+ } grpc_rb_channel;
75
+
76
+ typedef enum { CONTINUOUS_WATCH, WATCH_STATE_API } watch_state_op_type;
77
+
78
+ typedef struct watch_state_op {
79
+ watch_state_op_type op_type;
80
+ // from event.success
81
+ union {
82
+ struct {
83
+ int success;
84
+ // has been called back due to a cq next call
85
+ int called_back;
86
+ } api_callback_args;
87
+ struct {
88
+ bg_watched_channel* bg;
89
+ } continuous_watch_callback_args;
90
+ } op;
91
+ } watch_state_op;
92
+
93
+ static bg_watched_channel* bg_watched_channel_list_head = NULL;
94
+
95
+ static void grpc_rb_channel_try_register_connection_polling(
96
+ bg_watched_channel* bg);
97
+ static void* wait_until_channel_polling_thread_started_no_gil(void*);
98
+ static void wait_until_channel_polling_thread_started_unblocking_func(void*);
99
+ static void* channel_init_try_register_connection_polling_without_gil(
100
+ void* arg);
101
+
102
+ typedef struct channel_init_try_register_stack {
103
+ grpc_channel* channel;
104
+ grpc_rb_channel* wrapper;
105
+ } channel_init_try_register_stack;
106
+
107
+ static grpc_completion_queue* channel_polling_cq;
108
+ static gpr_mu global_connection_polling_mu;
109
+ static gpr_cv global_connection_polling_cv;
110
+ static int abort_channel_polling = 0;
111
+ static int channel_polling_thread_started = 0;
112
+
113
+ static int bg_watched_channel_list_lookup(bg_watched_channel* bg);
114
+ static bg_watched_channel* bg_watched_channel_list_create_and_add(
115
+ grpc_channel* channel);
116
+ static void bg_watched_channel_list_free_and_remove(bg_watched_channel* bg);
117
+ static void run_poll_channels_loop_unblocking_func(void* arg);
118
+
119
+ // Needs to be called under global_connection_polling_mu
120
+ static void grpc_rb_channel_watch_connection_state_op_complete(
121
+ watch_state_op* op, int success) {
122
+ GPR_ASSERT(!op->op.api_callback_args.called_back);
123
+ op->op.api_callback_args.called_back = 1;
124
+ op->op.api_callback_args.success = success;
125
+ // wake up the watch API call that's waiting on this op
126
+ gpr_cv_broadcast(&global_connection_polling_cv);
127
+ }
128
+
129
+ /* Avoids destroying a channel twice. */
130
+ static void grpc_rb_channel_safe_destroy(bg_watched_channel* bg) {
131
+ gpr_mu_lock(&global_connection_polling_mu);
132
+ GPR_ASSERT(bg_watched_channel_list_lookup(bg));
133
+ if (!bg->channel_destroyed) {
134
+ grpc_channel_destroy(bg->channel);
135
+ bg->channel_destroyed = 1;
136
+ }
137
+ bg->refcount--;
138
+ if (bg->refcount == 0) {
139
+ bg_watched_channel_list_free_and_remove(bg);
140
+ }
141
+ gpr_mu_unlock(&global_connection_polling_mu);
142
+ }
143
+
144
+ static void* channel_safe_destroy_without_gil(void* arg) {
145
+ grpc_rb_channel_safe_destroy((bg_watched_channel*)arg);
146
+ return NULL;
147
+ }
148
+
149
+ static void grpc_rb_channel_free_internal(void* p) {
150
+ grpc_rb_channel* ch = NULL;
151
+ if (p == NULL) {
152
+ return;
153
+ };
154
+ ch = (grpc_rb_channel*)p;
155
+ if (ch->bg_wrapped != NULL) {
156
+ /* assumption made here: it's ok to directly gpr_mu_lock the global
157
+ * connection polling mutex because we're in a finalizer,
158
+ * and we can count on this thread to not be interrupted or
159
+ * yield the gil. */
160
+ grpc_rb_channel_safe_destroy(ch->bg_wrapped);
161
+ ch->bg_wrapped = NULL;
162
+ }
163
+ xfree(p);
164
+ }
165
+
166
+ /* Destroys Channel instances. */
167
+ static void grpc_rb_channel_free(void* p) {
168
+ grpc_rb_channel_free_internal(p);
169
+ grpc_ruby_shutdown();
170
+ }
171
+
172
+ /* Protects the mark object from GC */
173
+ static void grpc_rb_channel_mark(void* p) {
174
+ grpc_rb_channel* channel = NULL;
175
+ if (p == NULL) {
176
+ return;
177
+ }
178
+ channel = (grpc_rb_channel*)p;
179
+ if (channel->credentials != Qnil) {
180
+ rb_gc_mark(channel->credentials);
181
+ }
182
+ }
183
+
184
+ static rb_data_type_t grpc_channel_data_type = {"grpc_channel",
185
+ {grpc_rb_channel_mark,
186
+ grpc_rb_channel_free,
187
+ GRPC_RB_MEMSIZE_UNAVAILABLE,
188
+ {NULL, NULL}},
189
+ NULL,
190
+ NULL,
191
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
192
+ RUBY_TYPED_FREE_IMMEDIATELY
193
+ #endif
194
+ };
195
+
196
+ /* Allocates grpc_rb_channel instances. */
197
+ static VALUE grpc_rb_channel_alloc(VALUE cls) {
198
+ grpc_ruby_init();
199
+ grpc_rb_channel* wrapper = ALLOC(grpc_rb_channel);
200
+ wrapper->bg_wrapped = NULL;
201
+ wrapper->credentials = Qnil;
202
+ return TypedData_Wrap_Struct(cls, &grpc_channel_data_type, wrapper);
203
+ }
204
+
205
+ /*
206
+ call-seq:
207
+ insecure_channel = Channel:new("myhost:8080", {'arg1': 'value1'},
208
+ :this_channel_is_insecure)
209
+ creds = ...
210
+ secure_channel = Channel:new("myhost:443", {'arg1': 'value1'}, creds)
211
+
212
+ Creates channel instances. */
213
+ static VALUE grpc_rb_channel_init(int argc, VALUE* argv, VALUE self) {
214
+ VALUE channel_args = Qnil;
215
+ VALUE credentials = Qnil;
216
+ VALUE target = Qnil;
217
+ grpc_rb_channel* wrapper = NULL;
218
+ grpc_channel* ch = NULL;
219
+ grpc_channel_credentials* creds = NULL;
220
+ char* target_chars = NULL;
221
+ grpc_channel_args args;
222
+ channel_init_try_register_stack stack;
223
+ int stop_waiting_for_thread_start = 0;
224
+ MEMZERO(&args, grpc_channel_args, 1);
225
+
226
+ grpc_ruby_fork_guard();
227
+ rb_thread_call_without_gvl(
228
+ wait_until_channel_polling_thread_started_no_gil,
229
+ &stop_waiting_for_thread_start,
230
+ wait_until_channel_polling_thread_started_unblocking_func,
231
+ &stop_waiting_for_thread_start);
232
+
233
+ /* "3" == 3 mandatory args */
234
+ rb_scan_args(argc, argv, "3", &target, &channel_args, &credentials);
235
+
236
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
237
+ target_chars = StringValueCStr(target);
238
+ grpc_rb_hash_convert_to_channel_args(channel_args, &args);
239
+ if (TYPE(credentials) == T_SYMBOL) {
240
+ if (id_insecure_channel != SYM2ID(credentials)) {
241
+ rb_raise(rb_eTypeError,
242
+ "bad creds symbol, want :this_channel_is_insecure");
243
+ return Qnil;
244
+ }
245
+ ch = grpc_insecure_channel_create(target_chars, &args, NULL);
246
+ } else {
247
+ wrapper->credentials = credentials;
248
+ if (grpc_rb_is_channel_credentials(credentials)) {
249
+ creds = grpc_rb_get_wrapped_channel_credentials(credentials);
250
+ } else if (grpc_rb_is_xds_channel_credentials(credentials)) {
251
+ creds = grpc_rb_get_wrapped_xds_channel_credentials(credentials);
252
+ } else {
253
+ rb_raise(rb_eTypeError,
254
+ "bad creds, want ChannelCredentials or XdsChannelCredentials");
255
+ return Qnil;
256
+ }
257
+ ch = grpc_secure_channel_create(creds, target_chars, &args, NULL);
258
+ }
259
+
260
+ GPR_ASSERT(ch);
261
+ stack.channel = ch;
262
+ stack.wrapper = wrapper;
263
+ rb_thread_call_without_gvl(
264
+ channel_init_try_register_connection_polling_without_gil, &stack, NULL,
265
+ NULL);
266
+
267
+ if (args.args != NULL) {
268
+ xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
269
+ }
270
+ if (ch == NULL) {
271
+ rb_raise(rb_eRuntimeError, "could not create an rpc channel to target:%s",
272
+ target_chars);
273
+ return Qnil;
274
+ }
275
+ rb_ivar_set(self, id_target, target);
276
+ return self;
277
+ }
278
+
279
+ typedef struct get_state_stack {
280
+ bg_watched_channel* bg;
281
+ int try_to_connect;
282
+ int out;
283
+ } get_state_stack;
284
+
285
+ static void* get_state_without_gil(void* arg) {
286
+ get_state_stack* stack = (get_state_stack*)arg;
287
+
288
+ gpr_mu_lock(&global_connection_polling_mu);
289
+ GPR_ASSERT(abort_channel_polling || channel_polling_thread_started);
290
+ if (stack->bg->channel_destroyed) {
291
+ stack->out = GRPC_CHANNEL_SHUTDOWN;
292
+ } else {
293
+ stack->out = grpc_channel_check_connectivity_state(stack->bg->channel,
294
+ stack->try_to_connect);
295
+ }
296
+ gpr_mu_unlock(&global_connection_polling_mu);
297
+
298
+ return NULL;
299
+ }
300
+
301
+ /*
302
+ call-seq:
303
+ ch.connectivity_state -> state
304
+ ch.connectivity_state(true) -> state
305
+
306
+ Indicates the current state of the channel, whose value is one of the
307
+ constants defined in GRPC::Core::ConnectivityStates.
308
+
309
+ It also tries to connect if the channel is idle in the second form. */
310
+ static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE* argv,
311
+ VALUE self) {
312
+ VALUE try_to_connect_param = Qfalse;
313
+ grpc_rb_channel* wrapper = NULL;
314
+ get_state_stack stack;
315
+
316
+ /* "01" == 0 mandatory args, 1 (try_to_connect) is optional */
317
+ rb_scan_args(argc, argv, "01", &try_to_connect_param);
318
+
319
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
320
+ if (wrapper->bg_wrapped == NULL) {
321
+ rb_raise(rb_eRuntimeError, "closed!");
322
+ return Qnil;
323
+ }
324
+
325
+ stack.bg = wrapper->bg_wrapped;
326
+ stack.try_to_connect = RTEST(try_to_connect_param) ? 1 : 0;
327
+ rb_thread_call_without_gvl(get_state_without_gil, &stack, NULL, NULL);
328
+
329
+ return LONG2NUM(stack.out);
330
+ }
331
+
332
+ typedef struct watch_state_stack {
333
+ bg_watched_channel* bg_wrapped;
334
+ gpr_timespec deadline;
335
+ int last_state;
336
+ } watch_state_stack;
337
+
338
+ static void* wait_for_watch_state_op_complete_without_gvl(void* arg) {
339
+ watch_state_stack* stack = (watch_state_stack*)arg;
340
+ watch_state_op* op = NULL;
341
+ void* success = (void*)0;
342
+
343
+ gpr_mu_lock(&global_connection_polling_mu);
344
+ // it's unsafe to do a "watch" after "channel polling abort" because the cq
345
+ // has been shut down.
346
+ if (abort_channel_polling || stack->bg_wrapped->channel_destroyed) {
347
+ gpr_mu_unlock(&global_connection_polling_mu);
348
+ return (void*)0;
349
+ }
350
+ op = gpr_zalloc(sizeof(watch_state_op));
351
+ op->op_type = WATCH_STATE_API;
352
+ grpc_channel_watch_connectivity_state(stack->bg_wrapped->channel,
353
+ stack->last_state, stack->deadline,
354
+ channel_polling_cq, op);
355
+
356
+ while (!op->op.api_callback_args.called_back) {
357
+ gpr_cv_wait(&global_connection_polling_cv, &global_connection_polling_mu,
358
+ gpr_inf_future(GPR_CLOCK_REALTIME));
359
+ }
360
+ if (op->op.api_callback_args.success) {
361
+ success = (void*)1;
362
+ }
363
+ gpr_free(op);
364
+ gpr_mu_unlock(&global_connection_polling_mu);
365
+
366
+ return success;
367
+ }
368
+ static void wait_for_watch_state_op_complete_unblocking_func(void* arg) {
369
+ bg_watched_channel* bg = (bg_watched_channel*)arg;
370
+ gpr_mu_lock(&global_connection_polling_mu);
371
+ if (!bg->channel_destroyed) {
372
+ grpc_channel_destroy(bg->channel);
373
+ bg->channel_destroyed = 1;
374
+ }
375
+ gpr_mu_unlock(&global_connection_polling_mu);
376
+ }
377
+
378
+ /* Wait until the channel's connectivity state becomes different from
379
+ * "last_state", or "deadline" expires.
380
+ * Returns true if the channel's connectivity state becomes different
381
+ * from "last_state" within "deadline".
382
+ * Returns false if "deadline" expires before the channel's connectivity
383
+ * state changes from "last_state".
384
+ * */
385
+ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
386
+ VALUE last_state,
387
+ VALUE deadline) {
388
+ grpc_rb_channel* wrapper = NULL;
389
+ watch_state_stack stack;
390
+ void* op_success = 0;
391
+
392
+ grpc_ruby_fork_guard();
393
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
394
+
395
+ if (wrapper->bg_wrapped == NULL) {
396
+ rb_raise(rb_eRuntimeError, "closed!");
397
+ return Qnil;
398
+ }
399
+
400
+ if (!FIXNUM_P(last_state)) {
401
+ rb_raise(
402
+ rb_eTypeError,
403
+ "bad type for last_state. want a GRPC::Core::ChannelState constant");
404
+ return Qnil;
405
+ }
406
+
407
+ stack.bg_wrapped = wrapper->bg_wrapped;
408
+ stack.deadline = grpc_rb_time_timeval(deadline, 0),
409
+ stack.last_state = NUM2LONG(last_state);
410
+
411
+ op_success = rb_thread_call_without_gvl(
412
+ wait_for_watch_state_op_complete_without_gvl, &stack,
413
+ wait_for_watch_state_op_complete_unblocking_func, wrapper->bg_wrapped);
414
+
415
+ return op_success ? Qtrue : Qfalse;
416
+ }
417
+
418
+ /* Create a call given a grpc_channel, in order to call method. The request
419
+ is not sent until grpc_call_invoke is called. */
420
+ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
421
+ VALUE method, VALUE host,
422
+ VALUE deadline) {
423
+ VALUE res = Qnil;
424
+ grpc_rb_channel* wrapper = NULL;
425
+ grpc_call* call = NULL;
426
+ grpc_call* parent_call = NULL;
427
+ grpc_completion_queue* cq = NULL;
428
+ int flags = GRPC_PROPAGATE_DEFAULTS;
429
+ grpc_slice method_slice;
430
+ grpc_slice host_slice;
431
+ grpc_slice* host_slice_ptr = NULL;
432
+ char* tmp_str = NULL;
433
+
434
+ grpc_ruby_fork_guard();
435
+ if (host != Qnil) {
436
+ host_slice =
437
+ grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host));
438
+ host_slice_ptr = &host_slice;
439
+ }
440
+ if (mask != Qnil) {
441
+ flags = NUM2UINT(mask);
442
+ }
443
+ if (parent != Qnil) {
444
+ parent_call = grpc_rb_get_wrapped_call(parent);
445
+ }
446
+
447
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
448
+ if (wrapper->bg_wrapped == NULL) {
449
+ rb_raise(rb_eRuntimeError, "closed!");
450
+ return Qnil;
451
+ }
452
+
453
+ cq = grpc_completion_queue_create_for_pluck(NULL);
454
+ method_slice =
455
+ grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method));
456
+ call = grpc_channel_create_call(wrapper->bg_wrapped->channel, parent_call,
457
+ flags, cq, method_slice, host_slice_ptr,
458
+ grpc_rb_time_timeval(deadline,
459
+ /* absolute time */ 0),
460
+ NULL);
461
+
462
+ if (call == NULL) {
463
+ tmp_str = grpc_slice_to_c_string(method_slice);
464
+ rb_raise(rb_eRuntimeError, "cannot create call with method %s", tmp_str);
465
+ return Qnil;
466
+ }
467
+
468
+ grpc_slice_unref(method_slice);
469
+ if (host_slice_ptr != NULL) {
470
+ grpc_slice_unref(host_slice);
471
+ }
472
+
473
+ res = grpc_rb_wrap_call(call, cq);
474
+
475
+ /* Make this channel an instance attribute of the call so that it is not GCed
476
+ * before the call. */
477
+ rb_ivar_set(res, id_channel, self);
478
+ return res;
479
+ }
480
+
481
+ /* Closes the channel, calling it's destroy method */
482
+ /* Note this is an API-level call; a wrapped channel's finalizer doesn't call
483
+ * this */
484
+ static VALUE grpc_rb_channel_destroy(VALUE self) {
485
+ grpc_rb_channel* wrapper = NULL;
486
+
487
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
488
+ if (wrapper->bg_wrapped != NULL) {
489
+ rb_thread_call_without_gvl(channel_safe_destroy_without_gil,
490
+ wrapper->bg_wrapped, NULL, NULL);
491
+ wrapper->bg_wrapped = NULL;
492
+ }
493
+
494
+ return Qnil;
495
+ }
496
+
497
+ /* Called to obtain the target that this channel accesses. */
498
+ static VALUE grpc_rb_channel_get_target(VALUE self) {
499
+ grpc_rb_channel* wrapper = NULL;
500
+ VALUE res = Qnil;
501
+ char* target = NULL;
502
+
503
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
504
+ target = grpc_channel_get_target(wrapper->bg_wrapped->channel);
505
+ res = rb_str_new2(target);
506
+ gpr_free(target);
507
+
508
+ return res;
509
+ }
510
+
511
+ /* Needs to be called under global_connection_polling_mu */
512
+ static int bg_watched_channel_list_lookup(bg_watched_channel* target) {
513
+ bg_watched_channel* cur = bg_watched_channel_list_head;
514
+
515
+ while (cur != NULL) {
516
+ if (cur == target) {
517
+ return 1;
518
+ }
519
+ cur = cur->next;
520
+ }
521
+
522
+ return 0;
523
+ }
524
+
525
+ /* Needs to be called under global_connection_polling_mu */
526
+ static bg_watched_channel* bg_watched_channel_list_create_and_add(
527
+ grpc_channel* channel) {
528
+ bg_watched_channel* watched = gpr_zalloc(sizeof(bg_watched_channel));
529
+
530
+ watched->channel = channel;
531
+ watched->next = bg_watched_channel_list_head;
532
+ watched->refcount = 1;
533
+ bg_watched_channel_list_head = watched;
534
+ return watched;
535
+ }
536
+
537
+ /* Needs to be called under global_connection_polling_mu */
538
+ static void bg_watched_channel_list_free_and_remove(
539
+ bg_watched_channel* target) {
540
+ bg_watched_channel* bg = NULL;
541
+
542
+ GPR_ASSERT(bg_watched_channel_list_lookup(target));
543
+ GPR_ASSERT(target->channel_destroyed && target->refcount == 0);
544
+ if (bg_watched_channel_list_head == target) {
545
+ bg_watched_channel_list_head = target->next;
546
+ gpr_free(target);
547
+ return;
548
+ }
549
+ bg = bg_watched_channel_list_head;
550
+ while (bg != NULL && bg->next != NULL) {
551
+ if (bg->next == target) {
552
+ bg->next = bg->next->next;
553
+ gpr_free(target);
554
+ return;
555
+ }
556
+ bg = bg->next;
557
+ }
558
+ GPR_ASSERT(0);
559
+ }
560
+
561
+ /* Initialize a grpc_rb_channel's "protected grpc_channel" and try to push
562
+ * it onto the background thread for constant watches. */
563
+ static void* channel_init_try_register_connection_polling_without_gil(
564
+ void* arg) {
565
+ channel_init_try_register_stack* stack =
566
+ (channel_init_try_register_stack*)arg;
567
+
568
+ gpr_mu_lock(&global_connection_polling_mu);
569
+ stack->wrapper->bg_wrapped =
570
+ bg_watched_channel_list_create_and_add(stack->channel);
571
+ grpc_rb_channel_try_register_connection_polling(stack->wrapper->bg_wrapped);
572
+ gpr_mu_unlock(&global_connection_polling_mu);
573
+ return NULL;
574
+ }
575
+
576
+ // Needs to be called under global_connection_poolling_mu
577
+ static void grpc_rb_channel_try_register_connection_polling(
578
+ bg_watched_channel* bg) {
579
+ grpc_connectivity_state conn_state;
580
+ watch_state_op* op = NULL;
581
+
582
+ GPR_ASSERT(channel_polling_thread_started || abort_channel_polling);
583
+
584
+ if (bg->refcount == 0) {
585
+ GPR_ASSERT(bg->channel_destroyed);
586
+ bg_watched_channel_list_free_and_remove(bg);
587
+ return;
588
+ }
589
+ GPR_ASSERT(bg->refcount == 1);
590
+ if (bg->channel_destroyed || abort_channel_polling) {
591
+ return;
592
+ }
593
+
594
+ conn_state = grpc_channel_check_connectivity_state(bg->channel, 0);
595
+ if (conn_state == GRPC_CHANNEL_SHUTDOWN) {
596
+ return;
597
+ }
598
+ GPR_ASSERT(bg_watched_channel_list_lookup(bg));
599
+ // prevent bg from being free'd by GC while background thread is watching it
600
+ bg->refcount++;
601
+
602
+ op = gpr_zalloc(sizeof(watch_state_op));
603
+ op->op_type = CONTINUOUS_WATCH;
604
+ op->op.continuous_watch_callback_args.bg = bg;
605
+ grpc_channel_watch_connectivity_state(bg->channel, conn_state,
606
+ gpr_inf_future(GPR_CLOCK_REALTIME),
607
+ channel_polling_cq, op);
608
+ }
609
+
610
+ // Note this loop breaks out with a single call of
611
+ // "run_poll_channels_loop_no_gil".
612
+ // This assumes that a ruby call the unblocking func
613
+ // indicates process shutdown.
614
+ // In the worst case, this stops polling channel connectivity
615
+ // early and falls back to current behavior.
616
+ static void* run_poll_channels_loop_no_gil(void* arg) {
617
+ grpc_event event;
618
+ watch_state_op* op = NULL;
619
+ bg_watched_channel* bg = NULL;
620
+ (void)arg;
621
+ gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop_no_gil - begin");
622
+
623
+ gpr_mu_lock(&global_connection_polling_mu);
624
+ GPR_ASSERT(!channel_polling_thread_started);
625
+ channel_polling_thread_started = 1;
626
+ gpr_cv_broadcast(&global_connection_polling_cv);
627
+ gpr_mu_unlock(&global_connection_polling_mu);
628
+
629
+ for (;;) {
630
+ event = grpc_completion_queue_next(
631
+ channel_polling_cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
632
+ if (event.type == GRPC_QUEUE_SHUTDOWN) {
633
+ break;
634
+ }
635
+ gpr_mu_lock(&global_connection_polling_mu);
636
+ if (event.type == GRPC_OP_COMPLETE) {
637
+ op = (watch_state_op*)event.tag;
638
+ if (op->op_type == CONTINUOUS_WATCH) {
639
+ bg = (bg_watched_channel*)op->op.continuous_watch_callback_args.bg;
640
+ bg->refcount--;
641
+ grpc_rb_channel_try_register_connection_polling(bg);
642
+ gpr_free(op);
643
+ } else if (op->op_type == WATCH_STATE_API) {
644
+ grpc_rb_channel_watch_connection_state_op_complete(
645
+ (watch_state_op*)event.tag, event.success);
646
+ } else {
647
+ GPR_ASSERT(0);
648
+ }
649
+ }
650
+ gpr_mu_unlock(&global_connection_polling_mu);
651
+ }
652
+ grpc_completion_queue_destroy(channel_polling_cq);
653
+ gpr_log(GPR_DEBUG,
654
+ "GRPC_RUBY: run_poll_channels_loop_no_gil - exit connection polling "
655
+ "loop");
656
+ return NULL;
657
+ }
658
+
659
+ // Notify the channel polling loop to cleanup and shutdown.
660
+ static void run_poll_channels_loop_unblocking_func(void* arg) {
661
+ bg_watched_channel* bg = NULL;
662
+ (void)arg;
663
+
664
+ gpr_mu_lock(&global_connection_polling_mu);
665
+ gpr_log(GPR_DEBUG,
666
+ "GRPC_RUBY: run_poll_channels_loop_unblocking_func - begin aborting "
667
+ "connection polling");
668
+ // early out after first time through
669
+ if (abort_channel_polling) {
670
+ gpr_mu_unlock(&global_connection_polling_mu);
671
+ return;
672
+ }
673
+ abort_channel_polling = 1;
674
+
675
+ // force pending watches to end by switching to shutdown state
676
+ bg = bg_watched_channel_list_head;
677
+ while (bg != NULL) {
678
+ if (!bg->channel_destroyed) {
679
+ grpc_channel_destroy(bg->channel);
680
+ bg->channel_destroyed = 1;
681
+ }
682
+ bg = bg->next;
683
+ }
684
+
685
+ grpc_completion_queue_shutdown(channel_polling_cq);
686
+ gpr_cv_broadcast(&global_connection_polling_cv);
687
+ gpr_mu_unlock(&global_connection_polling_mu);
688
+ gpr_log(GPR_DEBUG,
689
+ "GRPC_RUBY: run_poll_channels_loop_unblocking_func - end aborting "
690
+ "connection polling");
691
+ }
692
+
693
+ // Poll channel connectivity states in background thread without the GIL.
694
+ static VALUE run_poll_channels_loop(VALUE arg) {
695
+ (void)arg;
696
+ gpr_log(
697
+ GPR_DEBUG,
698
+ "GRPC_RUBY: run_poll_channels_loop - create connection polling thread");
699
+ grpc_ruby_init();
700
+ rb_thread_call_without_gvl(run_poll_channels_loop_no_gil, NULL,
701
+ run_poll_channels_loop_unblocking_func, NULL);
702
+ grpc_ruby_shutdown();
703
+ return Qnil;
704
+ }
705
+
706
+ static void* wait_until_channel_polling_thread_started_no_gil(void* arg) {
707
+ int* stop_waiting = (int*)arg;
708
+ gpr_log(GPR_DEBUG, "GRPC_RUBY: wait for channel polling thread to start");
709
+ gpr_mu_lock(&global_connection_polling_mu);
710
+ while (!channel_polling_thread_started && !abort_channel_polling &&
711
+ !*stop_waiting) {
712
+ gpr_cv_wait(&global_connection_polling_cv, &global_connection_polling_mu,
713
+ gpr_inf_future(GPR_CLOCK_REALTIME));
714
+ }
715
+ gpr_mu_unlock(&global_connection_polling_mu);
716
+
717
+ return NULL;
718
+ }
719
+
720
+ static void wait_until_channel_polling_thread_started_unblocking_func(
721
+ void* arg) {
722
+ int* stop_waiting = (int*)arg;
723
+ gpr_mu_lock(&global_connection_polling_mu);
724
+ gpr_log(GPR_DEBUG,
725
+ "GRPC_RUBY: interrupt wait for channel polling thread to start");
726
+ *stop_waiting = 1;
727
+ gpr_cv_broadcast(&global_connection_polling_cv);
728
+ gpr_mu_unlock(&global_connection_polling_mu);
729
+ }
730
+
731
+ static void* set_abort_channel_polling_without_gil(void* arg) {
732
+ (void)arg;
733
+ gpr_mu_lock(&global_connection_polling_mu);
734
+ abort_channel_polling = 1;
735
+ gpr_cv_broadcast(&global_connection_polling_cv);
736
+ gpr_mu_unlock(&global_connection_polling_mu);
737
+ return NULL;
738
+ }
739
+
740
+ /* Temporary fix for
741
+ * https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/899.
742
+ * Transports in idle channels can get destroyed. Normally c-core re-connects,
743
+ * but in grpc-ruby core never gets a thread until an RPC is made, because ruby
744
+ * only calls c-core's "completion_queu_pluck" API.
745
+ * This uses a global background thread that calls
746
+ * "completion_queue_next" on registered "watch_channel_connectivity_state"
747
+ * calls - so that c-core can reconnect if needed, when there aren't any RPC's.
748
+ * TODO(apolcyn) remove this when core handles new RPCs on dead connections.
749
+ */
750
+ void grpc_rb_channel_polling_thread_start() {
751
+ VALUE background_thread = Qnil;
752
+
753
+ GPR_ASSERT(!abort_channel_polling);
754
+ GPR_ASSERT(!channel_polling_thread_started);
755
+ GPR_ASSERT(channel_polling_cq == NULL);
756
+
757
+ gpr_mu_init(&global_connection_polling_mu);
758
+ gpr_cv_init(&global_connection_polling_cv);
759
+
760
+ channel_polling_cq = grpc_completion_queue_create_for_next(NULL);
761
+ background_thread = rb_thread_create(run_poll_channels_loop, NULL);
762
+
763
+ if (!RTEST(background_thread)) {
764
+ gpr_log(GPR_DEBUG, "GRPC_RUBY: failed to spawn channel polling thread");
765
+ rb_thread_call_without_gvl(set_abort_channel_polling_without_gil, NULL,
766
+ NULL, NULL);
767
+ }
768
+ }
769
+
770
+ static void Init_grpc_propagate_masks() {
771
+ /* Constants representing call propagation masks in grpc.h */
772
+ VALUE grpc_rb_mPropagateMasks =
773
+ rb_define_module_under(grpc_rb_mGrpcCore, "PropagateMasks");
774
+ rb_define_const(grpc_rb_mPropagateMasks, "DEADLINE",
775
+ UINT2NUM(GRPC_PROPAGATE_DEADLINE));
776
+ rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_STATS_CONTEXT",
777
+ UINT2NUM(GRPC_PROPAGATE_CENSUS_STATS_CONTEXT));
778
+ rb_define_const(grpc_rb_mPropagateMasks, "CENSUS_TRACING_CONTEXT",
779
+ UINT2NUM(GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT));
780
+ rb_define_const(grpc_rb_mPropagateMasks, "CANCELLATION",
781
+ UINT2NUM(GRPC_PROPAGATE_CANCELLATION));
782
+ rb_define_const(grpc_rb_mPropagateMasks, "DEFAULTS",
783
+ UINT2NUM(GRPC_PROPAGATE_DEFAULTS));
784
+ }
785
+
786
+ static void Init_grpc_connectivity_states() {
787
+ /* Constants representing call propagation masks in grpc.h */
788
+ VALUE grpc_rb_mConnectivityStates =
789
+ rb_define_module_under(grpc_rb_mGrpcCore, "ConnectivityStates");
790
+ rb_define_const(grpc_rb_mConnectivityStates, "IDLE",
791
+ LONG2NUM(GRPC_CHANNEL_IDLE));
792
+ rb_define_const(grpc_rb_mConnectivityStates, "CONNECTING",
793
+ LONG2NUM(GRPC_CHANNEL_CONNECTING));
794
+ rb_define_const(grpc_rb_mConnectivityStates, "READY",
795
+ LONG2NUM(GRPC_CHANNEL_READY));
796
+ rb_define_const(grpc_rb_mConnectivityStates, "TRANSIENT_FAILURE",
797
+ LONG2NUM(GRPC_CHANNEL_TRANSIENT_FAILURE));
798
+ rb_define_const(grpc_rb_mConnectivityStates, "FATAL_FAILURE",
799
+ LONG2NUM(GRPC_CHANNEL_SHUTDOWN));
800
+ }
801
+
802
+ void Init_grpc_channel() {
803
+ grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
804
+ grpc_rb_cChannel =
805
+ rb_define_class_under(grpc_rb_mGrpcCore, "Channel", rb_cObject);
806
+
807
+ /* Allocates an object managed by the ruby runtime */
808
+ rb_define_alloc_func(grpc_rb_cChannel, grpc_rb_channel_alloc);
809
+
810
+ /* Provides a ruby constructor and support for dup/clone. */
811
+ rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1);
812
+ rb_define_method(grpc_rb_cChannel, "initialize_copy",
813
+ grpc_rb_cannot_init_copy, 1);
814
+
815
+ /* Add ruby analogues of the Channel methods. */
816
+ rb_define_method(grpc_rb_cChannel, "connectivity_state",
817
+ grpc_rb_channel_get_connectivity_state, -1);
818
+ rb_define_method(grpc_rb_cChannel, "watch_connectivity_state",
819
+ grpc_rb_channel_watch_connectivity_state, 2);
820
+ rb_define_method(grpc_rb_cChannel, "create_call", grpc_rb_channel_create_call,
821
+ 5);
822
+ rb_define_method(grpc_rb_cChannel, "target", grpc_rb_channel_get_target, 0);
823
+ rb_define_method(grpc_rb_cChannel, "destroy", grpc_rb_channel_destroy, 0);
824
+ rb_define_alias(grpc_rb_cChannel, "close", "destroy");
825
+
826
+ id_channel = rb_intern("__channel");
827
+ id_target = rb_intern("__target");
828
+ rb_define_const(grpc_rb_cChannel, "SSL_TARGET",
829
+ ID2SYM(rb_intern(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)));
830
+ rb_define_const(grpc_rb_cChannel, "ENABLE_CENSUS",
831
+ ID2SYM(rb_intern(GRPC_ARG_ENABLE_CENSUS)));
832
+ rb_define_const(grpc_rb_cChannel, "MAX_CONCURRENT_STREAMS",
833
+ ID2SYM(rb_intern(GRPC_ARG_MAX_CONCURRENT_STREAMS)));
834
+ rb_define_const(grpc_rb_cChannel, "MAX_MESSAGE_LENGTH",
835
+ ID2SYM(rb_intern(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH)));
836
+ id_insecure_channel = rb_intern("this_channel_is_insecure");
837
+ Init_grpc_propagate_masks();
838
+ Init_grpc_connectivity_states();
839
+ }
840
+
841
+ /* Gets the wrapped channel from the ruby wrapper */
842
+ grpc_channel* grpc_rb_get_wrapped_channel(VALUE v) {
843
+ grpc_rb_channel* wrapper = NULL;
844
+ TypedData_Get_Struct(v, grpc_rb_channel, &grpc_channel_data_type, wrapper);
845
+ return wrapper->bg_wrapped->channel;
846
+ }