grpc 1.6.7 → 1.7.0.pre1

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +579 -77
  3. data/include/grpc/byte_buffer.h +1 -63
  4. data/include/grpc/compression.h +27 -5
  5. data/include/grpc/fork.h +24 -0
  6. data/include/grpc/grpc.h +12 -6
  7. data/include/grpc/grpc_security.h +28 -7
  8. data/include/grpc/impl/codegen/atm.h +1 -0
  9. data/include/grpc/impl/codegen/byte_buffer.h +86 -0
  10. data/include/grpc/impl/codegen/compression_types.h +63 -5
  11. data/include/grpc/impl/codegen/fork.h +48 -0
  12. data/include/grpc/impl/codegen/grpc_types.h +26 -9
  13. data/include/grpc/impl/codegen/port_platform.h +11 -4
  14. data/include/grpc/impl/codegen/slice.h +6 -1
  15. data/include/grpc/impl/codegen/sync.h +3 -1
  16. data/include/grpc/impl/codegen/sync_custom.h +36 -0
  17. data/include/grpc/module.modulemap +75 -3
  18. data/include/grpc/slice.h +1 -5
  19. data/include/grpc/support/sync_custom.h +24 -0
  20. data/src/core/ext/census/base_resources.c +14 -14
  21. data/src/core/ext/census/context.c +7 -5
  22. data/src/core/ext/census/grpc_filter.c +12 -14
  23. data/src/core/ext/census/mlog.c +2 -1
  24. data/src/core/ext/census/resource.c +13 -9
  25. data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
  26. data/src/core/ext/filters/client_channel/client_channel.c +418 -439
  27. data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
  28. data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
  30. data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
  31. data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
  36. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
  37. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
  38. data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
  39. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  40. data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
  44. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
  45. data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
  46. data/src/core/ext/filters/client_channel/subchannel.c +30 -30
  47. data/src/core/ext/filters/client_channel/subchannel.h +1 -4
  48. data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
  49. data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
  50. data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
  51. data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
  52. data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
  53. data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
  54. data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
  55. data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
  56. data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
  57. data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
  58. data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
  59. data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
  60. data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
  61. data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
  62. data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
  63. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
  64. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
  65. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
  67. data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
  68. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
  69. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
  70. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  71. data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
  72. data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
  73. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
  74. data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
  75. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  76. data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
  77. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
  78. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
  79. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
  80. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  81. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
  82. data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
  83. data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
  84. data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
  85. data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
  86. data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
  87. data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
  88. data/src/core/lib/channel/channel_args.c +112 -12
  89. data/src/core/lib/channel/channel_args.h +31 -0
  90. data/src/core/lib/channel/channel_stack.c +1 -15
  91. data/src/core/lib/channel/channel_stack.h +3 -10
  92. data/src/core/lib/channel/channel_stack_builder.c +41 -10
  93. data/src/core/lib/channel/channel_stack_builder.h +10 -0
  94. data/src/core/lib/channel/connected_channel.c +94 -23
  95. data/src/core/lib/channel/handshaker.c +8 -6
  96. data/src/core/lib/channel/handshaker_registry.c +1 -1
  97. data/src/core/lib/compression/algorithm_metadata.h +14 -0
  98. data/src/core/lib/compression/compression.c +101 -1
  99. data/src/core/lib/compression/stream_compression.c +32 -146
  100. data/src/core/lib/compression/stream_compression.h +28 -4
  101. data/src/core/lib/compression/stream_compression_gzip.c +228 -0
  102. data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
  103. data/src/core/lib/compression/stream_compression_identity.c +94 -0
  104. data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
  105. data/src/core/lib/debug/stats.c +174 -0
  106. data/src/core/lib/debug/stats.h +61 -0
  107. data/src/core/lib/debug/stats_data.c +687 -0
  108. data/src/core/lib/debug/stats_data.h +470 -0
  109. data/src/core/lib/debug/trace.c +3 -3
  110. data/src/core/lib/debug/trace.h +1 -1
  111. data/src/core/lib/http/format_request.c +1 -1
  112. data/src/core/lib/http/httpcli.c +8 -7
  113. data/src/core/lib/http/httpcli_security_connector.c +2 -1
  114. data/src/core/lib/http/parser.c +4 -3
  115. data/src/core/lib/iomgr/call_combiner.c +202 -0
  116. data/src/core/lib/iomgr/call_combiner.h +121 -0
  117. data/src/core/lib/iomgr/closure.c +18 -4
  118. data/src/core/lib/iomgr/combiner.c +11 -4
  119. data/src/core/lib/iomgr/error.c +26 -24
  120. data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
  121. data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
  122. data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
  123. data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
  124. data/src/core/lib/iomgr/ev_posix.c +5 -9
  125. data/src/core/lib/iomgr/ev_posix.h +1 -1
  126. data/src/core/lib/iomgr/exec_ctx.h +6 -1
  127. data/src/core/lib/iomgr/executor.c +142 -36
  128. data/src/core/lib/iomgr/executor.h +6 -1
  129. data/src/core/lib/iomgr/fork_posix.c +88 -0
  130. data/src/core/lib/iomgr/fork_windows.c +39 -0
  131. data/src/core/lib/iomgr/iocp_windows.c +2 -0
  132. data/src/core/lib/iomgr/iomgr.c +2 -8
  133. data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
  134. data/src/core/lib/iomgr/load_file.c +2 -1
  135. data/src/core/lib/iomgr/polling_entity.c +9 -9
  136. data/src/core/lib/iomgr/polling_entity.h +7 -1
  137. data/src/core/lib/iomgr/pollset.h +1 -1
  138. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  139. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  140. data/src/core/lib/iomgr/port.h +4 -0
  141. data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
  142. data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
  143. data/src/core/lib/iomgr/resource_quota.c +24 -19
  144. data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
  145. data/src/core/lib/iomgr/socket_mutator.c +4 -4
  146. data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
  147. data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
  148. data/src/core/lib/iomgr/tcp_posix.c +181 -20
  149. data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
  150. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
  151. data/src/core/lib/iomgr/timer.h +4 -0
  152. data/src/core/lib/iomgr/timer_generic.c +138 -3
  153. data/src/core/lib/iomgr/timer_generic.h +3 -0
  154. data/src/core/lib/iomgr/timer_heap.c +4 -4
  155. data/src/core/lib/iomgr/timer_manager.c +2 -2
  156. data/src/core/lib/iomgr/timer_uv.c +2 -0
  157. data/src/core/lib/iomgr/udp_server.c +10 -8
  158. data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
  159. data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
  160. data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
  161. data/src/core/lib/json/json.c +1 -1
  162. data/src/core/lib/json/json_string.c +13 -13
  163. data/src/core/lib/profiling/timers.h +18 -8
  164. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
  166. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
  167. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
  168. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
  169. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
  170. data/src/core/lib/security/transport/client_auth_filter.c +68 -135
  171. data/src/core/lib/security/transport/secure_endpoint.c +110 -90
  172. data/src/core/lib/security/transport/secure_endpoint.h +8 -3
  173. data/src/core/lib/security/transport/security_connector.c +10 -12
  174. data/src/core/lib/security/transport/security_handshaker.c +45 -24
  175. data/src/core/lib/security/transport/server_auth_filter.c +71 -20
  176. data/src/core/lib/slice/b64.c +2 -2
  177. data/src/core/lib/slice/slice.c +16 -14
  178. data/src/core/lib/slice/slice_buffer.c +5 -4
  179. data/src/core/lib/slice/slice_hash_table.c +3 -2
  180. data/src/core/lib/slice/slice_intern.c +8 -5
  181. data/src/core/lib/support/block_annotate.h +22 -0
  182. data/src/core/lib/support/fork.c +62 -0
  183. data/src/core/lib/support/fork.h +35 -0
  184. data/src/core/lib/support/log_linux.c +1 -1
  185. data/src/core/lib/support/string.c +15 -1
  186. data/src/core/lib/support/string.h +3 -0
  187. data/src/core/lib/support/thd_internal.h +6 -0
  188. data/src/core/lib/support/thd_posix.c +56 -0
  189. data/src/core/lib/support/thd_windows.c +2 -0
  190. data/src/core/lib/surface/alarm.c +22 -15
  191. data/src/core/lib/surface/byte_buffer.c +4 -2
  192. data/src/core/lib/surface/call.c +442 -141
  193. data/src/core/lib/surface/call.h +6 -6
  194. data/src/core/lib/surface/call_log_batch.c +1 -1
  195. data/src/core/lib/surface/call_test_only.h +12 -0
  196. data/src/core/lib/surface/channel.c +39 -4
  197. data/src/core/lib/surface/channel_init.c +6 -6
  198. data/src/core/lib/surface/channel_ping.c +2 -2
  199. data/src/core/lib/surface/completion_queue.c +56 -57
  200. data/src/core/lib/surface/init.c +17 -3
  201. data/src/core/lib/surface/init_secure.c +5 -1
  202. data/src/core/lib/surface/lame_client.cc +9 -10
  203. data/src/core/lib/surface/server.c +81 -72
  204. data/src/core/lib/surface/version.c +2 -2
  205. data/src/core/lib/transport/byte_stream.c +1 -0
  206. data/src/core/lib/transport/byte_stream.h +3 -1
  207. data/src/core/lib/transport/connectivity_state.c +2 -1
  208. data/src/core/lib/transport/metadata.c +7 -4
  209. data/src/core/lib/transport/metadata_batch.c +18 -16
  210. data/src/core/lib/transport/metadata_batch.h +1 -0
  211. data/src/core/lib/transport/service_config.c +5 -3
  212. data/src/core/lib/transport/static_metadata.c +395 -614
  213. data/src/core/lib/transport/static_metadata.h +165 -133
  214. data/src/core/lib/transport/status_conversion.c +1 -1
  215. data/src/core/lib/transport/transport.c +20 -20
  216. data/src/core/lib/transport/transport.h +8 -5
  217. data/src/core/lib/transport/transport_impl.h +0 -3
  218. data/src/core/lib/transport/transport_op_string.c +8 -1
  219. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
  220. data/src/core/tsi/fake_transport_security.c +133 -2
  221. data/src/core/tsi/fake_transport_security.h +5 -0
  222. data/src/core/tsi/ssl_transport_security.c +105 -8
  223. data/src/core/tsi/ssl_transport_security.h +30 -7
  224. data/src/core/tsi/transport_security.h +8 -2
  225. data/src/core/tsi/transport_security_grpc.c +20 -13
  226. data/src/core/tsi/transport_security_grpc.h +13 -9
  227. data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
  228. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  229. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
  230. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
  231. data/src/ruby/lib/grpc.rb +1 -0
  232. data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
  233. data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
  234. data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
  235. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  236. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  237. data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
  238. data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
  239. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
  240. data/src/ruby/lib/grpc/version.rb +1 -1
  241. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
  242. data/src/ruby/spec/channel_connection_spec.rb +1 -34
  243. data/src/ruby/spec/client_server_spec.rb +188 -82
  244. data/src/ruby/spec/generic/active_call_spec.rb +65 -11
  245. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  246. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  247. data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
  248. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
  249. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  250. data/src/ruby/spec/spec_helper.rb +4 -0
  251. data/src/ruby/spec/support/helpers.rb +73 -0
  252. data/src/ruby/spec/support/services.rb +147 -0
  253. data/third_party/cares/ares_build.h +21 -62
  254. data/third_party/cares/cares/ares.h +23 -1
  255. data/third_party/cares/cares/ares__close_sockets.c +2 -2
  256. data/third_party/cares/cares/ares_create_query.c +3 -3
  257. data/third_party/cares/cares/ares_expand_name.c +6 -2
  258. data/third_party/cares/cares/ares_expand_string.c +1 -1
  259. data/third_party/cares/cares/ares_getnameinfo.c +27 -7
  260. data/third_party/cares/cares/ares_init.c +407 -39
  261. data/third_party/cares/cares/ares_library_init.c +10 -0
  262. data/third_party/cares/cares/ares_library_init.h +2 -1
  263. data/third_party/cares/cares/ares_nowarn.c +6 -6
  264. data/third_party/cares/cares/ares_nowarn.h +2 -2
  265. data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
  266. data/third_party/cares/cares/ares_private.h +11 -0
  267. data/third_party/cares/cares/ares_process.c +126 -37
  268. data/third_party/cares/cares/ares_version.h +2 -2
  269. data/third_party/cares/cares/ares_writev.c +2 -2
  270. data/third_party/cares/cares/config-win32.h +8 -34
  271. data/third_party/cares/cares/inet_net_pton.c +2 -2
  272. data/third_party/cares/cares/setup_once.h +5 -5
  273. data/third_party/cares/config_darwin/ares_config.h +98 -196
  274. data/third_party/cares/config_linux/ares_config.h +103 -203
  275. metadata +47 -20
  276. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
  277. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
@@ -26,7 +26,15 @@
26
26
  #include "src/core/lib/security/transport/auth_filters.h"
27
27
  #include "src/core/lib/slice/slice_internal.h"
28
28
 
29
+ typedef enum {
30
+ STATE_INIT = 0,
31
+ STATE_DONE,
32
+ STATE_CANCELLED,
33
+ } async_state;
34
+
29
35
  typedef struct call_data {
36
+ grpc_call_combiner *call_combiner;
37
+ grpc_call_stack *owning_call;
30
38
  grpc_transport_stream_op_batch *recv_initial_metadata_batch;
31
39
  grpc_closure *original_recv_initial_metadata_ready;
32
40
  grpc_closure recv_initial_metadata_ready;
@@ -34,6 +42,8 @@ typedef struct call_data {
34
42
  const grpc_metadata *consumed_md;
35
43
  size_t num_consumed_md;
36
44
  grpc_auth_context *auth_context;
45
+ grpc_closure cancel_closure;
46
+ gpr_atm state; // async_state
37
47
  } call_data;
38
48
 
39
49
  typedef struct channel_data {
@@ -78,54 +88,94 @@ static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx,
78
88
  return GRPC_FILTERED_MDELEM(md);
79
89
  }
80
90
 
81
- /* called from application code */
82
- static void on_md_processing_done(
83
- void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md,
84
- const grpc_metadata *response_md, size_t num_response_md,
85
- grpc_status_code status, const char *error_details) {
86
- grpc_call_element *elem = user_data;
91
+ static void on_md_processing_done_inner(grpc_exec_ctx *exec_ctx,
92
+ grpc_call_element *elem,
93
+ const grpc_metadata *consumed_md,
94
+ size_t num_consumed_md,
95
+ const grpc_metadata *response_md,
96
+ size_t num_response_md,
97
+ grpc_error *error) {
87
98
  call_data *calld = elem->call_data;
88
99
  grpc_transport_stream_op_batch *batch = calld->recv_initial_metadata_batch;
89
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
90
100
  /* TODO(jboeuf): Implement support for response_md. */
91
101
  if (response_md != NULL && num_response_md > 0) {
92
102
  gpr_log(GPR_INFO,
93
103
  "response_md in auth metadata processing not supported for now. "
94
104
  "Ignoring...");
95
105
  }
96
- grpc_error *error = GRPC_ERROR_NONE;
97
- if (status == GRPC_STATUS_OK) {
106
+ if (error == GRPC_ERROR_NONE) {
98
107
  calld->consumed_md = consumed_md;
99
108
  calld->num_consumed_md = num_consumed_md;
100
109
  error = grpc_metadata_batch_filter(
101
- &exec_ctx, batch->payload->recv_initial_metadata.recv_initial_metadata,
110
+ exec_ctx, batch->payload->recv_initial_metadata.recv_initial_metadata,
102
111
  remove_consumed_md, elem, "Response metadata filtering error");
103
- } else {
104
- if (error_details == NULL) {
105
- error_details = "Authentication metadata processing failed.";
112
+ }
113
+ GRPC_CLOSURE_SCHED(exec_ctx, calld->original_recv_initial_metadata_ready,
114
+ error);
115
+ }
116
+
117
+ // Called from application code.
118
+ static void on_md_processing_done(
119
+ void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md,
120
+ const grpc_metadata *response_md, size_t num_response_md,
121
+ grpc_status_code status, const char *error_details) {
122
+ grpc_call_element *elem = user_data;
123
+ call_data *calld = elem->call_data;
124
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
125
+ // If the call was not cancelled while we were in flight, process the result.
126
+ if (gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
127
+ (gpr_atm)STATE_DONE)) {
128
+ grpc_error *error = GRPC_ERROR_NONE;
129
+ if (status != GRPC_STATUS_OK) {
130
+ if (error_details == NULL) {
131
+ error_details = "Authentication metadata processing failed.";
132
+ }
133
+ error = grpc_error_set_int(
134
+ GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_details),
135
+ GRPC_ERROR_INT_GRPC_STATUS, status);
106
136
  }
107
- error =
108
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_details),
109
- GRPC_ERROR_INT_GRPC_STATUS, status);
137
+ on_md_processing_done_inner(&exec_ctx, elem, consumed_md, num_consumed_md,
138
+ response_md, num_response_md, error);
110
139
  }
140
+ // Clean up.
111
141
  for (size_t i = 0; i < calld->md.count; i++) {
112
142
  grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key);
113
143
  grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value);
114
144
  }
115
145
  grpc_metadata_array_destroy(&calld->md);
116
- GRPC_CLOSURE_SCHED(&exec_ctx, calld->original_recv_initial_metadata_ready,
117
- error);
146
+ GRPC_CALL_STACK_UNREF(&exec_ctx, calld->owning_call, "server_auth_metadata");
118
147
  grpc_exec_ctx_finish(&exec_ctx);
119
148
  }
120
149
 
150
+ static void cancel_call(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
151
+ grpc_call_element *elem = (grpc_call_element *)arg;
152
+ call_data *calld = elem->call_data;
153
+ // If the result was not already processed, invoke the callback now.
154
+ if (error != GRPC_ERROR_NONE &&
155
+ gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
156
+ (gpr_atm)STATE_CANCELLED)) {
157
+ on_md_processing_done_inner(exec_ctx, elem, NULL, 0, NULL, 0,
158
+ GRPC_ERROR_REF(error));
159
+ }
160
+ GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_call");
161
+ }
162
+
121
163
  static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, void *arg,
122
164
  grpc_error *error) {
123
- grpc_call_element *elem = arg;
165
+ grpc_call_element *elem = (grpc_call_element *)arg;
124
166
  channel_data *chand = elem->channel_data;
125
167
  call_data *calld = elem->call_data;
126
168
  grpc_transport_stream_op_batch *batch = calld->recv_initial_metadata_batch;
127
169
  if (error == GRPC_ERROR_NONE) {
128
170
  if (chand->creds != NULL && chand->creds->processor.process != NULL) {
171
+ // We're calling out to the application, so we need to make sure
172
+ // to drop the call combiner early if we get cancelled.
173
+ GRPC_CALL_STACK_REF(calld->owning_call, "cancel_call");
174
+ GRPC_CLOSURE_INIT(&calld->cancel_closure, cancel_call, elem,
175
+ grpc_schedule_on_exec_ctx);
176
+ grpc_call_combiner_set_notify_on_cancel(exec_ctx, calld->call_combiner,
177
+ &calld->cancel_closure);
178
+ GRPC_CALL_STACK_REF(calld->owning_call, "server_auth_metadata");
129
179
  calld->md = metadata_batch_to_md_array(
130
180
  batch->payload->recv_initial_metadata.recv_initial_metadata);
131
181
  chand->creds->processor.process(
@@ -159,6 +209,8 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
159
209
  const grpc_call_element_args *args) {
160
210
  call_data *calld = elem->call_data;
161
211
  channel_data *chand = elem->channel_data;
212
+ calld->call_combiner = args->call_combiner;
213
+ calld->owning_call = args->call_stack;
162
214
  GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready,
163
215
  recv_initial_metadata_ready, elem,
164
216
  grpc_schedule_on_exec_ctx);
@@ -218,6 +270,5 @@ const grpc_channel_filter grpc_server_auth_filter = {
218
270
  sizeof(channel_data),
219
271
  init_channel_elem,
220
272
  destroy_channel_elem,
221
- grpc_call_next_get_peer,
222
273
  grpc_channel_next_get_info,
223
274
  "server-auth"};
@@ -58,7 +58,7 @@ char *grpc_base64_encode(const void *vdata, size_t data_size, int url_safe,
58
58
  int multiline) {
59
59
  size_t result_projected_size =
60
60
  grpc_base64_estimate_encoded_size(data_size, url_safe, multiline);
61
- char *result = gpr_malloc(result_projected_size);
61
+ char *result = (char *)gpr_malloc(result_projected_size);
62
62
  grpc_base64_encode_core(result, vdata, data_size, url_safe, multiline);
63
63
  return result;
64
64
  }
@@ -75,7 +75,7 @@ size_t grpc_base64_estimate_encoded_size(size_t data_size, int url_safe,
75
75
 
76
76
  void grpc_base64_encode_core(char *result, const void *vdata, size_t data_size,
77
77
  int url_safe, int multiline) {
78
- const unsigned char *data = vdata;
78
+ const unsigned char *data = (const unsigned char *)vdata;
79
79
  const char *base64_chars =
80
80
  url_safe ? base64_url_safe_chars : base64_url_unsafe_chars;
81
81
  const size_t result_projected_size =
@@ -27,7 +27,7 @@
27
27
  #include "src/core/lib/iomgr/exec_ctx.h"
28
28
 
29
29
  char *grpc_slice_to_c_string(grpc_slice slice) {
30
- char *out = gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1);
30
+ char *out = (char *)gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1);
31
31
  memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice));
32
32
  out[GRPC_SLICE_LENGTH(slice)] = 0;
33
33
  return out;
@@ -105,12 +105,12 @@ typedef struct new_slice_refcount {
105
105
  } new_slice_refcount;
106
106
 
107
107
  static void new_slice_ref(void *p) {
108
- new_slice_refcount *r = p;
108
+ new_slice_refcount *r = (new_slice_refcount *)p;
109
109
  gpr_ref(&r->refs);
110
110
  }
111
111
 
112
112
  static void new_slice_unref(grpc_exec_ctx *exec_ctx, void *p) {
113
- new_slice_refcount *r = p;
113
+ new_slice_refcount *r = (new_slice_refcount *)p;
114
114
  if (gpr_unref(&r->refs)) {
115
115
  r->user_destroy(r->user_data);
116
116
  gpr_free(r);
@@ -125,7 +125,8 @@ grpc_slice grpc_slice_new_with_user_data(void *p, size_t len,
125
125
  void (*destroy)(void *),
126
126
  void *user_data) {
127
127
  grpc_slice slice;
128
- new_slice_refcount *rc = gpr_malloc(sizeof(new_slice_refcount));
128
+ new_slice_refcount *rc =
129
+ (new_slice_refcount *)gpr_malloc(sizeof(new_slice_refcount));
129
130
  gpr_ref_init(&rc->refs, 1);
130
131
  rc->rc.vtable = &new_slice_vtable;
131
132
  rc->rc.sub_refcount = &rc->rc;
@@ -133,7 +134,7 @@ grpc_slice grpc_slice_new_with_user_data(void *p, size_t len,
133
134
  rc->user_data = user_data;
134
135
 
135
136
  slice.refcount = &rc->rc;
136
- slice.data.refcounted.bytes = p;
137
+ slice.data.refcounted.bytes = (uint8_t *)p;
137
138
  slice.data.refcounted.length = len;
138
139
  return slice;
139
140
  }
@@ -154,12 +155,12 @@ typedef struct new_with_len_slice_refcount {
154
155
  } new_with_len_slice_refcount;
155
156
 
156
157
  static void new_with_len_ref(void *p) {
157
- new_with_len_slice_refcount *r = p;
158
+ new_with_len_slice_refcount *r = (new_with_len_slice_refcount *)p;
158
159
  gpr_ref(&r->refs);
159
160
  }
160
161
 
161
162
  static void new_with_len_unref(grpc_exec_ctx *exec_ctx, void *p) {
162
- new_with_len_slice_refcount *r = p;
163
+ new_with_len_slice_refcount *r = (new_with_len_slice_refcount *)p;
163
164
  if (gpr_unref(&r->refs)) {
164
165
  r->user_destroy(r->user_data, r->user_length);
165
166
  gpr_free(r);
@@ -173,8 +174,8 @@ static const grpc_slice_refcount_vtable new_with_len_vtable = {
173
174
  grpc_slice grpc_slice_new_with_len(void *p, size_t len,
174
175
  void (*destroy)(void *, size_t)) {
175
176
  grpc_slice slice;
176
- new_with_len_slice_refcount *rc =
177
- gpr_malloc(sizeof(new_with_len_slice_refcount));
177
+ new_with_len_slice_refcount *rc = (new_with_len_slice_refcount *)gpr_malloc(
178
+ sizeof(new_with_len_slice_refcount));
178
179
  gpr_ref_init(&rc->refs, 1);
179
180
  rc->rc.vtable = &new_with_len_vtable;
180
181
  rc->rc.sub_refcount = &rc->rc;
@@ -183,7 +184,7 @@ grpc_slice grpc_slice_new_with_len(void *p, size_t len,
183
184
  rc->user_length = len;
184
185
 
185
186
  slice.refcount = &rc->rc;
186
- slice.data.refcounted.bytes = p;
187
+ slice.data.refcounted.bytes = (uint8_t *)p;
187
188
  slice.data.refcounted.length = len;
188
189
  return slice;
189
190
  }
@@ -205,12 +206,12 @@ typedef struct {
205
206
  } malloc_refcount;
206
207
 
207
208
  static void malloc_ref(void *p) {
208
- malloc_refcount *r = p;
209
+ malloc_refcount *r = (malloc_refcount *)p;
209
210
  gpr_ref(&r->refs);
210
211
  }
211
212
 
212
213
  static void malloc_unref(grpc_exec_ctx *exec_ctx, void *p) {
213
- malloc_refcount *r = p;
214
+ malloc_refcount *r = (malloc_refcount *)p;
214
215
  if (gpr_unref(&r->refs)) {
215
216
  gpr_free(r);
216
217
  }
@@ -232,7 +233,8 @@ grpc_slice grpc_slice_malloc_large(size_t length) {
232
233
  refcount is a malloc_refcount
233
234
  bytes is an array of bytes of the requested length
234
235
  Both parts are placed in the same allocation returned from gpr_malloc */
235
- malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
236
+ malloc_refcount *rc =
237
+ (malloc_refcount *)gpr_malloc(sizeof(malloc_refcount) + length);
236
238
 
237
239
  /* Initial refcount on rc is 1 - and it's up to the caller to release
238
240
  this reference. */
@@ -451,7 +453,7 @@ int grpc_slice_rchr(grpc_slice s, char c) {
451
453
 
452
454
  int grpc_slice_chr(grpc_slice s, char c) {
453
455
  const char *b = (const char *)GRPC_SLICE_START_PTR(s);
454
- const char *p = memchr(b, c, GRPC_SLICE_LENGTH(s));
456
+ const char *p = (const char *)memchr(b, c, GRPC_SLICE_LENGTH(s));
455
457
  return p == NULL ? -1 : (int)(p - b);
456
458
  }
457
459
 
@@ -45,11 +45,12 @@ static void maybe_embiggen(grpc_slice_buffer *sb) {
45
45
  sb->capacity = GROW(sb->capacity);
46
46
  GPR_ASSERT(sb->capacity > slice_count);
47
47
  if (sb->base_slices == sb->inlined) {
48
- sb->base_slices = gpr_malloc(sb->capacity * sizeof(grpc_slice));
48
+ sb->base_slices =
49
+ (grpc_slice *)gpr_malloc(sb->capacity * sizeof(grpc_slice));
49
50
  memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice));
50
51
  } else {
51
- sb->base_slices =
52
- gpr_realloc(sb->base_slices, sb->capacity * sizeof(grpc_slice));
52
+ sb->base_slices = (grpc_slice *)gpr_realloc(
53
+ sb->base_slices, sb->capacity * sizeof(grpc_slice));
53
54
  }
54
55
 
55
56
  sb->slices = sb->base_slices + slice_offset;
@@ -291,7 +292,7 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src, size_t n,
291
292
  void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx,
292
293
  grpc_slice_buffer *src, size_t n,
293
294
  void *dst) {
294
- char *dstp = dst;
295
+ char *dstp = (char *)dst;
295
296
  GPR_ASSERT(src->length >= n);
296
297
 
297
298
  while (n > 0) {
@@ -60,14 +60,15 @@ grpc_slice_hash_table* grpc_slice_hash_table_create(
60
60
  size_t num_entries, grpc_slice_hash_table_entry* entries,
61
61
  void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value),
62
62
  int (*value_cmp)(void* a, void* b)) {
63
- grpc_slice_hash_table* table = gpr_zalloc(sizeof(*table));
63
+ grpc_slice_hash_table* table =
64
+ (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table));
64
65
  gpr_ref_init(&table->refs, 1);
65
66
  table->destroy_value = destroy_value;
66
67
  table->value_cmp = value_cmp;
67
68
  // Keep load factor low to improve performance of lookups.
68
69
  table->size = num_entries * 2;
69
70
  const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size;
70
- table->entries = gpr_zalloc(entry_size);
71
+ table->entries = (grpc_slice_hash_table_entry*)gpr_zalloc(entry_size);
71
72
  for (size_t i = 0; i < num_entries; ++i) {
72
73
  grpc_slice_hash_table_entry* entry = &entries[i];
73
74
  grpc_slice_hash_table_add(table, entry->key, entry->value);
@@ -69,7 +69,7 @@ static uint32_t max_static_metadata_hash_probe;
69
69
  static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT];
70
70
 
71
71
  static void interned_slice_ref(void *p) {
72
- interned_slice_refcount *s = p;
72
+ interned_slice_refcount *s = (interned_slice_refcount *)p;
73
73
  GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0);
74
74
  }
75
75
 
@@ -90,7 +90,7 @@ static void interned_slice_destroy(interned_slice_refcount *s) {
90
90
  }
91
91
 
92
92
  static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) {
93
- interned_slice_refcount *s = p;
93
+ interned_slice_refcount *s = (interned_slice_refcount *)p;
94
94
  if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) {
95
95
  interned_slice_destroy(s);
96
96
  }
@@ -129,7 +129,8 @@ static void grow_shard(slice_shard *shard) {
129
129
 
130
130
  GPR_TIMER_BEGIN("grow_strtab", 0);
131
131
 
132
- strtab = gpr_zalloc(sizeof(interned_slice_refcount *) * capacity);
132
+ strtab = (interned_slice_refcount **)gpr_zalloc(
133
+ sizeof(interned_slice_refcount *) * capacity);
133
134
 
134
135
  for (i = 0; i < shard->capacity; i++) {
135
136
  for (s = shard->strs[i]; s; s = next) {
@@ -242,7 +243,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) {
242
243
 
243
244
  /* not found: create a new string */
244
245
  /* string data goes after the internal_string header */
245
- s = gpr_malloc(sizeof(*s) + GRPC_SLICE_LENGTH(slice));
246
+ s = (interned_slice_refcount *)gpr_malloc(sizeof(*s) +
247
+ GRPC_SLICE_LENGTH(slice));
246
248
  gpr_atm_rel_store(&s->refcnt, 1);
247
249
  s->length = GRPC_SLICE_LENGTH(slice);
248
250
  s->hash = hash;
@@ -280,7 +282,8 @@ void grpc_slice_intern_init(void) {
280
282
  gpr_mu_init(&shard->mu);
281
283
  shard->count = 0;
282
284
  shard->capacity = INITIAL_SHARD_CAPACITY;
283
- shard->strs = gpr_zalloc(sizeof(*shard->strs) * shard->capacity);
285
+ shard->strs = (interned_slice_refcount **)gpr_zalloc(sizeof(*shard->strs) *
286
+ shard->capacity);
284
287
  }
285
288
  for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) {
286
289
  static_metadata_hash[i].hash = 0;
@@ -19,15 +19,37 @@
19
19
  #ifndef GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H
20
20
  #define GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H
21
21
 
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ void gpr_thd_start_blocking_region();
27
+ void gpr_thd_end_blocking_region();
28
+
29
+ #ifdef __cplusplus
30
+ }
31
+ #endif
32
+
22
33
  /* These annotations identify the beginning and end of regions where
23
34
  the code may block for reasons other than synchronization functions.
24
35
  These include poll, epoll, and getaddrinfo. */
25
36
 
37
+ #ifdef GRPC_SCHEDULING_MARK_BLOCKING_REGION
38
+ #define GRPC_SCHEDULING_START_BLOCKING_REGION \
39
+ do { \
40
+ gpr_thd_start_blocking_region(); \
41
+ } while (0)
42
+ #define GRPC_SCHEDULING_END_BLOCKING_REGION \
43
+ do { \
44
+ gpr_thd_end_blocking_region(); \
45
+ } while (0)
46
+ #else
26
47
  #define GRPC_SCHEDULING_START_BLOCKING_REGION \
27
48
  do { \
28
49
  } while (0)
29
50
  #define GRPC_SCHEDULING_END_BLOCKING_REGION \
30
51
  do { \
31
52
  } while (0)
53
+ #endif
32
54
 
33
55
  #endif /* GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H */
@@ -0,0 +1,62 @@
1
+ /*
2
+ *
3
+ * Copyright 2017 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 "src/core/lib/support/fork.h"
20
+
21
+ #include <string.h>
22
+
23
+ #include <grpc/support/alloc.h>
24
+ #include <grpc/support/useful.h>
25
+
26
+ #include "src/core/lib/support/env.h"
27
+
28
+ /*
29
+ * NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
30
+ * AROUND VERY SPECIFIC USE CASES.
31
+ */
32
+
33
+ static int override_fork_support_enabled = -1;
34
+ static int fork_support_enabled;
35
+
36
+ void grpc_fork_support_init() {
37
+ #ifdef GRPC_ENABLE_FORK_SUPPORT
38
+ fork_support_enabled = 1;
39
+ #else
40
+ fork_support_enabled = 0;
41
+ char *env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
42
+ if (env != NULL) {
43
+ static const char *truthy[] = {"yes", "Yes", "YES", "true",
44
+ "True", "TRUE", "1"};
45
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
46
+ if (0 == strcmp(env, truthy[i])) {
47
+ fork_support_enabled = 1;
48
+ }
49
+ }
50
+ gpr_free(env);
51
+ }
52
+ #endif
53
+ if (override_fork_support_enabled != -1) {
54
+ fork_support_enabled = override_fork_support_enabled;
55
+ }
56
+ }
57
+
58
+ int grpc_fork_support_enabled() { return fork_support_enabled; }
59
+
60
+ void grpc_enable_fork_support(int enable) {
61
+ override_fork_support_enabled = enable;
62
+ }