grpc 0.14.1 → 0.15.0

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 +1398 -817
  3. data/include/grpc/compression.h +2 -1
  4. data/include/grpc/grpc.h +10 -1
  5. data/include/grpc/grpc_cronet.h +51 -0
  6. data/include/grpc/grpc_posix.h +70 -0
  7. data/include/grpc/impl/codegen/atm.h +2 -2
  8. data/include/grpc/impl/codegen/{atm_win32.h → atm_windows.h} +3 -3
  9. data/include/grpc/impl/codegen/compression_types.h +39 -5
  10. data/include/grpc/impl/codegen/connectivity_state.h +1 -1
  11. data/include/grpc/impl/codegen/grpc_types.h +10 -0
  12. data/include/grpc/impl/codegen/log.h +2 -1
  13. data/include/grpc/impl/codegen/port_platform.h +30 -12
  14. data/include/grpc/impl/codegen/slice_buffer.h +2 -3
  15. data/include/grpc/impl/codegen/sync.h +2 -2
  16. data/include/grpc/impl/codegen/{sync_win32.h → sync_windows.h} +3 -3
  17. data/include/grpc/support/{sync_win32.h → atm_windows.h} +4 -4
  18. data/include/grpc/support/avl.h +5 -0
  19. data/include/grpc/support/{log_win32.h → log_windows.h} +3 -3
  20. data/include/grpc/support/string_util.h +2 -1
  21. data/include/grpc/support/{atm_win32.h → sync_windows.h} +4 -4
  22. data/src/core/ext/census/gen/census.pb.c +179 -0
  23. data/src/core/ext/census/gen/census.pb.h +294 -0
  24. data/src/core/ext/census/grpc_filter.c +11 -7
  25. data/src/core/ext/client_config/channel_connectivity.c +28 -14
  26. data/src/core/ext/client_config/client_channel.c +77 -53
  27. data/src/core/ext/client_config/connector.h +1 -1
  28. data/src/core/ext/client_config/lb_policy.c +9 -6
  29. data/src/core/ext/client_config/lb_policy.h +9 -5
  30. data/src/core/ext/client_config/subchannel.c +58 -39
  31. data/src/core/ext/client_config/subchannel.h +3 -2
  32. data/src/core/ext/client_config/subchannel_call_holder.c +34 -19
  33. data/src/core/ext/client_config/subchannel_call_holder.h +2 -1
  34. data/src/core/ext/client_config/subchannel_index.c +20 -9
  35. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +7 -7
  36. data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +5 -5
  37. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/{v0 → v1}/load_balancer.pb.c +29 -30
  38. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +178 -0
  39. data/src/core/ext/lb_policy/pick_first/pick_first.c +65 -45
  40. data/src/core/ext/lb_policy/round_robin/round_robin.c +84 -43
  41. data/src/core/ext/load_reporting/load_reporting.c +133 -0
  42. data/src/core/ext/load_reporting/load_reporting.h +75 -0
  43. data/src/core/ext/load_reporting/load_reporting_filter.c +151 -0
  44. data/src/core/ext/load_reporting/load_reporting_filter.h +41 -0
  45. data/src/core/ext/resolver/dns/native/dns_resolver.c +22 -8
  46. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +2 -2
  47. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +4 -4
  48. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
  49. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +14 -18
  50. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +49 -24
  51. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +82 -0
  52. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +104 -60
  53. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +232 -0
  54. data/src/{ruby/ext/grpc/rb_signal.c → core/ext/transport/chttp2/transport/bin_decoder.h} +27 -31
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +481 -260
  56. data/src/core/ext/transport/chttp2/transport/frame.h +1 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_data.c +44 -27
  58. data/src/core/ext/transport/chttp2/transport/frame_data.h +6 -5
  59. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +23 -17
  60. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.c +12 -7
  62. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -3
  63. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +25 -12
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -2
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +23 -21
  66. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
  67. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -9
  68. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -2
  69. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +365 -287
  70. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -6
  71. data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -20
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -4
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +1 -0
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -0
  75. data/src/core/ext/transport/chttp2/transport/internal.h +34 -32
  76. data/src/core/ext/transport/chttp2/transport/parsing.c +296 -212
  77. data/src/core/ext/transport/chttp2/transport/writing.c +12 -9
  78. data/src/core/lib/channel/channel_args.c +26 -12
  79. data/src/core/lib/channel/channel_args.h +1 -1
  80. data/src/core/lib/channel/channel_stack.c +12 -8
  81. data/src/core/lib/channel/channel_stack.h +27 -11
  82. data/src/core/lib/channel/channel_stack_builder.c +2 -2
  83. data/src/core/lib/channel/compress_filter.c +26 -31
  84. data/src/core/lib/channel/compress_filter.h +4 -4
  85. data/src/core/lib/channel/connected_channel.c +7 -5
  86. data/src/core/lib/channel/http_client_filter.c +34 -8
  87. data/src/core/lib/channel/http_client_filter.h +1 -1
  88. data/src/core/lib/channel/http_server_filter.c +21 -12
  89. data/src/core/lib/compression/{compression_algorithm.c → compression.c} +22 -21
  90. data/src/core/lib/http/httpcli.c +81 -59
  91. data/src/core/lib/http/httpcli.h +11 -15
  92. data/src/core/lib/http/httpcli_security_connector.c +5 -3
  93. data/src/core/lib/http/parser.c +127 -118
  94. data/src/core/lib/http/parser.h +11 -6
  95. data/src/core/lib/iomgr/closure.c +20 -16
  96. data/src/core/lib/iomgr/closure.h +19 -15
  97. data/src/core/lib/iomgr/endpoint.h +1 -1
  98. data/src/core/lib/iomgr/endpoint_pair_posix.c +2 -2
  99. data/src/core/lib/iomgr/error.c +535 -0
  100. data/src/core/lib/iomgr/error.h +192 -0
  101. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +190 -83
  102. data/src/core/lib/iomgr/ev_poll_posix.c +1267 -0
  103. data/src/{ruby/ext/grpc/rb_signal.h → core/lib/iomgr/ev_poll_posix.h} +7 -5
  104. data/src/core/lib/iomgr/ev_posix.c +104 -14
  105. data/src/core/lib/iomgr/ev_posix.h +17 -7
  106. data/src/core/lib/iomgr/exec_ctx.c +25 -7
  107. data/src/core/lib/iomgr/exec_ctx.h +27 -8
  108. data/src/core/lib/iomgr/executor.c +2 -2
  109. data/src/core/lib/iomgr/executor.h +1 -1
  110. data/src/core/lib/iomgr/iocp_windows.c +2 -41
  111. data/src/core/lib/iomgr/iocp_windows.h +0 -8
  112. data/src/core/lib/iomgr/iomgr.c +5 -4
  113. data/src/core/lib/iomgr/iomgr_posix.c +5 -1
  114. data/src/core/lib/iomgr/iomgr_windows.c +1 -1
  115. data/src/core/lib/{support → iomgr}/load_file.c +15 -17
  116. data/src/core/lib/{support → iomgr}/load_file.h +8 -7
  117. data/src/core/lib/iomgr/polling_entity.c +104 -0
  118. data/src/core/lib/iomgr/polling_entity.h +81 -0
  119. data/src/core/lib/iomgr/pollset.h +6 -5
  120. data/src/core/lib/iomgr/pollset_set_windows.c +4 -1
  121. data/src/core/lib/iomgr/pollset_windows.c +10 -6
  122. data/src/core/lib/iomgr/resolve_address.h +5 -9
  123. data/src/core/lib/iomgr/resolve_address_posix.c +55 -38
  124. data/src/core/lib/iomgr/resolve_address_windows.c +51 -37
  125. data/src/core/lib/iomgr/sockaddr.h +2 -2
  126. data/src/core/lib/iomgr/{sockaddr_win32.h → sockaddr_windows.h} +3 -3
  127. data/src/core/lib/iomgr/socket_utils_common_posix.c +92 -45
  128. data/src/core/lib/iomgr/socket_utils_posix.h +19 -12
  129. data/src/core/lib/iomgr/socket_windows.c +61 -2
  130. data/src/core/lib/iomgr/socket_windows.h +13 -0
  131. data/src/core/lib/iomgr/tcp_client_posix.c +54 -39
  132. data/src/core/lib/iomgr/tcp_client_windows.c +34 -34
  133. data/src/core/lib/iomgr/tcp_posix.c +43 -39
  134. data/src/core/lib/iomgr/tcp_server.h +5 -3
  135. data/src/core/lib/iomgr/tcp_server_posix.c +103 -64
  136. data/src/core/lib/iomgr/tcp_server_windows.c +114 -101
  137. data/src/core/lib/iomgr/tcp_windows.c +45 -50
  138. data/src/core/lib/iomgr/tcp_windows.h +1 -1
  139. data/src/core/lib/iomgr/timer.c +26 -13
  140. data/src/core/lib/iomgr/udp_server.c +28 -4
  141. data/src/core/lib/iomgr/udp_server.h +5 -1
  142. data/src/core/lib/iomgr/unix_sockets_posix.c +8 -7
  143. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -1
  144. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -2
  145. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +15 -5
  146. data/src/core/lib/iomgr/wakeup_fd_pipe.c +13 -9
  147. data/src/core/lib/iomgr/wakeup_fd_posix.c +6 -6
  148. data/src/core/lib/iomgr/wakeup_fd_posix.h +9 -6
  149. data/src/core/lib/iomgr/workqueue.h +5 -4
  150. data/src/core/lib/iomgr/workqueue_posix.c +40 -26
  151. data/src/core/lib/iomgr/workqueue_windows.c +2 -2
  152. data/src/core/lib/profiling/basic_timers.c +2 -2
  153. data/src/core/lib/security/{security_context.c → context/security_context.c} +1 -1
  154. data/src/core/lib/security/{security_context.h → context/security_context.h} +4 -4
  155. data/src/core/lib/security/credentials/composite/composite_credentials.c +263 -0
  156. data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
  157. data/src/core/lib/security/credentials/credentials.c +233 -0
  158. data/src/core/lib/security/{credentials.h → credentials/credentials.h} +19 -157
  159. data/src/core/lib/security/{credentials_metadata.c → credentials/credentials_metadata.c} +1 -1
  160. data/src/core/lib/security/credentials/fake/fake_credentials.c +139 -0
  161. data/src/core/lib/security/credentials/fake/fake_credentials.h +56 -0
  162. data/src/core/lib/security/{credentials_posix.c → credentials/google_default/credentials_posix.c} +1 -1
  163. data/src/core/lib/security/{credentials_win32.c → credentials/google_default/credentials_windows.c} +3 -3
  164. data/src/core/lib/security/{google_default_credentials.c → credentials/google_default/google_default_credentials.c} +93 -35
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +46 -0
  166. data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
  167. data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
  168. data/src/core/lib/security/{json_token.c → credentials/jwt/json_token.c} +10 -101
  169. data/src/core/lib/security/{json_token.h → credentials/jwt/json_token.h} +3 -33
  170. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +160 -0
  171. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +62 -0
  172. data/src/core/lib/security/{jwt_verifier.c → credentials/jwt/jwt_verifier.c} +35 -15
  173. data/src/core/lib/security/{jwt_verifier.h → credentials/jwt/jwt_verifier.h} +3 -3
  174. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +433 -0
  175. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
  176. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +129 -0
  177. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
  178. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +240 -0
  179. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
  180. data/src/core/lib/security/{auth_filters.h → transport/auth_filters.h} +3 -3
  181. data/src/core/lib/security/{client_auth_filter.c → transport/client_auth_filter.c} +27 -20
  182. data/src/core/lib/security/{handshake.c → transport/handshake.c} +77 -45
  183. data/src/core/lib/security/{handshake.h → transport/handshake.h} +9 -11
  184. data/src/core/lib/security/{secure_endpoint.c → transport/secure_endpoint.c} +19 -12
  185. data/src/core/lib/security/{secure_endpoint.h → transport/secure_endpoint.h} +3 -3
  186. data/src/core/lib/security/{security_connector.c → transport/security_connector.c} +26 -17
  187. data/src/core/lib/security/{security_connector.h → transport/security_connector.h} +8 -8
  188. data/src/core/lib/security/{server_auth_filter.c → transport/server_auth_filter.c} +24 -16
  189. data/src/core/lib/security/transport/tsi_error.c +40 -0
  190. data/src/core/lib/security/transport/tsi_error.h +42 -0
  191. data/src/core/lib/security/{b64.c → util/b64.c} +1 -1
  192. data/src/core/lib/security/{b64.h → util/b64.h} +3 -3
  193. data/src/core/lib/security/util/json_util.c +61 -0
  194. data/src/core/lib/security/util/json_util.h +55 -0
  195. data/src/core/lib/support/avl.c +11 -0
  196. data/src/core/lib/support/cpu_windows.c +2 -2
  197. data/src/core/lib/support/{env_win32.c → env_windows.c} +3 -3
  198. data/src/core/lib/support/log.c +3 -1
  199. data/src/core/lib/support/log_linux.c +2 -2
  200. data/src/core/lib/support/{log_win32.c → log_windows.c} +4 -4
  201. data/src/core/lib/support/murmur_hash.c +3 -5
  202. data/src/core/lib/support/string.c +10 -0
  203. data/src/core/lib/support/string.h +4 -0
  204. data/src/core/lib/support/{string_util_win32.c → string_util_windows.c} +3 -3
  205. data/src/core/lib/support/{string_win32.c → string_windows.c} +2 -2
  206. data/src/core/lib/support/{string_win32.h → string_windows.h} +5 -5
  207. data/src/core/lib/support/subprocess_windows.c +1 -1
  208. data/src/core/lib/support/{sync_win32.c → sync_windows.c} +2 -2
  209. data/src/core/lib/support/{thd_win32.c → thd_windows.c} +2 -2
  210. data/src/core/lib/support/{time_win32.c → time_windows.c} +2 -2
  211. data/src/core/lib/support/tmpfile_msys.c +1 -1
  212. data/src/core/lib/support/{tmpfile_win32.c → tmpfile_windows.c} +3 -3
  213. data/src/core/lib/surface/alarm.c +2 -2
  214. data/src/core/lib/surface/byte_buffer_reader.c +13 -6
  215. data/src/core/lib/surface/call.c +323 -123
  216. data/src/core/lib/surface/call.h +2 -0
  217. data/src/core/lib/surface/call_log_batch.c +1 -1
  218. data/src/core/lib/surface/channel.c +64 -15
  219. data/src/core/lib/surface/channel.h +9 -0
  220. data/src/core/lib/surface/channel_ping.c +3 -3
  221. data/src/core/lib/surface/completion_queue.c +75 -19
  222. data/src/core/lib/surface/completion_queue.h +7 -2
  223. data/src/core/lib/surface/init.c +2 -1
  224. data/src/core/lib/surface/init_secure.c +4 -4
  225. data/src/core/lib/surface/lame_client.c +12 -8
  226. data/src/core/lib/surface/server.c +213 -120
  227. data/src/core/lib/surface/server.h +1 -0
  228. data/src/core/lib/surface/version.c +1 -1
  229. data/src/core/lib/transport/connectivity_state.c +40 -18
  230. data/src/core/lib/transport/connectivity_state.h +4 -1
  231. data/src/core/lib/transport/metadata.c +23 -23
  232. data/src/core/lib/transport/metadata.h +4 -0
  233. data/src/core/lib/transport/metadata_batch.c +9 -0
  234. data/src/core/lib/transport/metadata_batch.h +3 -0
  235. data/src/core/lib/transport/static_metadata.c +6 -5
  236. data/src/core/lib/transport/static_metadata.h +64 -60
  237. data/src/core/lib/transport/transport.c +24 -12
  238. data/src/core/lib/transport/transport.h +6 -5
  239. data/src/core/lib/transport/transport_impl.h +4 -0
  240. data/src/core/lib/transport/transport_op_string.c +2 -2
  241. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -0
  242. data/src/ruby/bin/math_services.rb +41 -2
  243. data/src/ruby/ext/grpc/rb_call.c +42 -40
  244. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  245. data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
  246. data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
  247. data/src/ruby/ext/grpc/rb_grpc.c +1 -3
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
  249. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
  250. data/src/ruby/ext/grpc/rb_loader.c +1 -1
  251. data/src/ruby/ext/grpc/rb_server.c +5 -3
  252. data/src/ruby/lib/grpc.rb +0 -3
  253. data/src/ruby/lib/grpc/errors.rb +3 -2
  254. data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
  255. data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
  256. data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
  257. data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
  258. data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
  259. data/src/ruby/lib/grpc/generic/service.rb +8 -8
  260. data/src/ruby/lib/grpc/version.rb +1 -1
  261. data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
  262. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
  263. data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
  264. data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
  265. data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
  266. data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
  267. data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
  268. data/src/ruby/pb/test/client.rb +5 -2
  269. data/src/ruby/spec/generic/active_call_spec.rb +3 -2
  270. data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
  271. data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
  272. data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
  273. data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
  274. metadata +86 -48
  275. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h +0 -182
  276. data/src/core/lib/security/credentials.c +0 -1296
  277. data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -52,6 +52,6 @@
52
52
  */
53
53
  grpc_endpoint *grpc_tcp_create(grpc_winsocket *socket, char *peer_string);
54
54
 
55
- int grpc_tcp_prepare_socket(SOCKET sock);
55
+ grpc_error *grpc_tcp_prepare_socket(SOCKET sock);
56
56
 
57
57
  #endif /* GRPC_CORE_LIB_IOMGR_TCP_WINDOWS_H */
@@ -73,7 +73,7 @@ static shard_type *g_shard_queue[NUM_SHARDS];
73
73
  static bool g_initialized = false;
74
74
 
75
75
  static int run_some_expired_timers(grpc_exec_ctx *exec_ctx, gpr_timespec now,
76
- gpr_timespec *next, int success);
76
+ gpr_timespec *next, grpc_error *error);
77
77
 
78
78
  static gpr_timespec compute_min_deadline(shard_type *shard) {
79
79
  return grpc_timer_heap_is_empty(&shard->heap)
@@ -105,7 +105,8 @@ void grpc_timer_list_init(gpr_timespec now) {
105
105
 
106
106
  void grpc_timer_list_shutdown(grpc_exec_ctx *exec_ctx) {
107
107
  int i;
108
- run_some_expired_timers(exec_ctx, gpr_inf_future(g_clock_type), NULL, 0);
108
+ run_some_expired_timers(exec_ctx, gpr_inf_future(g_clock_type), NULL,
109
+ GRPC_ERROR_CREATE("Timer list shutdown"));
109
110
  for (i = 0; i < NUM_SHARDS; i++) {
110
111
  shard_type *shard = &g_shards[i];
111
112
  gpr_mu_destroy(&shard->mu);
@@ -185,13 +186,16 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer,
185
186
 
186
187
  if (!g_initialized) {
187
188
  timer->triggered = 1;
188
- grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, false, NULL);
189
+ grpc_exec_ctx_sched(
190
+ exec_ctx, &timer->closure,
191
+ GRPC_ERROR_CREATE("Attempt to create timer before initialization"),
192
+ NULL);
189
193
  return;
190
194
  }
191
195
 
192
196
  if (gpr_time_cmp(deadline, now) <= 0) {
193
197
  timer->triggered = 1;
194
- grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, true, NULL);
198
+ grpc_exec_ctx_sched(exec_ctx, &timer->closure, GRPC_ERROR_NONE, NULL);
195
199
  return;
196
200
  }
197
201
 
@@ -235,10 +239,15 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer,
235
239
  }
236
240
 
237
241
  void grpc_timer_cancel(grpc_exec_ctx *exec_ctx, grpc_timer *timer) {
242
+ if (!g_initialized) {
243
+ /* must have already been cancelled, also the shard mutex is invalid */
244
+ return;
245
+ }
246
+
238
247
  shard_type *shard = &g_shards[shard_idx(timer)];
239
248
  gpr_mu_lock(&shard->mu);
240
249
  if (!timer->triggered) {
241
- grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, false, NULL);
250
+ grpc_exec_ctx_sched(exec_ctx, &timer->closure, GRPC_ERROR_CANCELLED, NULL);
242
251
  timer->triggered = 1;
243
252
  if (timer->heap_index == INVALID_HEAP_INDEX) {
244
253
  list_remove(timer);
@@ -278,8 +287,8 @@ static int refill_queue(shard_type *shard, gpr_timespec now) {
278
287
  return !grpc_timer_heap_is_empty(&shard->heap);
279
288
  }
280
289
 
281
- /* This pops the next non-cancelled timer with deadline <= now from the queue,
282
- or returns NULL if there isn't one.
290
+ /* This pops the next non-cancelled timer with deadline <= now from the
291
+ queue, or returns NULL if there isn't one.
283
292
  REQUIRES: shard->mu locked */
284
293
  static grpc_timer *pop_one(shard_type *shard, gpr_timespec now) {
285
294
  grpc_timer *timer;
@@ -299,12 +308,12 @@ static grpc_timer *pop_one(shard_type *shard, gpr_timespec now) {
299
308
  /* REQUIRES: shard->mu unlocked */
300
309
  static size_t pop_timers(grpc_exec_ctx *exec_ctx, shard_type *shard,
301
310
  gpr_timespec now, gpr_timespec *new_min_deadline,
302
- int success) {
311
+ grpc_error *error) {
303
312
  size_t n = 0;
304
313
  grpc_timer *timer;
305
314
  gpr_mu_lock(&shard->mu);
306
315
  while ((timer = pop_one(shard, now))) {
307
- grpc_exec_ctx_enqueue(exec_ctx, &timer->closure, success, NULL);
316
+ grpc_exec_ctx_sched(exec_ctx, &timer->closure, GRPC_ERROR_REF(error), NULL);
308
317
  n++;
309
318
  }
310
319
  *new_min_deadline = compute_min_deadline(shard);
@@ -313,7 +322,7 @@ static size_t pop_timers(grpc_exec_ctx *exec_ctx, shard_type *shard,
313
322
  }
314
323
 
315
324
  static int run_some_expired_timers(grpc_exec_ctx *exec_ctx, gpr_timespec now,
316
- gpr_timespec *next, int success) {
325
+ gpr_timespec *next, grpc_error *error) {
317
326
  size_t n = 0;
318
327
 
319
328
  /* TODO(ctiller): verify that there are any timers (atomically) here */
@@ -327,8 +336,8 @@ static int run_some_expired_timers(grpc_exec_ctx *exec_ctx, gpr_timespec now,
327
336
  /* For efficiency, we pop as many available timers as we can from the
328
337
  shard. This may violate perfect timer deadline ordering, but that
329
338
  shouldn't be a big deal because we don't make ordering guarantees. */
330
- n += pop_timers(exec_ctx, g_shard_queue[0], now, &new_min_deadline,
331
- success);
339
+ n +=
340
+ pop_timers(exec_ctx, g_shard_queue[0], now, &new_min_deadline, error);
332
341
 
333
342
  /* An grpc_timer_init() on the shard could intervene here, adding a new
334
343
  timer that is earlier than new_min_deadline. However,
@@ -359,6 +368,8 @@ static int run_some_expired_timers(grpc_exec_ctx *exec_ctx, gpr_timespec now,
359
368
  *next, gpr_time_add(now, gpr_time_from_millis(1, GPR_TIMESPAN)));
360
369
  }
361
370
 
371
+ GRPC_ERROR_UNREF(error);
372
+
362
373
  return (int)n;
363
374
  }
364
375
 
@@ -367,5 +378,7 @@ bool grpc_timer_check(grpc_exec_ctx *exec_ctx, gpr_timespec now,
367
378
  GPR_ASSERT(now.clock_type == g_clock_type);
368
379
  return run_some_expired_timers(
369
380
  exec_ctx, now, next,
370
- gpr_time_cmp(now, gpr_inf_future(now.clock_type)) != 0);
381
+ gpr_time_cmp(now, gpr_inf_future(now.clock_type)) != 0
382
+ ? GRPC_ERROR_NONE
383
+ : GRPC_ERROR_CREATE("Shutting down timer system"));
371
384
  }
@@ -81,6 +81,7 @@ typedef struct {
81
81
  grpc_closure read_closure;
82
82
  grpc_closure destroyed_closure;
83
83
  grpc_udp_server_read_cb read_cb;
84
+ grpc_udp_server_orphan_cb orphan_cb;
84
85
  } server_port;
85
86
 
86
87
  /* the overall server */
@@ -168,6 +169,10 @@ static void deactivated_all_ports(grpc_exec_ctx *exec_ctx, grpc_udp_server *s) {
168
169
  server_port *sp = &s->ports[i];
169
170
  sp->destroyed_closure.cb = destroyed_port;
170
171
  sp->destroyed_closure.cb_arg = s;
172
+
173
+ GPR_ASSERT(sp->orphan_cb);
174
+ sp->orphan_cb(sp->emfd);
175
+
171
176
  grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL,
172
177
  "udp_listener_shutdown");
173
178
  }
@@ -205,6 +210,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
205
210
  size_t addr_len) {
206
211
  struct sockaddr_storage sockname_temp;
207
212
  socklen_t sockname_len;
213
+ /* Set send/receive socket buffers to 1 MB */
214
+ int buffer_size_bytes = 1024 * 1024;
208
215
 
209
216
  if (fd < 0) {
210
217
  goto error;
@@ -234,6 +241,18 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
234
241
  goto error;
235
242
  }
236
243
 
244
+ if (!grpc_set_socket_sndbuf(fd, buffer_size_bytes)) {
245
+ gpr_log(GPR_ERROR, "Failed to set send buffer size to %d bytes",
246
+ buf_size_bytes);
247
+ goto error;
248
+ }
249
+
250
+ if (!grpc_set_socket_rcvbuf(fd, buffer_size_bytes)) {
251
+ gpr_log(GPR_ERROR, "Failed to set receive buffer size to %d bytes",
252
+ buf_size_bytes);
253
+ goto error;
254
+ }
255
+
237
256
  return grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
238
257
 
239
258
  error:
@@ -268,7 +287,8 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
268
287
 
269
288
  static int add_socket_to_server(grpc_udp_server *s, int fd,
270
289
  const struct sockaddr *addr, size_t addr_len,
271
- grpc_udp_server_read_cb read_cb) {
290
+ grpc_udp_server_read_cb read_cb,
291
+ grpc_udp_server_orphan_cb orphan_cb) {
272
292
  server_port *sp;
273
293
  int port;
274
294
  char *addr_str;
@@ -292,6 +312,7 @@ static int add_socket_to_server(grpc_udp_server *s, int fd,
292
312
  memcpy(sp->addr.untyped, addr, addr_len);
293
313
  sp->addr_len = addr_len;
294
314
  sp->read_cb = read_cb;
315
+ sp->orphan_cb = orphan_cb;
295
316
  GPR_ASSERT(sp->emfd);
296
317
  gpr_mu_unlock(&s->mu);
297
318
  gpr_free(name);
@@ -301,7 +322,8 @@ static int add_socket_to_server(grpc_udp_server *s, int fd,
301
322
  }
302
323
 
303
324
  int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
304
- size_t addr_len, grpc_udp_server_read_cb read_cb) {
325
+ size_t addr_len, grpc_udp_server_read_cb read_cb,
326
+ grpc_udp_server_orphan_cb orphan_cb) {
305
327
  int allocated_port1 = -1;
306
328
  int allocated_port2 = -1;
307
329
  unsigned i;
@@ -348,7 +370,8 @@ int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
348
370
  addr = (struct sockaddr *)&wild6;
349
371
  addr_len = sizeof(wild6);
350
372
  fd = grpc_create_dualstack_socket(addr, SOCK_DGRAM, IPPROTO_UDP, &dsmode);
351
- allocated_port1 = add_socket_to_server(s, fd, addr, addr_len, read_cb);
373
+ allocated_port1 =
374
+ add_socket_to_server(s, fd, addr, addr_len, read_cb, orphan_cb);
352
375
  if (fd >= 0 && dsmode == GRPC_DSMODE_DUALSTACK) {
353
376
  goto done;
354
377
  }
@@ -370,7 +393,8 @@ int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
370
393
  addr = (struct sockaddr *)&addr4_copy;
371
394
  addr_len = sizeof(addr4_copy);
372
395
  }
373
- allocated_port2 = add_socket_to_server(s, fd, addr, addr_len, read_cb);
396
+ allocated_port2 =
397
+ add_socket_to_server(s, fd, addr, addr_len, read_cb, orphan_cb);
374
398
 
375
399
  done:
376
400
  gpr_free(allocated_addr);
@@ -48,6 +48,9 @@ typedef struct grpc_udp_server grpc_udp_server;
48
48
  typedef void (*grpc_udp_server_read_cb)(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
49
49
  struct grpc_server *server);
50
50
 
51
+ /* Called when the grpc_fd is about to be orphaned (and the FD closed). */
52
+ typedef void (*grpc_udp_server_orphan_cb)(grpc_fd *emfd);
53
+
51
54
  /* Create a server, initially not bound to any ports */
52
55
  grpc_udp_server *grpc_udp_server_create(void);
53
56
 
@@ -69,7 +72,8 @@ int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index);
69
72
  /* TODO(ctiller): deprecate this, and make grpc_udp_server_add_ports to handle
70
73
  all of the multiple socket port matching logic in one place */
71
74
  int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
72
- size_t addr_len, grpc_udp_server_read_cb read_cb);
75
+ size_t addr_len, grpc_udp_server_read_cb read_cb,
76
+ grpc_udp_server_orphan_cb orphan_cb);
73
77
 
74
78
  void grpc_udp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_udp_server *server,
75
79
  grpc_closure *on_done);
@@ -47,17 +47,18 @@ void grpc_create_socketpair_if_unix(int sv[2]) {
47
47
  GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
48
48
  }
49
49
 
50
- grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char *name) {
50
+ grpc_error *grpc_resolve_unix_domain_address(const char *name,
51
+ grpc_resolved_addresses **addrs) {
51
52
  struct sockaddr_un *un;
52
53
 
53
- grpc_resolved_addresses *addrs = gpr_malloc(sizeof(grpc_resolved_addresses));
54
- addrs->naddrs = 1;
55
- addrs->addrs = gpr_malloc(sizeof(grpc_resolved_address));
56
- un = (struct sockaddr_un *)addrs->addrs->addr;
54
+ *addrs = gpr_malloc(sizeof(grpc_resolved_addresses));
55
+ (*addrs)->naddrs = 1;
56
+ (*addrs)->addrs = gpr_malloc(sizeof(grpc_resolved_address));
57
+ un = (struct sockaddr_un *)(*addrs)->addrs->addr;
57
58
  un->sun_family = AF_UNIX;
58
59
  strcpy(un->sun_path, name);
59
- addrs->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
60
- return addrs;
60
+ (*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
61
+ return GRPC_ERROR_NONE;
61
62
  }
62
63
 
63
64
  int grpc_is_unix_socket(const struct sockaddr *addr) {
@@ -43,7 +43,8 @@
43
43
 
44
44
  void grpc_create_socketpair_if_unix(int sv[2]);
45
45
 
46
- grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char *name);
46
+ grpc_error *grpc_resolve_unix_domain_address(
47
+ const char *name, grpc_resolved_addresses **addresses);
47
48
 
48
49
  int grpc_is_unix_socket(const struct sockaddr *addr);
49
50
 
@@ -44,8 +44,10 @@ void grpc_create_socketpair_if_unix(int sv[2]) {
44
44
  GPR_ASSERT(0);
45
45
  }
46
46
 
47
- grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char *name) {
48
- return NULL;
47
+ grpc_error *grpc_resolve_unix_domain_address(
48
+ const char *name, grpc_resolved_addresses **addresses) {
49
+ *addresses = NULL;
50
+ return GRPC_ERROR_CREATE("Unix domain sockets are not supported on Windows");
49
51
  }
50
52
 
51
53
  int grpc_is_unix_socket(const struct sockaddr *addr) { return false; }
@@ -44,29 +44,39 @@
44
44
  #include "src/core/lib/iomgr/wakeup_fd_posix.h"
45
45
  #include "src/core/lib/profiling/timers.h"
46
46
 
47
- static void eventfd_create(grpc_wakeup_fd* fd_info) {
47
+ static grpc_error* eventfd_create(grpc_wakeup_fd* fd_info) {
48
48
  int efd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
49
- /* TODO(klempner): Handle failure more gracefully */
50
- GPR_ASSERT(efd >= 0);
49
+ if (efd < 0) {
50
+ return GRPC_OS_ERROR(errno, "eventfd");
51
+ }
51
52
  fd_info->read_fd = efd;
52
53
  fd_info->write_fd = -1;
54
+ return GRPC_ERROR_NONE;
53
55
  }
54
56
 
55
- static void eventfd_consume(grpc_wakeup_fd* fd_info) {
57
+ static grpc_error* eventfd_consume(grpc_wakeup_fd* fd_info) {
56
58
  eventfd_t value;
57
59
  int err;
58
60
  do {
59
61
  err = eventfd_read(fd_info->read_fd, &value);
60
62
  } while (err < 0 && errno == EINTR);
63
+ if (err < 0 && errno != EAGAIN) {
64
+ return GRPC_OS_ERROR(errno, "eventfd_read");
65
+ }
66
+ return GRPC_ERROR_NONE;
61
67
  }
62
68
 
63
- static void eventfd_wakeup(grpc_wakeup_fd* fd_info) {
69
+ static grpc_error* eventfd_wakeup(grpc_wakeup_fd* fd_info) {
64
70
  int err;
65
71
  GPR_TIMER_BEGIN("eventfd_wakeup", 0);
66
72
  do {
67
73
  err = eventfd_write(fd_info->read_fd, 1);
68
74
  } while (err < 0 && errno == EINTR);
75
+ if (err < 0) {
76
+ return GRPC_OS_ERROR(errno, "eventfd_write");
77
+ }
69
78
  GPR_TIMER_END("eventfd_wakeup", 0);
79
+ return GRPC_ERROR_NONE;
70
80
  }
71
81
 
72
82
  static void eventfd_destroy(grpc_wakeup_fd* fd_info) {
@@ -45,7 +45,7 @@
45
45
 
46
46
  #include "src/core/lib/iomgr/socket_utils_posix.h"
47
47
 
48
- static void pipe_init(grpc_wakeup_fd* fd_info) {
48
+ static grpc_error* pipe_init(grpc_wakeup_fd* fd_info) {
49
49
  int pipefd[2];
50
50
  /* TODO(klempner): Make this nonfatal */
51
51
  int r = pipe(pipefd);
@@ -53,36 +53,40 @@ static void pipe_init(grpc_wakeup_fd* fd_info) {
53
53
  gpr_log(GPR_ERROR, "pipe creation failed (%d): %s", errno, strerror(errno));
54
54
  abort();
55
55
  }
56
- GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[0], 1));
57
- GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[1], 1));
56
+ grpc_error* err;
57
+ err = grpc_set_socket_nonblocking(pipefd[0], 1);
58
+ if (err != GRPC_ERROR_NONE) return err;
59
+ err = grpc_set_socket_nonblocking(pipefd[1], 1);
60
+ if (err != GRPC_ERROR_NONE) return err;
58
61
  fd_info->read_fd = pipefd[0];
59
62
  fd_info->write_fd = pipefd[1];
63
+ return GRPC_ERROR_NONE;
60
64
  }
61
65
 
62
- static void pipe_consume(grpc_wakeup_fd* fd_info) {
66
+ static grpc_error* pipe_consume(grpc_wakeup_fd* fd_info) {
63
67
  char buf[128];
64
68
  ssize_t r;
65
69
 
66
70
  for (;;) {
67
71
  r = read(fd_info->read_fd, buf, sizeof(buf));
68
72
  if (r > 0) continue;
69
- if (r == 0) return;
73
+ if (r == 0) return GRPC_ERROR_NONE;
70
74
  switch (errno) {
71
75
  case EAGAIN:
72
- return;
76
+ return GRPC_ERROR_NONE;
73
77
  case EINTR:
74
78
  continue;
75
79
  default:
76
- gpr_log(GPR_ERROR, "error reading pipe: %s", strerror(errno));
77
- return;
80
+ return GRPC_OS_ERROR(errno, "read");
78
81
  }
79
82
  }
80
83
  }
81
84
 
82
- static void pipe_wakeup(grpc_wakeup_fd* fd_info) {
85
+ static grpc_error* pipe_wakeup(grpc_wakeup_fd* fd_info) {
83
86
  char c = 0;
84
87
  while (write(fd_info->write_fd, &c, 1) != 1 && errno == EINTR)
85
88
  ;
89
+ return GRPC_ERROR_NONE;
86
90
  }
87
91
 
88
92
  static void pipe_destroy(grpc_wakeup_fd* fd_info) {
@@ -53,16 +53,16 @@ void grpc_wakeup_fd_global_init(void) {
53
53
 
54
54
  void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = NULL; }
55
55
 
56
- void grpc_wakeup_fd_init(grpc_wakeup_fd *fd_info) {
57
- wakeup_fd_vtable->init(fd_info);
56
+ grpc_error *grpc_wakeup_fd_init(grpc_wakeup_fd *fd_info) {
57
+ return wakeup_fd_vtable->init(fd_info);
58
58
  }
59
59
 
60
- void grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd *fd_info) {
61
- wakeup_fd_vtable->consume(fd_info);
60
+ grpc_error *grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd *fd_info) {
61
+ return wakeup_fd_vtable->consume(fd_info);
62
62
  }
63
63
 
64
- void grpc_wakeup_fd_wakeup(grpc_wakeup_fd *fd_info) {
65
- wakeup_fd_vtable->wakeup(fd_info);
64
+ grpc_error *grpc_wakeup_fd_wakeup(grpc_wakeup_fd *fd_info) {
65
+ return wakeup_fd_vtable->wakeup(fd_info);
66
66
  }
67
67
 
68
68
  void grpc_wakeup_fd_destroy(grpc_wakeup_fd *fd_info) {
@@ -62,6 +62,8 @@
62
62
  #ifndef GRPC_CORE_LIB_IOMGR_WAKEUP_FD_POSIX_H
63
63
  #define GRPC_CORE_LIB_IOMGR_WAKEUP_FD_POSIX_H
64
64
 
65
+ #include "src/core/lib/iomgr/error.h"
66
+
65
67
  void grpc_wakeup_fd_global_init(void);
66
68
  void grpc_wakeup_fd_global_destroy(void);
67
69
 
@@ -72,9 +74,9 @@ void grpc_wakeup_fd_global_init_force_fallback(void);
72
74
  typedef struct grpc_wakeup_fd grpc_wakeup_fd;
73
75
 
74
76
  typedef struct grpc_wakeup_fd_vtable {
75
- void (*init)(grpc_wakeup_fd* fd_info);
76
- void (*consume)(grpc_wakeup_fd* fd_info);
77
- void (*wakeup)(grpc_wakeup_fd* fd_info);
77
+ grpc_error* (*init)(grpc_wakeup_fd* fd_info);
78
+ grpc_error* (*consume)(grpc_wakeup_fd* fd_info);
79
+ grpc_error* (*wakeup)(grpc_wakeup_fd* fd_info);
78
80
  void (*destroy)(grpc_wakeup_fd* fd_info);
79
81
  /* Must be called before calling any other functions */
80
82
  int (*check_availability)(void);
@@ -89,9 +91,10 @@ extern int grpc_allow_specialized_wakeup_fd;
89
91
 
90
92
  #define GRPC_WAKEUP_FD_GET_READ_FD(fd_info) ((fd_info)->read_fd)
91
93
 
92
- void grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info);
93
- void grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info);
94
- void grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info);
94
+ grpc_error* grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info) GRPC_MUST_USE_RESULT;
95
+ grpc_error* grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info)
96
+ GRPC_MUST_USE_RESULT;
97
+ grpc_error* grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info) GRPC_MUST_USE_RESULT;
95
98
  void grpc_wakeup_fd_destroy(grpc_wakeup_fd* fd_info);
96
99
 
97
100
  /* Defined in some specialized implementation's .c file, or by