grpc 1.2.5 → 1.3.4

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 (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -90,7 +90,7 @@ grpc_error *grpc_set_socket_no_sigpipe_if_possible(int fd) {
90
90
  return GRPC_OS_ERROR(errno, "getsockopt(SO_NOSIGPIPE)");
91
91
  }
92
92
  if ((newval != 0) != (val != 0)) {
93
- return GRPC_ERROR_CREATE("Failed to set SO_NOSIGPIPE");
93
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_NOSIGPIPE");
94
94
  }
95
95
  #endif
96
96
  return GRPC_ERROR_NONE;
@@ -164,7 +164,7 @@ grpc_error *grpc_set_socket_reuse_addr(int fd, int reuse) {
164
164
  return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEADDR)");
165
165
  }
166
166
  if ((newval != 0) != val) {
167
- return GRPC_ERROR_CREATE("Failed to set SO_REUSEADDR");
167
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEADDR");
168
168
  }
169
169
 
170
170
  return GRPC_ERROR_NONE;
@@ -173,7 +173,8 @@ grpc_error *grpc_set_socket_reuse_addr(int fd, int reuse) {
173
173
  /* set a socket to reuse old addresses */
174
174
  grpc_error *grpc_set_socket_reuse_port(int fd, int reuse) {
175
175
  #ifndef SO_REUSEPORT
176
- return GRPC_ERROR_CREATE("SO_REUSEPORT unavailable on compiling system");
176
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
177
+ "SO_REUSEPORT unavailable on compiling system");
177
178
  #else
178
179
  int val = (reuse != 0);
179
180
  int newval;
@@ -185,7 +186,7 @@ grpc_error *grpc_set_socket_reuse_port(int fd, int reuse) {
185
186
  return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEPORT)");
186
187
  }
187
188
  if ((newval != 0) != val) {
188
- return GRPC_ERROR_CREATE("Failed to set SO_REUSEPORT");
189
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEPORT");
189
190
  }
190
191
 
191
192
  return GRPC_ERROR_NONE;
@@ -204,7 +205,7 @@ grpc_error *grpc_set_socket_low_latency(int fd, int low_latency) {
204
205
  return GRPC_OS_ERROR(errno, "getsockopt(TCP_NODELAY)");
205
206
  }
206
207
  if ((newval != 0) != val) {
207
- return GRPC_ERROR_CREATE("Failed to set TCP_NODELAY");
208
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set TCP_NODELAY");
208
209
  }
209
210
  return GRPC_ERROR_NONE;
210
211
  }
@@ -213,7 +214,7 @@ grpc_error *grpc_set_socket_low_latency(int fd, int low_latency) {
213
214
  grpc_error *grpc_set_socket_with_mutator(int fd, grpc_socket_mutator *mutator) {
214
215
  GPR_ASSERT(mutator);
215
216
  if (!grpc_socket_mutator_mutate_fd(mutator, fd)) {
216
- return GRPC_ERROR_CREATE("grpc_socket_mutator failed.");
217
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_socket_mutator failed.");
217
218
  }
218
219
  return GRPC_ERROR_NONE;
219
220
  }
@@ -268,7 +269,8 @@ static grpc_error *error_for_fd(int fd, const grpc_resolved_address *addr) {
268
269
  char *addr_str;
269
270
  grpc_sockaddr_to_string(&addr_str, addr, 0);
270
271
  grpc_error *err = grpc_error_set_str(GRPC_OS_ERROR(errno, "socket"),
271
- GRPC_ERROR_STR_TARGET_ADDRESS, addr_str);
272
+ GRPC_ERROR_STR_TARGET_ADDRESS,
273
+ grpc_slice_from_copied_string(addr_str));
272
274
  gpr_free(addr_str);
273
275
  return err;
274
276
  }
@@ -276,11 +278,25 @@ static grpc_error *error_for_fd(int fd, const grpc_resolved_address *addr) {
276
278
  grpc_error *grpc_create_dualstack_socket(
277
279
  const grpc_resolved_address *resolved_addr, int type, int protocol,
278
280
  grpc_dualstack_mode *dsmode, int *newfd) {
281
+ return grpc_create_dualstack_socket_using_factory(NULL, resolved_addr, type,
282
+ protocol, dsmode, newfd);
283
+ }
284
+
285
+ static int create_socket(grpc_socket_factory *factory, int domain, int type,
286
+ int protocol) {
287
+ return (factory != NULL)
288
+ ? grpc_socket_factory_socket(factory, domain, type, protocol)
289
+ : socket(domain, type, protocol);
290
+ }
291
+
292
+ grpc_error *grpc_create_dualstack_socket_using_factory(
293
+ grpc_socket_factory *factory, const grpc_resolved_address *resolved_addr,
294
+ int type, int protocol, grpc_dualstack_mode *dsmode, int *newfd) {
279
295
  const struct sockaddr *addr = (const struct sockaddr *)resolved_addr->addr;
280
296
  int family = addr->sa_family;
281
297
  if (family == AF_INET6) {
282
298
  if (grpc_ipv6_loopback_available()) {
283
- *newfd = socket(family, type, protocol);
299
+ *newfd = create_socket(factory, family, type, protocol);
284
300
  } else {
285
301
  *newfd = -1;
286
302
  errno = EAFNOSUPPORT;
@@ -302,7 +318,7 @@ grpc_error *grpc_create_dualstack_socket(
302
318
  family = AF_INET;
303
319
  }
304
320
  *dsmode = family == AF_INET ? GRPC_DSMODE_IPV4 : GRPC_DSMODE_NONE;
305
- *newfd = socket(family, type, protocol);
321
+ *newfd = create_socket(factory, family, type, protocol);
306
322
  return error_for_fd(*newfd, resolved_addr);
307
323
  }
308
324
 
@@ -41,6 +41,7 @@
41
41
 
42
42
  #include <grpc/impl/codegen/grpc_types.h>
43
43
  #include "src/core/lib/iomgr/error.h"
44
+ #include "src/core/lib/iomgr/socket_factory_posix.h"
44
45
  #include "src/core/lib/iomgr/socket_mutator.h"
45
46
 
46
47
  /* a wrapper for accept or accept4 */
@@ -137,4 +138,10 @@ grpc_error *grpc_create_dualstack_socket(const grpc_resolved_address *addr,
137
138
  grpc_dualstack_mode *dsmode,
138
139
  int *newfd);
139
140
 
141
+ /* Same as grpc_create_dualstack_socket(), but use the given socket factory (if
142
+ non-null) to create the socket, rather than calling socket() directly. */
143
+ grpc_error *grpc_create_dualstack_socket_using_factory(
144
+ grpc_socket_factory *factory, const grpc_resolved_address *addr, int type,
145
+ int protocol, grpc_dualstack_mode *dsmode, int *newfd);
146
+
140
147
  #endif /* GRPC_CORE_LIB_IOMGR_SOCKET_UTILS_POSIX_H */
@@ -40,10 +40,6 @@
40
40
  #include "src/core/lib/iomgr/pollset_set.h"
41
41
  #include "src/core/lib/iomgr/resolve_address.h"
42
42
 
43
- /* Channel arg (integer) setting how large a slice to try and read from the wire
44
- each time recvmsg (or equivalent) is called */
45
- #define GRPC_ARG_TCP_READ_CHUNK_SIZE "grpc.experimental.tcp_read_chunk_size"
46
-
47
43
  /* Asynchronously connect to an address (specified as (addr, len)), and call
48
44
  cb with arg and the completed connection when done (or call cb with arg and
49
45
  NULL on failure).
@@ -121,8 +121,8 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
121
121
  }
122
122
  gpr_mu_lock(&ac->mu);
123
123
  if (ac->fd != NULL) {
124
- grpc_fd_shutdown(exec_ctx, ac->fd,
125
- GRPC_ERROR_CREATE("connect() timed out"));
124
+ grpc_fd_shutdown(exec_ctx, ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
125
+ "connect() timed out"));
126
126
  }
127
127
  done = (--ac->refs == 0);
128
128
  gpr_mu_unlock(&ac->mu);
@@ -137,29 +137,7 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
137
137
  grpc_endpoint *grpc_tcp_client_create_from_fd(
138
138
  grpc_exec_ctx *exec_ctx, grpc_fd *fd, const grpc_channel_args *channel_args,
139
139
  const char *addr_str) {
140
- size_t tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE;
141
- grpc_resource_quota *resource_quota = grpc_resource_quota_create(NULL);
142
- if (channel_args != NULL) {
143
- for (size_t i = 0; i < channel_args->num_args; i++) {
144
- if (0 ==
145
- strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) {
146
- grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
147
- 8 * 1024 * 1024};
148
- tcp_read_chunk_size = (size_t)grpc_channel_arg_get_integer(
149
- &channel_args->args[i], options);
150
- } else if (0 ==
151
- strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
152
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
153
- resource_quota = grpc_resource_quota_ref_internal(
154
- channel_args->args[i].value.pointer.p);
155
- }
156
- }
157
- }
158
-
159
- grpc_endpoint *ep =
160
- grpc_tcp_create(fd, resource_quota, tcp_read_chunk_size, addr_str);
161
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
162
- return ep;
140
+ return grpc_tcp_create(exec_ctx, fd, channel_args, addr_str);
163
141
  }
164
142
 
165
143
  static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
@@ -191,7 +169,8 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
191
169
  gpr_mu_lock(&ac->mu);
192
170
  if (error != GRPC_ERROR_NONE) {
193
171
  error =
194
- grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, "Timeout occurred");
172
+ grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
173
+ grpc_slice_from_static_string("Timeout occurred"));
195
174
  goto finish;
196
175
  }
197
176
 
@@ -252,12 +231,17 @@ finish:
252
231
  gpr_mu_unlock(&ac->mu);
253
232
  if (error != GRPC_ERROR_NONE) {
254
233
  char *error_descr;
255
- gpr_asprintf(&error_descr, "Failed to connect to remote host: %s",
256
- grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION));
257
- error = grpc_error_set_str(error, GRPC_ERROR_STR_DESCRIPTION, error_descr);
234
+ grpc_slice str;
235
+ bool ret = grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION, &str);
236
+ GPR_ASSERT(ret);
237
+ char *desc = grpc_slice_to_c_string(str);
238
+ gpr_asprintf(&error_descr, "Failed to connect to remote host: %s", desc);
239
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_DESCRIPTION,
240
+ grpc_slice_from_copied_string(error_descr));
258
241
  gpr_free(error_descr);
259
- error =
260
- grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS, ac->addr_str);
242
+ gpr_free(desc);
243
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS,
244
+ grpc_slice_from_copied_string(ac->addr_str));
261
245
  }
262
246
  if (done) {
263
247
  gpr_mu_destroy(&ac->mu);
@@ -100,17 +100,21 @@ static void uv_tc_on_connect(uv_connect_t *req, int status) {
100
100
  *connect->endpoint = grpc_tcp_create(
101
101
  connect->tcp_handle, connect->resource_quota, connect->addr_name);
102
102
  } else {
103
- error = GRPC_ERROR_CREATE("Failed to connect to remote host");
103
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
104
+ "Failed to connect to remote host");
104
105
  error = grpc_error_set_int(error, GRPC_ERROR_INT_ERRNO, -status);
105
106
  error =
106
- grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, uv_strerror(status));
107
+ grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
108
+ grpc_slice_from_static_string(uv_strerror(status)));
107
109
  if (status == UV_ECANCELED) {
108
- error = grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
109
- "Timeout occurred");
110
+ error =
111
+ grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
112
+ grpc_slice_from_static_string("Timeout occurred"));
110
113
  // This should only happen if the handle is already closed
111
114
  } else {
112
- error = grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
113
- uv_strerror(status));
115
+ error = grpc_error_set_str(
116
+ error, GRPC_ERROR_STR_OS_ERROR,
117
+ grpc_slice_from_static_string(uv_strerror(status)));
114
118
  uv_close((uv_handle_t *)connect->tcp_handle, tcp_close_callback);
115
119
  }
116
120
  }
@@ -63,7 +63,7 @@ typedef struct {
63
63
  int refs;
64
64
  grpc_closure on_connect;
65
65
  grpc_endpoint **endpoint;
66
- grpc_resource_quota *resource_quota;
66
+ grpc_channel_args *channel_args;
67
67
  } async_connect;
68
68
 
69
69
  static void async_connect_unlock_and_cleanup(grpc_exec_ctx *exec_ctx,
@@ -72,7 +72,7 @@ static void async_connect_unlock_and_cleanup(grpc_exec_ctx *exec_ctx,
72
72
  int done = (--ac->refs == 0);
73
73
  gpr_mu_unlock(&ac->mu);
74
74
  if (done) {
75
- grpc_resource_quota_unref_internal(exec_ctx, ac->resource_quota);
75
+ grpc_channel_args_destroy(exec_ctx, ac->channel_args);
76
76
  gpr_mu_destroy(&ac->mu);
77
77
  gpr_free(ac->addr_name);
78
78
  gpr_free(ac);
@@ -119,11 +119,12 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
119
119
  if (!wsa_success) {
120
120
  error = GRPC_WSA_ERROR(WSAGetLastError(), "ConnectEx");
121
121
  } else {
122
- *ep = grpc_tcp_create(socket, ac->resource_quota, ac->addr_name);
122
+ *ep =
123
+ grpc_tcp_create(exec_ctx, socket, ac->channel_args, ac->addr_name);
123
124
  socket = NULL;
124
125
  }
125
126
  } else {
126
- error = GRPC_ERROR_CREATE("socket is null");
127
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("socket is null");
127
128
  }
128
129
  }
129
130
 
@@ -152,17 +153,6 @@ static void tcp_client_connect_impl(
152
153
  grpc_winsocket_callback_info *info;
153
154
  grpc_error *error = GRPC_ERROR_NONE;
154
155
 
155
- grpc_resource_quota *resource_quota = grpc_resource_quota_create(NULL);
156
- if (channel_args != NULL) {
157
- for (size_t i = 0; i < channel_args->num_args; i++) {
158
- if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
159
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
160
- resource_quota = grpc_resource_quota_ref_internal(
161
- channel_args->args[i].value.pointer.p);
162
- }
163
- }
164
- }
165
-
166
156
  *endpoint = NULL;
167
157
 
168
158
  /* Use dualstack sockets where available. */
@@ -225,7 +215,7 @@ static void tcp_client_connect_impl(
225
215
  ac->refs = 2;
226
216
  ac->addr_name = grpc_sockaddr_to_uri(addr);
227
217
  ac->endpoint = endpoint;
228
- ac->resource_quota = resource_quota;
218
+ ac->channel_args = grpc_channel_args_copy(channel_args);
229
219
  grpc_closure_init(&ac->on_connect, on_connect, ac, grpc_schedule_on_exec_ctx);
230
220
 
231
221
  grpc_closure_init(&ac->on_alarm, on_alarm, ac, grpc_schedule_on_exec_ctx);
@@ -238,15 +228,15 @@ failure:
238
228
  GPR_ASSERT(error != GRPC_ERROR_NONE);
239
229
  char *target_uri = grpc_sockaddr_to_uri(addr);
240
230
  grpc_error *final_error = grpc_error_set_str(
241
- GRPC_ERROR_CREATE_REFERENCING("Failed to connect", &error, 1),
242
- GRPC_ERROR_STR_TARGET_ADDRESS, target_uri);
231
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Failed to connect",
232
+ &error, 1),
233
+ GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(target_uri));
243
234
  GRPC_ERROR_UNREF(error);
244
235
  if (socket != NULL) {
245
236
  grpc_winsocket_destroy(socket);
246
237
  } else if (sock != INVALID_SOCKET) {
247
238
  closesocket(sock);
248
239
  }
249
- grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
250
240
  grpc_closure_sched(exec_ctx, on_done, final_error);
251
241
  }
252
242
 
@@ -52,7 +52,9 @@
52
52
  #include <grpc/support/string_util.h>
53
53
  #include <grpc/support/sync.h>
54
54
  #include <grpc/support/time.h>
55
+ #include <grpc/support/useful.h>
55
56
 
57
+ #include "src/core/lib/channel/channel_args.h"
56
58
  #include "src/core/lib/debug/trace.h"
57
59
  #include "src/core/lib/iomgr/ev_posix.h"
58
60
  #include "src/core/lib/profiling/timers.h"
@@ -80,10 +82,14 @@ typedef struct {
80
82
  int fd;
81
83
  bool finished_edge;
82
84
  msg_iovlen_type iov_size; /* Number of slices to allocate per read attempt */
83
- size_t slice_size;
85
+ double target_length;
86
+ double bytes_read_this_round;
84
87
  gpr_refcount refcount;
85
88
  gpr_atm shutdown_count;
86
89
 
90
+ int min_read_chunk_size;
91
+ int max_read_chunk_size;
92
+
87
93
  /* garbage after the last read */
88
94
  grpc_slice_buffer last_read_buffer;
89
95
 
@@ -108,10 +114,47 @@ typedef struct {
108
114
  grpc_resource_user_slice_allocator slice_allocator;
109
115
  } grpc_tcp;
110
116
 
117
+ static void add_to_estimate(grpc_tcp *tcp, size_t bytes) {
118
+ tcp->bytes_read_this_round += (double)bytes;
119
+ }
120
+
121
+ static void finish_estimate(grpc_tcp *tcp) {
122
+ /* If we read >80% of the target buffer in one read loop, increase the size
123
+ of the target buffer to either the amount read, or twice its previous
124
+ value */
125
+ if (tcp->bytes_read_this_round > tcp->target_length * 0.8) {
126
+ tcp->target_length =
127
+ GPR_MAX(2 * tcp->target_length, tcp->bytes_read_this_round);
128
+ } else {
129
+ tcp->target_length =
130
+ 0.99 * tcp->target_length + 0.01 * tcp->bytes_read_this_round;
131
+ }
132
+ tcp->bytes_read_this_round = 0;
133
+ }
134
+
135
+ static size_t get_target_read_size(grpc_tcp *tcp) {
136
+ grpc_resource_quota *rq = grpc_resource_user_quota(tcp->resource_user);
137
+ double pressure = grpc_resource_quota_get_memory_pressure(rq);
138
+ double target =
139
+ tcp->target_length * (pressure > 0.8 ? (1.0 - pressure) / 0.2 : 1.0);
140
+ size_t sz = (((size_t)GPR_CLAMP(target, tcp->min_read_chunk_size,
141
+ tcp->max_read_chunk_size)) +
142
+ 255) &
143
+ ~(size_t)255;
144
+ /* don't use more than 1/16th of the overall resource quota for a single read
145
+ * alloc */
146
+ size_t rqmax = grpc_resource_quota_peek_size(rq);
147
+ if (sz > rqmax / 16 && rqmax > 1024) {
148
+ sz = rqmax / 16;
149
+ }
150
+ return sz;
151
+ }
152
+
111
153
  static grpc_error *tcp_annotate_error(grpc_error *src_error, grpc_tcp *tcp) {
112
154
  return grpc_error_set_str(
113
155
  grpc_error_set_int(src_error, GRPC_ERROR_INT_FD, tcp->fd),
114
- GRPC_ERROR_STR_TARGET_ADDRESS, tcp->peer_string);
156
+ GRPC_ERROR_STR_TARGET_ADDRESS,
157
+ grpc_slice_from_copied_string(tcp->peer_string));
115
158
  }
116
159
 
117
160
  static void tcp_handle_read(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
@@ -231,9 +274,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
231
274
  /* NB: After calling call_read_cb a parallel call of the read handler may
232
275
  * be running. */
233
276
  if (errno == EAGAIN) {
234
- if (tcp->iov_size > 1) {
235
- tcp->iov_size /= 2;
236
- }
277
+ finish_estimate(tcp);
237
278
  /* We've consumed the edge, request a new one */
238
279
  grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_closure);
239
280
  } else {
@@ -246,18 +287,19 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
246
287
  } else if (read_bytes == 0) {
247
288
  /* 0 read size ==> end of stream */
248
289
  grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer);
249
- call_read_cb(exec_ctx, tcp,
250
- tcp_annotate_error(GRPC_ERROR_CREATE("Socket closed"), tcp));
290
+ call_read_cb(
291
+ exec_ctx, tcp,
292
+ tcp_annotate_error(
293
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp));
251
294
  TCP_UNREF(exec_ctx, tcp, "read");
252
295
  } else {
296
+ add_to_estimate(tcp, (size_t)read_bytes);
253
297
  GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length);
254
298
  if ((size_t)read_bytes < tcp->incoming_buffer->length) {
255
299
  grpc_slice_buffer_trim_end(
256
300
  tcp->incoming_buffer,
257
301
  tcp->incoming_buffer->length - (size_t)read_bytes,
258
302
  &tcp->last_read_buffer);
259
- } else if (tcp->iov_size < MAX_READ_IOVEC) {
260
- ++tcp->iov_size;
261
303
  }
262
304
  GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length);
263
305
  call_read_cb(exec_ctx, tcp, GRPC_ERROR_NONE);
@@ -282,11 +324,11 @@ static void tcp_read_allocation_done(grpc_exec_ctx *exec_ctx, void *tcpp,
282
324
  }
283
325
 
284
326
  static void tcp_continue_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
285
- if (tcp->incoming_buffer->count < (size_t)tcp->iov_size) {
286
- grpc_resource_user_alloc_slices(
287
- exec_ctx, &tcp->slice_allocator, tcp->slice_size,
288
- (size_t)tcp->iov_size - tcp->incoming_buffer->count,
289
- tcp->incoming_buffer);
327
+ size_t target_read_size = get_target_read_size(tcp);
328
+ if (tcp->incoming_buffer->length < target_read_size &&
329
+ tcp->incoming_buffer->count < MAX_READ_IOVEC) {
330
+ grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator,
331
+ target_read_size, 1, tcp->incoming_buffer);
290
332
  } else {
291
333
  tcp_do_read(exec_ctx, tcp);
292
334
  }
@@ -464,10 +506,12 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
464
506
 
465
507
  if (buf->length == 0) {
466
508
  GPR_TIMER_END("tcp_write", 0);
467
- grpc_closure_sched(exec_ctx, cb,
468
- grpc_fd_is_shutdown(tcp->em_fd)
469
- ? tcp_annotate_error(GRPC_ERROR_CREATE("EOF"), tcp)
470
- : GRPC_ERROR_NONE);
509
+ grpc_closure_sched(
510
+ exec_ctx, cb,
511
+ grpc_fd_is_shutdown(tcp->em_fd)
512
+ ? tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"),
513
+ tcp)
514
+ : GRPC_ERROR_NONE);
471
515
  return;
472
516
  }
473
517
  tcp->outgoing_buffer = buf;
@@ -535,9 +579,50 @@ static const grpc_endpoint_vtable vtable = {tcp_read,
535
579
  tcp_get_peer,
536
580
  tcp_get_fd};
537
581
 
538
- grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd,
539
- grpc_resource_quota *resource_quota,
540
- size_t slice_size, const char *peer_string) {
582
+ #define MAX_CHUNK_SIZE 32 * 1024 * 1024
583
+
584
+ grpc_endpoint *grpc_tcp_create(grpc_exec_ctx *exec_ctx, grpc_fd *em_fd,
585
+ const grpc_channel_args *channel_args,
586
+ const char *peer_string) {
587
+ int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE;
588
+ int tcp_max_read_chunk_size = 4 * 1024 * 1024;
589
+ int tcp_min_read_chunk_size = 256;
590
+ grpc_resource_quota *resource_quota = grpc_resource_quota_create(NULL);
591
+ if (channel_args != NULL) {
592
+ for (size_t i = 0; i < channel_args->num_args; i++) {
593
+ if (0 ==
594
+ strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) {
595
+ grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
596
+ MAX_CHUNK_SIZE};
597
+ tcp_read_chunk_size =
598
+ grpc_channel_arg_get_integer(&channel_args->args[i], options);
599
+ } else if (0 == strcmp(channel_args->args[i].key,
600
+ GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE)) {
601
+ grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
602
+ MAX_CHUNK_SIZE};
603
+ tcp_min_read_chunk_size =
604
+ grpc_channel_arg_get_integer(&channel_args->args[i], options);
605
+ } else if (0 == strcmp(channel_args->args[i].key,
606
+ GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE)) {
607
+ grpc_integer_options options = {(int)tcp_read_chunk_size, 1,
608
+ MAX_CHUNK_SIZE};
609
+ tcp_max_read_chunk_size =
610
+ grpc_channel_arg_get_integer(&channel_args->args[i], options);
611
+ } else if (0 ==
612
+ strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
613
+ grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
614
+ resource_quota = grpc_resource_quota_ref_internal(
615
+ channel_args->args[i].value.pointer.p);
616
+ }
617
+ }
618
+ }
619
+
620
+ if (tcp_min_read_chunk_size > tcp_max_read_chunk_size) {
621
+ tcp_min_read_chunk_size = tcp_max_read_chunk_size;
622
+ }
623
+ tcp_read_chunk_size = GPR_CLAMP(tcp_read_chunk_size, tcp_min_read_chunk_size,
624
+ tcp_max_read_chunk_size);
625
+
541
626
  grpc_tcp *tcp = (grpc_tcp *)gpr_malloc(sizeof(grpc_tcp));
542
627
  tcp->base.vtable = &vtable;
543
628
  tcp->peer_string = gpr_strdup(peer_string);
@@ -547,7 +632,10 @@ grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd,
547
632
  tcp->release_fd_cb = NULL;
548
633
  tcp->release_fd = NULL;
549
634
  tcp->incoming_buffer = NULL;
550
- tcp->slice_size = slice_size;
635
+ tcp->target_length = (double)tcp_read_chunk_size;
636
+ tcp->min_read_chunk_size = tcp_min_read_chunk_size;
637
+ tcp->max_read_chunk_size = tcp_max_read_chunk_size;
638
+ tcp->bytes_read_this_round = 0;
551
639
  tcp->iov_size = 1;
552
640
  tcp->finished_edge = true;
553
641
  /* paired with unref in grpc_tcp_destroy */
@@ -564,6 +652,7 @@ grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd,
564
652
  &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp);
565
653
  /* Tell network status tracker about new endpoint */
566
654
  grpc_network_status_register_endpoint(&tcp->base);
655
+ grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
567
656
 
568
657
  return &tcp->base;
569
658
  }