wearefair-grpc 1.3.1.pre.c → 1.4.0.fair

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +418 -126
  3. data/include/grpc/grpc.h +15 -69
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/compression_types.h +3 -4
  6. data/include/grpc/impl/codegen/gpr_types.h +0 -1
  7. data/include/grpc/impl/codegen/grpc_types.h +69 -3
  8. data/include/grpc/impl/codegen/port_platform.h +6 -0
  9. data/include/grpc/impl/codegen/slice.h +2 -1
  10. data/include/grpc/load_reporting.h +6 -6
  11. data/include/grpc/slice.h +25 -3
  12. data/include/grpc/slice_buffer.h +4 -0
  13. data/src/core/ext/census/context.c +1 -1
  14. data/src/core/ext/census/resource.c +3 -1
  15. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  16. data/src/core/ext/filters/client_channel/client_channel.c +158 -100
  17. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  18. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  19. data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  29. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  33. data/src/core/ext/filters/client_channel/parse_address.c +37 -7
  34. data/src/core/ext/filters/client_channel/parse_address.h +11 -8
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  36. data/src/core/ext/filters/client_channel/subchannel.c +19 -16
  37. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  38. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  39. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  40. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  41. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  42. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  43. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  44. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  45. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  46. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  47. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  48. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  49. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  50. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  51. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  52. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  53. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  54. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  57. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  58. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
  59. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  60. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  61. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  62. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  63. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  66. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  69. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  70. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  71. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  72. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  73. data/src/core/lib/channel/channel_args.c +28 -9
  74. data/src/core/lib/channel/channel_args.h +5 -1
  75. data/src/core/lib/channel/channel_stack.c +1 -1
  76. data/src/core/lib/channel/channel_stack.h +2 -2
  77. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  78. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  79. data/src/core/lib/channel/connected_channel.c +3 -1
  80. data/src/core/lib/channel/context.h +2 -2
  81. data/src/core/lib/compression/message_compress.c +2 -2
  82. data/src/core/lib/debug/trace.c +13 -6
  83. data/src/core/lib/debug/trace.h +27 -1
  84. data/src/core/lib/http/httpcli.c +1 -1
  85. data/src/core/lib/http/httpcli_security_connector.c +6 -10
  86. data/src/core/lib/http/parser.c +2 -2
  87. data/src/core/lib/http/parser.h +2 -1
  88. data/src/core/lib/iomgr/combiner.c +6 -6
  89. data/src/core/lib/iomgr/combiner.h +2 -1
  90. data/src/core/lib/iomgr/error.c +12 -5
  91. data/src/core/lib/iomgr/error.h +13 -13
  92. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  93. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  94. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  95. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  96. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  97. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  98. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  99. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  100. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
  101. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  102. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  103. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  104. data/src/core/lib/iomgr/ev_posix.c +22 -8
  105. data/src/core/lib/iomgr/ev_posix.h +4 -3
  106. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  107. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  108. data/src/core/lib/iomgr/iomgr.c +4 -0
  109. data/src/core/lib/iomgr/iomgr.h +3 -0
  110. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  111. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  112. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  113. data/src/core/lib/iomgr/pollset.h +2 -5
  114. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  115. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  116. data/src/core/lib/iomgr/resource_quota.c +9 -8
  117. data/src/core/lib/iomgr/resource_quota.h +2 -1
  118. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  119. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  120. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  121. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  122. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  123. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  124. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  125. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  126. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  127. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  128. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  129. data/src/core/lib/iomgr/timer_generic.c +24 -25
  130. data/src/core/lib/iomgr/timer_manager.c +276 -0
  131. data/src/core/lib/iomgr/timer_manager.h +52 -0
  132. data/src/core/lib/iomgr/timer_uv.c +6 -0
  133. data/src/core/lib/iomgr/udp_server.c +42 -9
  134. data/src/core/lib/iomgr/udp_server.h +3 -1
  135. data/src/core/lib/security/credentials/credentials.c +0 -1
  136. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  137. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  138. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  139. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  140. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  141. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  142. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  143. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  144. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  145. data/src/core/lib/security/transport/security_connector.c +32 -51
  146. data/src/core/lib/security/transport/security_connector.h +10 -14
  147. data/src/core/lib/slice/b64.c +1 -1
  148. data/src/core/lib/slice/percent_encoding.c +3 -3
  149. data/src/core/lib/slice/slice.c +66 -33
  150. data/src/core/lib/slice/slice_buffer.c +25 -6
  151. data/src/core/lib/slice/slice_hash_table.c +33 -35
  152. data/src/core/lib/slice/slice_hash_table.h +7 -12
  153. data/src/core/lib/support/atomic.h +45 -0
  154. data/src/core/lib/support/atomic_with_atm.h +70 -0
  155. data/src/core/lib/support/atomic_with_std.h +48 -0
  156. data/src/core/lib/support/avl.c +14 -14
  157. data/src/core/lib/support/memory.h +74 -0
  158. data/src/core/lib/support/mpscq.c +12 -1
  159. data/src/core/lib/support/mpscq.h +4 -0
  160. data/src/core/lib/support/stack_lockfree.c +3 -36
  161. data/src/core/lib/support/time_posix.c +8 -0
  162. data/src/core/lib/support/tmpfile_posix.c +10 -10
  163. data/src/core/lib/surface/alarm.c +3 -1
  164. data/src/core/lib/surface/api_trace.c +2 -1
  165. data/src/core/lib/surface/api_trace.h +2 -2
  166. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  167. data/src/core/lib/surface/call.c +65 -22
  168. data/src/core/lib/surface/call.h +4 -2
  169. data/src/core/lib/surface/channel_init.c +2 -19
  170. data/src/core/lib/surface/channel_stack_type.c +18 -0
  171. data/src/core/lib/surface/channel_stack_type.h +2 -0
  172. data/src/core/lib/surface/completion_queue.c +249 -83
  173. data/src/core/lib/surface/completion_queue.h +18 -13
  174. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  175. data/src/core/lib/surface/init.c +1 -52
  176. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  177. data/src/core/lib/surface/server.c +50 -27
  178. data/src/core/lib/surface/server.h +2 -1
  179. data/src/core/lib/surface/version.c +2 -2
  180. data/src/core/lib/transport/bdp_estimator.c +20 -9
  181. data/src/core/lib/transport/bdp_estimator.h +5 -1
  182. data/src/core/lib/transport/byte_stream.c +23 -9
  183. data/src/core/lib/transport/byte_stream.h +15 -6
  184. data/src/core/lib/transport/connectivity_state.c +6 -6
  185. data/src/core/lib/transport/connectivity_state.h +2 -1
  186. data/src/core/lib/transport/service_config.c +6 -13
  187. data/src/core/lib/transport/service_config.h +2 -2
  188. data/src/core/lib/transport/static_metadata.c +403 -389
  189. data/src/core/lib/transport/static_metadata.h +127 -114
  190. data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
  191. data/src/core/tsi/fake_transport_security.c +5 -4
  192. data/src/core/tsi/ssl_transport_security.c +71 -82
  193. data/src/core/tsi/ssl_transport_security.h +39 -61
  194. data/src/core/tsi/transport_security.c +83 -2
  195. data/src/core/tsi/transport_security.h +27 -2
  196. data/src/core/tsi/transport_security_adapter.c +236 -0
  197. data/src/core/tsi/transport_security_adapter.h +62 -0
  198. data/src/core/tsi/transport_security_interface.h +179 -66
  199. data/src/ruby/ext/grpc/extconf.rb +2 -1
  200. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  201. data/src/ruby/ext/grpc/rb_call.c +56 -48
  202. data/src/ruby/ext/grpc/rb_call.h +3 -4
  203. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  204. data/src/ruby/ext/grpc/rb_channel.c +45 -29
  205. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  206. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  207. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  208. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  209. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  210. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  211. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  212. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  213. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
  214. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
  215. data/src/ruby/ext/grpc/rb_server.c +26 -28
  216. data/src/ruby/lib/grpc/version.rb +1 -1
  217. metadata +40 -18
  218. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  219. data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -39,13 +39,13 @@
39
39
  #include <grpc/grpc.h>
40
40
 
41
41
  /* Gets the wrapped call from a VALUE. */
42
- grpc_call* grpc_rb_get_wrapped_call(VALUE v);
42
+ grpc_call *grpc_rb_get_wrapped_call(VALUE v);
43
43
 
44
44
  /* Gets the VALUE corresponding to given grpc_call. */
45
45
  VALUE grpc_rb_wrap_call(grpc_call *c, grpc_completion_queue *q);
46
46
 
47
47
  /* Provides the details of an call error */
48
- const char* grpc_call_error_detail_of(grpc_call_error err);
48
+ const char *grpc_call_error_detail_of(grpc_call_error err);
49
49
 
50
50
  /* Converts a metadata array to a hash. */
51
51
  VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
@@ -53,8 +53,7 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary);
53
53
  /* grpc_rb_md_ary_convert converts a ruby metadata hash into
54
54
  a grpc_metadata_array.
55
55
  */
56
- void grpc_rb_md_ary_convert(VALUE md_ary_hash,
57
- grpc_metadata_array *md_ary);
56
+ void grpc_rb_md_ary_convert(VALUE md_ary_hash, grpc_metadata_array *md_ary);
58
57
 
59
58
  /* grpc_rb_eCallError is the ruby class of the exception thrown during call
60
59
  operations. */
@@ -33,8 +33,8 @@
33
33
 
34
34
  #include <ruby/ruby.h>
35
35
 
36
- #include "rb_grpc_imports.generated.h"
37
36
  #include "rb_call_credentials.h"
37
+ #include "rb_grpc_imports.generated.h"
38
38
 
39
39
  #include <ruby/thread.h>
40
40
 
@@ -82,20 +82,18 @@ static VALUE grpc_rb_call_credentials_callback(VALUE callback_args) {
82
82
  static VALUE grpc_rb_call_credentials_callback_rescue(VALUE args,
83
83
  VALUE exception_object) {
84
84
  VALUE result = rb_hash_new();
85
- VALUE backtrace = rb_funcall(
86
- rb_funcall(exception_object, rb_intern("backtrace"), 0),
87
- rb_intern("join"),
88
- 1, rb_str_new2("\n\tfrom "));
89
- VALUE rb_exception_info = rb_funcall(exception_object, rb_intern("inspect"), 0);
85
+ VALUE backtrace =
86
+ rb_funcall(rb_funcall(exception_object, rb_intern("backtrace"), 0),
87
+ rb_intern("join"), 1, rb_str_new2("\n\tfrom "));
88
+ VALUE rb_exception_info =
89
+ rb_funcall(exception_object, rb_intern("inspect"), 0);
90
90
  (void)args;
91
91
  gpr_log(GPR_INFO, "Call credentials callback failed: %s\n%s",
92
- StringValueCStr(rb_exception_info),
93
- StringValueCStr(backtrace));
92
+ StringValueCStr(rb_exception_info), StringValueCStr(backtrace));
94
93
  rb_hash_aset(result, rb_str_new2("metadata"), Qnil);
95
94
  rb_hash_aset(result, rb_str_new2("status"),
96
95
  INT2NUM(GRPC_STATUS_UNAUTHENTICATED));
97
- rb_hash_aset(result, rb_str_new2("details"),
98
- rb_exception_info);
96
+ rb_hash_aset(result, rb_str_new2("details"), rb_exception_info);
99
97
  return result;
100
98
  }
101
99
 
@@ -118,7 +116,8 @@ static void grpc_rb_call_credentials_callback_with_gil(void *param) {
118
116
  result = rb_rescue(grpc_rb_call_credentials_callback, callback_args,
119
117
  grpc_rb_call_credentials_callback_rescue, Qnil);
120
118
  // Both callbacks return a hash, so result should be a hash
121
- grpc_rb_md_ary_convert(rb_hash_aref(result, rb_str_new2("metadata")), &md_ary);
119
+ grpc_rb_md_ary_convert(rb_hash_aref(result, rb_str_new2("metadata")),
120
+ &md_ary);
122
121
  status = NUM2INT(rb_hash_aref(result, rb_str_new2("status")));
123
122
  details = rb_hash_aref(result, rb_str_new2("details"));
124
123
  error_details = StringValueCStr(details);
@@ -138,7 +137,7 @@ static void grpc_rb_call_credentials_plugin_get_metadata(
138
137
  params->callback = cb;
139
138
 
140
139
  grpc_rb_event_queue_enqueue(grpc_rb_call_credentials_callback_with_gil,
141
- (void*)(params));
140
+ (void *)(params));
142
141
  }
143
142
 
144
143
  static void grpc_rb_call_credentials_plugin_destroy(void *state) {
@@ -172,13 +171,15 @@ static void grpc_rb_call_credentials_mark(void *p) {
172
171
  }
173
172
 
174
173
  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,
174
+ "grpc_call_credentials",
175
+ {grpc_rb_call_credentials_mark,
176
+ grpc_rb_call_credentials_free,
177
+ GRPC_RB_MEMSIZE_UNAVAILABLE,
178
+ {NULL, NULL}},
179
+ NULL,
180
+ NULL,
180
181
  #ifdef RUBY_TYPED_FREE_IMMEDIATELY
181
- RUBY_TYPED_FREE_IMMEDIATELY
182
+ RUBY_TYPED_FREE_IMMEDIATELY
182
183
  #endif
183
184
  };
184
185
 
@@ -188,7 +189,8 @@ static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
188
189
  grpc_rb_call_credentials *wrapper = ALLOC(grpc_rb_call_credentials);
189
190
  wrapper->wrapped = NULL;
190
191
  wrapper->mark = Qnil;
191
- return TypedData_Wrap_Struct(cls, &grpc_rb_call_credentials_data_type, wrapper);
192
+ return TypedData_Wrap_Struct(cls, &grpc_rb_call_credentials_data_type,
193
+ wrapper);
192
194
  }
193
195
 
194
196
  /* Creates a wrapping object for a given call credentials. This should only be
@@ -232,7 +234,7 @@ static VALUE grpc_rb_call_credentials_init(VALUE self, VALUE proc) {
232
234
  rb_raise(rb_eTypeError, "Argument to CallCredentials#new must be a proc");
233
235
  return Qnil;
234
236
  }
235
- plugin.state = (void*)proc;
237
+ plugin.state = (void *)proc;
236
238
  plugin.type = "";
237
239
 
238
240
  creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL);
@@ -289,7 +291,6 @@ void Init_grpc_call_credentials() {
289
291
  grpc_call_credentials *grpc_rb_get_wrapped_call_credentials(VALUE v) {
290
292
  grpc_rb_call_credentials *wrapper = NULL;
291
293
  TypedData_Get_Struct(v, grpc_rb_call_credentials,
292
- &grpc_rb_call_credentials_data_type,
293
- wrapper);
294
+ &grpc_rb_call_credentials_data_type, wrapper);
294
295
  return wrapper->wrapped;
295
296
  }
@@ -34,9 +34,9 @@
34
34
  #include <ruby/ruby.h>
35
35
  #include <ruby/thread.h>
36
36
 
37
- #include "rb_grpc_imports.generated.h"
38
37
  #include "rb_byte_buffer.h"
39
38
  #include "rb_channel.h"
39
+ #include "rb_grpc_imports.generated.h"
40
40
 
41
41
  #include <grpc/grpc.h>
42
42
  #include <grpc/grpc_security.h>
@@ -89,8 +89,8 @@ typedef struct grpc_rb_channel {
89
89
  static void grpc_rb_channel_try_register_connection_polling(
90
90
  grpc_rb_channel *wrapper);
91
91
  static void grpc_rb_channel_safe_destroy(grpc_rb_channel *wrapper);
92
- static void *wait_until_channel_polling_thread_started_no_gil(void*);
93
- static void wait_until_channel_polling_thread_started_unblocking_func(void*);
92
+ static void *wait_until_channel_polling_thread_started_no_gil(void *);
93
+ static void wait_until_channel_polling_thread_started_unblocking_func(void *);
94
94
 
95
95
  static grpc_completion_queue *channel_polling_cq;
96
96
  static gpr_mu global_connection_polling_mu;
@@ -171,8 +171,9 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
171
171
  MEMZERO(&args, grpc_channel_args, 1);
172
172
 
173
173
  grpc_ruby_once_init();
174
- rb_thread_call_without_gvl(wait_until_channel_polling_thread_started_no_gil, NULL,
175
- wait_until_channel_polling_thread_started_unblocking_func, NULL);
174
+ rb_thread_call_without_gvl(
175
+ wait_until_channel_polling_thread_started_no_gil, NULL,
176
+ wait_until_channel_polling_thread_started_unblocking_func, NULL);
176
177
 
177
178
  /* "3" == 3 mandatory args */
178
179
  rb_scan_args(argc, argv, "3", &target, &channel_args, &credentials);
@@ -204,14 +205,14 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
204
205
 
205
206
  gpr_mu_lock(&wrapper->channel_mu);
206
207
  wrapper->abort_watch_connectivity_state = 0;
207
- wrapper->current_connectivity_state = grpc_channel_check_connectivity_state(wrapper->wrapped, 0);
208
+ wrapper->current_connectivity_state =
209
+ grpc_channel_check_connectivity_state(wrapper->wrapped, 0);
208
210
  wrapper->safe_to_destroy = 0;
209
211
  wrapper->request_safe_destroy = 0;
210
212
 
211
213
  gpr_cv_broadcast(&wrapper->channel_cv);
212
214
  gpr_mu_unlock(&wrapper->channel_mu);
213
215
 
214
-
215
216
  grpc_rb_channel_try_register_connection_polling(wrapper);
216
217
 
217
218
  if (args.args != NULL) {
@@ -253,7 +254,8 @@ static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE *argv,
253
254
  rb_raise(rb_eRuntimeError, "closed!");
254
255
  return Qnil;
255
256
  }
256
- return LONG2NUM(grpc_channel_check_connectivity_state(wrapper->wrapped, grpc_try_to_connect));
257
+ return LONG2NUM(grpc_channel_check_connectivity_state(wrapper->wrapped,
258
+ grpc_try_to_connect));
257
259
  }
258
260
 
259
261
  typedef struct watch_state_stack {
@@ -263,22 +265,21 @@ typedef struct watch_state_stack {
263
265
  } watch_state_stack;
264
266
 
265
267
  static void *watch_channel_state_without_gvl(void *arg) {
266
- watch_state_stack *stack = (watch_state_stack*)arg;
268
+ watch_state_stack *stack = (watch_state_stack *)arg;
267
269
  gpr_timespec deadline = stack->deadline;
268
270
  grpc_rb_channel *wrapper = stack->wrapper;
269
271
  int last_state = stack->last_state;
270
- void *return_value = (void*)0;
272
+ void *return_value = (void *)0;
271
273
 
272
274
  gpr_mu_lock(&wrapper->channel_mu);
273
- while(wrapper->current_connectivity_state == last_state &&
274
- !wrapper->request_safe_destroy &&
275
- !wrapper->safe_to_destroy &&
276
- !wrapper->abort_watch_connectivity_state &&
277
- gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) {
275
+ while (wrapper->current_connectivity_state == last_state &&
276
+ !wrapper->request_safe_destroy && !wrapper->safe_to_destroy &&
277
+ !wrapper->abort_watch_connectivity_state &&
278
+ gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) {
278
279
  gpr_cv_wait(&wrapper->channel_cv, &wrapper->channel_mu, deadline);
279
280
  }
280
281
  if (wrapper->current_connectivity_state != last_state) {
281
- return_value = (void*)1;
282
+ return_value = (void *)1;
282
283
  }
283
284
  gpr_mu_unlock(&wrapper->channel_mu);
284
285
 
@@ -286,7 +287,7 @@ static void *watch_channel_state_without_gvl(void *arg) {
286
287
  }
287
288
 
288
289
  static void watch_channel_state_unblocking_func(void *arg) {
289
- grpc_rb_channel *wrapper = (grpc_rb_channel*)arg;
290
+ grpc_rb_channel *wrapper = (grpc_rb_channel *)arg;
290
291
  gpr_log(GPR_DEBUG, "GRPC_RUBY: watch channel state unblocking func called");
291
292
  gpr_mu_lock(&wrapper->channel_mu);
292
293
  wrapper->abort_watch_connectivity_state = 1;
@@ -306,7 +307,7 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
306
307
  VALUE deadline) {
307
308
  grpc_rb_channel *wrapper = NULL;
308
309
  watch_state_stack stack;
309
- void* out;
310
+ void *out;
310
311
 
311
312
  TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
312
313
 
@@ -316,14 +317,18 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
316
317
  }
317
318
 
318
319
  if (!FIXNUM_P(last_state)) {
319
- rb_raise(rb_eTypeError, "bad type for last_state. want a GRPC::Core::ChannelState constant");
320
+ rb_raise(
321
+ rb_eTypeError,
322
+ "bad type for last_state. want a GRPC::Core::ChannelState constant");
320
323
  return Qnil;
321
324
  }
322
325
 
323
326
  stack.wrapper = wrapper;
324
327
  stack.deadline = grpc_rb_time_timeval(deadline, 0);
325
328
  stack.last_state = NUM2LONG(last_state);
326
- out = rb_thread_call_without_gvl(watch_channel_state_without_gvl, &stack, watch_channel_state_unblocking_func, wrapper);
329
+ out =
330
+ rb_thread_call_without_gvl(watch_channel_state_without_gvl, &stack,
331
+ watch_channel_state_unblocking_func, wrapper);
327
332
  if (out) {
328
333
  return Qtrue;
329
334
  }
@@ -359,7 +364,7 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
359
364
  parent_call = grpc_rb_get_wrapped_call(parent);
360
365
  }
361
366
 
362
- cq = grpc_completion_queue_create(NULL);
367
+ cq = grpc_completion_queue_create_for_pluck(NULL);
363
368
  TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
364
369
  ch = wrapper->wrapped;
365
370
  if (ch == NULL) {
@@ -428,7 +433,7 @@ static VALUE grpc_rb_channel_get_target(VALUE self) {
428
433
  // destroy.
429
434
  // Not safe to call while a channel's connection state is polled.
430
435
  static void grpc_rb_channel_try_register_connection_polling(
431
- grpc_rb_channel *wrapper) {
436
+ grpc_rb_channel *wrapper) {
432
437
  grpc_connectivity_state conn_state;
433
438
  gpr_timespec sleep_time = gpr_time_add(
434
439
  gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(20, GPR_TIMESPAN));
@@ -501,11 +506,14 @@ static void *run_poll_channels_loop_no_gil(void *arg) {
501
506
  break;
502
507
  }
503
508
  if (event.type == GRPC_OP_COMPLETE) {
504
- grpc_rb_channel_try_register_connection_polling((grpc_rb_channel *)event.tag);
509
+ grpc_rb_channel_try_register_connection_polling(
510
+ (grpc_rb_channel *)event.tag);
505
511
  }
506
512
  }
507
513
  grpc_completion_queue_destroy(channel_polling_cq);
508
- gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop_no_gil - exit connection polling loop");
514
+ gpr_log(GPR_DEBUG,
515
+ "GRPC_RUBY: run_poll_channels_loop_no_gil - exit connection polling "
516
+ "loop");
509
517
  return NULL;
510
518
  }
511
519
 
@@ -513,7 +521,9 @@ static void *run_poll_channels_loop_no_gil(void *arg) {
513
521
  static void run_poll_channels_loop_unblocking_func(void *arg) {
514
522
  (void)arg;
515
523
  gpr_mu_lock(&global_connection_polling_mu);
516
- gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop_unblocking_func - begin aborting connection polling");
524
+ gpr_log(GPR_DEBUG,
525
+ "GRPC_RUBY: grpc_rb_event_unblocking_func - begin aborting "
526
+ "connection polling");
517
527
  abort_channel_polling = 1;
518
528
  grpc_completion_queue_shutdown(channel_polling_cq);
519
529
  gpr_mu_unlock(&global_connection_polling_mu);
@@ -522,7 +532,9 @@ static void run_poll_channels_loop_unblocking_func(void *arg) {
522
532
  // Poll channel connectivity states in background thread without the GIL.
523
533
  static VALUE run_poll_channels_loop(VALUE arg) {
524
534
  (void)arg;
525
- gpr_log(GPR_DEBUG, "GRPC_RUBY: run_poll_channels_loop - create connection polling thread");
535
+ gpr_log(
536
+ GPR_DEBUG,
537
+ "GRPC_RUBY: run_poll_channels_loop - create connection polling thread");
526
538
  rb_thread_call_without_gvl(run_poll_channels_loop_no_gil, NULL,
527
539
  run_poll_channels_loop_unblocking_func, NULL);
528
540
 
@@ -542,10 +554,14 @@ static void *wait_until_channel_polling_thread_started_no_gil(void *arg) {
542
554
  return NULL;
543
555
  }
544
556
 
545
- static void wait_until_channel_polling_thread_started_unblocking_func(void* arg) {
557
+ static void wait_until_channel_polling_thread_started_unblocking_func(
558
+ void *arg) {
546
559
  (void)arg;
547
560
  gpr_mu_lock(&global_connection_polling_mu);
548
- gpr_log(GPR_DEBUG, "GRPC_RUBY: wait_until_channel_polling_thread_started_unblocking_func - begin aborting connection polling");
561
+ gpr_log(GPR_DEBUG,
562
+ "GRPC_RUBY: "
563
+ "wait_until_channel_polling_thread_started_unblocking_func - begin "
564
+ "aborting connection polling");
549
565
  abort_channel_polling = 1;
550
566
  gpr_cv_broadcast(&global_connection_polling_cv);
551
567
  gpr_mu_unlock(&global_connection_polling_mu);
@@ -571,7 +587,7 @@ void grpc_rb_channel_polling_thread_start() {
571
587
  gpr_mu_init(&global_connection_polling_mu);
572
588
  gpr_cv_init(&global_connection_polling_cv);
573
589
 
574
- channel_polling_cq = grpc_completion_queue_create(NULL);
590
+ channel_polling_cq = grpc_completion_queue_create_for_next(NULL);
575
591
  background_thread = rb_thread_create(run_poll_channels_loop, NULL);
576
592
 
577
593
  if (!RTEST(background_thread)) {
@@ -33,8 +33,8 @@
33
33
 
34
34
  #include <ruby/ruby.h>
35
35
 
36
- #include "rb_grpc_imports.generated.h"
37
36
  #include "rb_channel_args.h"
37
+ #include "rb_grpc_imports.generated.h"
38
38
 
39
39
  #include <grpc/grpc.h>
40
40
 
@@ -42,9 +42,12 @@
42
42
 
43
43
  static rb_data_type_t grpc_rb_channel_args_data_type = {
44
44
  "grpc_channel_args",
45
- {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, GRPC_RB_MEMSIZE_UNAVAILABLE,
45
+ {GRPC_RB_GC_NOT_MARKED,
46
+ GRPC_RB_GC_DONT_FREE,
47
+ GRPC_RB_MEMSIZE_UNAVAILABLE,
46
48
  {NULL, NULL}},
47
- NULL, NULL,
49
+ NULL,
50
+ NULL,
48
51
  #ifdef RUBY_TYPED_FREE_IMMEDIATELY
49
52
  RUBY_TYPED_FREE_IMMEDIATELY
50
53
  #endif
@@ -137,11 +140,10 @@ static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
137
140
  params->dst->num_args = num_args;
138
141
  params->dst->args = ALLOC_N(grpc_arg, num_args);
139
142
  MEMZERO(params->dst->args, grpc_arg, num_args);
140
- rb_hash_foreach(params->src_hash,
141
- grpc_rb_channel_create_in_process_add_args_hash_cb,
142
- TypedData_Wrap_Struct(grpc_rb_cChannelArgs,
143
- &grpc_rb_channel_args_data_type,
144
- params->dst));
143
+ rb_hash_foreach(
144
+ params->src_hash, grpc_rb_channel_create_in_process_add_args_hash_cb,
145
+ TypedData_Wrap_Struct(grpc_rb_cChannelArgs,
146
+ &grpc_rb_channel_args_data_type, params->dst));
145
147
  /* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
146
148
  * decrements it during has processing */
147
149
  params->dst->num_args = num_args;
@@ -157,7 +159,7 @@ void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
157
159
  /* Make a protected call to grpc_rb_hash_convert_channel_args */
158
160
  params.src_hash = src_hash;
159
161
  params.dst = dst;
160
- rb_protect(grpc_rb_hash_convert_to_channel_args0, (VALUE) & params, &status);
162
+ rb_protect(grpc_rb_hash_convert_to_channel_args0, (VALUE)&params, &status);
161
163
  if (status != 0) {
162
164
  if (dst->args != NULL) {
163
165
  /* Free any allocated memory before propagating the error */
@@ -35,8 +35,8 @@
35
35
 
36
36
  #include <string.h>
37
37
 
38
- #include "rb_grpc_imports.generated.h"
39
38
  #include "rb_channel_credentials.h"
39
+ #include "rb_grpc_imports.generated.h"
40
40
 
41
41
  #include <grpc/grpc.h>
42
42
  #include <grpc/grpc_security.h>
@@ -91,8 +91,10 @@ static void grpc_rb_channel_credentials_mark(void *p) {
91
91
 
92
92
  static rb_data_type_t grpc_rb_channel_credentials_data_type = {
93
93
  "grpc_channel_credentials",
94
- {grpc_rb_channel_credentials_mark, grpc_rb_channel_credentials_free,
95
- GRPC_RB_MEMSIZE_UNAVAILABLE, {NULL, NULL}},
94
+ {grpc_rb_channel_credentials_mark,
95
+ grpc_rb_channel_credentials_free,
96
+ GRPC_RB_MEMSIZE_UNAVAILABLE,
97
+ {NULL, NULL}},
96
98
  NULL,
97
99
  NULL,
98
100
  #ifdef RUBY_TYPED_FREE_IMMEDIATELY
@@ -106,13 +108,15 @@ static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
106
108
  grpc_rb_channel_credentials *wrapper = ALLOC(grpc_rb_channel_credentials);
107
109
  wrapper->wrapped = NULL;
108
110
  wrapper->mark = Qnil;
109
- return TypedData_Wrap_Struct(cls, &grpc_rb_channel_credentials_data_type, wrapper);
111
+ return TypedData_Wrap_Struct(cls, &grpc_rb_channel_credentials_data_type,
112
+ wrapper);
110
113
  }
111
114
 
112
115
  /* Creates a wrapping object for a given channel credentials. This should only
113
116
  * be called with grpc_channel_credentials objects that are not already
114
117
  * associated with any Ruby object. */
115
- VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c, VALUE mark) {
118
+ VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c,
119
+ VALUE mark) {
116
120
  VALUE rb_wrapper;
117
121
  grpc_rb_channel_credentials *wrapper;
118
122
  if (c == NULL) {
@@ -147,7 +151,8 @@ static ID id_pem_cert_chain;
147
151
  pem_private_key: (optional) PEM encoding of the client's private key
148
152
  pem_cert_chain: (optional) PEM encoding of the client's cert chain
149
153
  Initializes Credential instances. */
150
- static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv, VALUE self) {
154
+ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv,
155
+ VALUE self) {
151
156
  VALUE pem_root_certs = Qnil;
152
157
  VALUE pem_private_key = Qnil;
153
158
  VALUE pem_cert_chain = Qnil;
@@ -173,8 +178,8 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv, VALUE self)
173
178
  } else {
174
179
  key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
175
180
  key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
176
- creds = grpc_ssl_credentials_create(pem_root_certs_cstr,
177
- &key_cert_pair, NULL);
181
+ creds =
182
+ grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair, NULL);
178
183
  }
179
184
  if (creds == NULL) {
180
185
  rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");
@@ -233,8 +238,8 @@ static VALUE grpc_rb_set_default_roots_pem(VALUE self, VALUE roots) {
233
238
  }
234
239
 
235
240
  void Init_grpc_channel_credentials() {
236
- grpc_rb_cChannelCredentials =
237
- rb_define_class_under(grpc_rb_mGrpcCore, "ChannelCredentials", rb_cObject);
241
+ grpc_rb_cChannelCredentials = rb_define_class_under(
242
+ grpc_rb_mGrpcCore, "ChannelCredentials", rb_cObject);
238
243
 
239
244
  /* Allocates an object managed by the ruby runtime */
240
245
  rb_define_alloc_func(grpc_rb_cChannelCredentials,
@@ -262,7 +267,6 @@ void Init_grpc_channel_credentials() {
262
267
  grpc_channel_credentials *grpc_rb_get_wrapped_channel_credentials(VALUE v) {
263
268
  grpc_rb_channel_credentials *wrapper = NULL;
264
269
  TypedData_Get_Struct(v, grpc_rb_channel_credentials,
265
- &grpc_rb_channel_credentials_data_type,
266
- wrapper);
270
+ &grpc_rb_channel_credentials_data_type, wrapper);
267
271
  return wrapper->wrapped;
268
272
  }