grpc 1.18.0 → 1.22.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 (428) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +4731 -7404
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc.h +11 -6
  5. data/include/grpc/grpc_security.h +297 -4
  6. data/include/grpc/grpc_security_constants.h +1 -1
  7. data/include/grpc/impl/codegen/byte_buffer.h +13 -0
  8. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +30 -7
  10. data/include/grpc/impl/codegen/port_platform.h +88 -7
  11. data/include/grpc/impl/codegen/slice.h +2 -22
  12. data/include/grpc/impl/codegen/status.h +2 -1
  13. data/include/grpc/impl/codegen/sync_posix.h +18 -0
  14. data/include/grpc/slice.h +3 -3
  15. data/src/core/ext/filters/client_channel/backup_poller.cc +21 -16
  16. data/src/core/ext/filters/client_channel/backup_poller.h +8 -2
  17. data/src/core/ext/filters/client_channel/channel_connectivity.cc +3 -1
  18. data/src/core/ext/filters/client_channel/client_channel.cc +2435 -1557
  19. data/src/core/ext/filters/client_channel/client_channel.h +2 -10
  20. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +6 -89
  21. data/src/core/ext/filters/client_channel/client_channel_channelz.h +8 -33
  22. data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
  23. data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
  24. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -11
  25. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +179 -0
  26. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  27. data/src/core/ext/filters/client_channel/health/health_check_client.cc +59 -55
  28. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -157
  30. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +844 -859
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +14 -12
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +16 -12
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -3
  39. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +185 -312
  40. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +143 -375
  41. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +192 -245
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1554 -955
  43. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
  44. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +14 -10
  45. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
  46. data/src/core/ext/filters/client_channel/lb_policy.cc +115 -22
  47. data/src/core/ext/filters/client_channel/lb_policy.h +260 -129
  48. data/src/core/ext/filters/client_channel/lb_policy_factory.h +5 -2
  49. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +107 -4
  50. data/src/core/ext/filters/client_channel/lb_policy_registry.h +10 -3
  51. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  52. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  53. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +121 -122
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +24 -10
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +111 -47
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  63. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  64. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  65. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  66. data/src/core/{lib/iomgr/network_status_tracker.cc → ext/filters/client_channel/resolver/dns/dns_resolver_selection.h} +8 -15
  67. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +36 -82
  68. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +111 -72
  69. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
  70. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
  71. data/src/core/ext/filters/client_channel/resolver.cc +54 -1
  72. data/src/core/ext/filters/client_channel/resolver.h +52 -23
  73. data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
  74. data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
  75. data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
  76. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +368 -241
  77. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +58 -76
  78. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +543 -0
  79. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +139 -0
  80. data/src/core/ext/filters/client_channel/server_address.cc +4 -54
  81. data/src/core/ext/filters/client_channel/server_address.h +1 -13
  82. data/src/core/ext/filters/client_channel/service_config.cc +329 -0
  83. data/src/core/ext/filters/client_channel/service_config.h +205 -0
  84. data/src/core/ext/filters/client_channel/subchannel.cc +803 -838
  85. data/src/core/ext/filters/client_channel/subchannel.h +295 -128
  86. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  87. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  88. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  89. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  90. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  91. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  92. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  93. data/src/core/ext/filters/http/client_authority_filter.cc +6 -3
  94. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  95. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  96. data/src/core/ext/filters/max_age/max_age_filter.cc +5 -2
  97. data/src/core/ext/filters/message_size/message_size_filter.cc +119 -77
  98. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  99. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  100. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  101. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -47
  102. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +134 -143
  103. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +68 -21
  104. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
  105. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
  106. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
  107. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
  108. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  109. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +156 -94
  110. data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -2
  111. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  112. data/src/core/ext/transport/chttp2/transport/frame_data.cc +33 -37
  113. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
  114. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
  116. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
  117. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
  118. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -6
  119. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
  120. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -4
  121. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  122. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +7 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
  124. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +74 -55
  125. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +33 -11
  126. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
  127. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -14
  128. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  129. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
  130. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +9 -3
  131. data/src/core/ext/transport/chttp2/transport/internal.h +43 -30
  132. data/src/core/ext/transport/chttp2/transport/parsing.cc +52 -70
  133. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  134. data/src/core/ext/transport/chttp2/transport/writing.cc +70 -33
  135. data/src/core/ext/transport/inproc/inproc_transport.cc +26 -18
  136. data/src/core/lib/channel/channel_args.cc +2 -101
  137. data/src/core/lib/channel/channel_args.h +3 -37
  138. data/src/core/lib/channel/channel_stack.h +10 -6
  139. data/src/core/lib/channel/channel_trace.cc +4 -4
  140. data/src/core/lib/channel/channel_trace.h +4 -4
  141. data/src/core/lib/channel/channelz.cc +168 -38
  142. data/src/core/lib/channel/channelz.h +40 -44
  143. data/src/core/lib/channel/channelz_registry.cc +75 -107
  144. data/src/core/lib/channel/channelz_registry.h +10 -28
  145. data/src/core/lib/channel/connected_channel.cc +2 -2
  146. data/src/core/lib/channel/context.h +2 -2
  147. data/src/core/lib/channel/handshaker.cc +151 -218
  148. data/src/core/lib/channel/handshaker.h +110 -101
  149. data/src/core/lib/channel/handshaker_factory.h +11 -19
  150. data/src/core/lib/channel/handshaker_registry.cc +67 -51
  151. data/src/core/lib/channel/handshaker_registry.h +21 -16
  152. data/src/core/lib/compression/algorithm_metadata.h +3 -3
  153. data/src/core/lib/compression/compression.cc +14 -9
  154. data/src/core/lib/compression/compression_args.cc +127 -0
  155. data/src/core/lib/compression/compression_args.h +55 -0
  156. data/src/core/lib/compression/compression_internal.cc +16 -12
  157. data/src/core/lib/compression/compression_internal.h +1 -1
  158. data/src/core/lib/compression/stream_compression.cc +3 -2
  159. data/src/core/lib/compression/stream_compression.h +2 -2
  160. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  161. data/src/core/lib/debug/trace.cc +13 -7
  162. data/src/core/lib/debug/trace.h +14 -1
  163. data/src/core/lib/gpr/arena.h +13 -9
  164. data/src/core/lib/gpr/cpu_posix.cc +5 -3
  165. data/src/core/lib/gpr/env.h +3 -6
  166. data/src/core/lib/gpr/env_linux.cc +6 -1
  167. data/src/core/lib/gpr/env_posix.cc +5 -0
  168. data/src/core/lib/gpr/env_windows.cc +7 -5
  169. data/src/core/lib/gpr/log.cc +9 -13
  170. data/src/core/lib/gpr/log_posix.cc +2 -1
  171. data/src/core/lib/gpr/string.cc +20 -7
  172. data/src/core/lib/gpr/string.h +10 -3
  173. data/src/core/lib/gpr/sync_posix.cc +65 -4
  174. data/src/core/lib/gpr/time.cc +8 -0
  175. data/src/core/lib/gpr/time_posix.cc +21 -2
  176. data/src/core/lib/gprpp/arena.cc +103 -0
  177. data/src/core/lib/gprpp/arena.h +121 -0
  178. data/src/core/lib/gprpp/atomic.h +75 -5
  179. data/src/core/lib/gprpp/fork.cc +13 -32
  180. data/src/core/lib/gprpp/fork.h +5 -1
  181. data/src/core/lib/gprpp/global_config.h +96 -0
  182. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  183. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  184. data/src/core/lib/gprpp/global_config_env.h +131 -0
  185. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  186. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  187. data/src/core/lib/gprpp/map.h +436 -0
  188. data/src/core/lib/gprpp/memory.h +2 -2
  189. data/src/core/lib/gprpp/optional.h +48 -0
  190. data/src/core/lib/gprpp/orphanable.h +6 -5
  191. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  192. data/src/core/lib/gprpp/ref_counted.h +36 -17
  193. data/src/core/lib/gprpp/sync.h +126 -0
  194. data/src/core/lib/gprpp/thd.h +42 -7
  195. data/src/core/lib/gprpp/thd_posix.cc +31 -13
  196. data/src/core/lib/gprpp/thd_windows.cc +47 -34
  197. data/src/core/lib/http/httpcli.cc +6 -5
  198. data/src/core/lib/http/httpcli_security_connector.cc +13 -15
  199. data/src/core/lib/http/parser.cc +3 -2
  200. data/src/core/lib/http/parser.h +2 -1
  201. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  202. data/src/core/lib/iomgr/buffer_list.h +72 -10
  203. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  204. data/src/core/lib/iomgr/call_combiner.h +75 -82
  205. data/src/core/lib/iomgr/cfstream_handle.cc +203 -0
  206. data/src/core/lib/iomgr/cfstream_handle.h +86 -0
  207. data/src/core/lib/iomgr/combiner.cc +11 -3
  208. data/src/core/lib/iomgr/combiner.h +1 -1
  209. data/src/core/lib/iomgr/endpoint.cc +2 -2
  210. data/src/core/lib/iomgr/endpoint.h +3 -2
  211. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  212. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  213. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  214. data/src/core/lib/iomgr/error.cc +21 -17
  215. data/src/core/lib/iomgr/error.h +36 -6
  216. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  217. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  218. data/src/core/lib/iomgr/error_internal.h +1 -1
  219. data/src/core/lib/iomgr/ev_epoll1_linux.cc +44 -28
  220. data/src/core/lib/iomgr/ev_epollex_linux.cc +173 -194
  221. data/src/core/lib/iomgr/ev_poll_posix.cc +16 -487
  222. data/src/core/lib/iomgr/ev_posix.cc +29 -19
  223. data/src/core/lib/iomgr/ev_posix.h +19 -3
  224. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  225. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  226. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  227. data/src/core/lib/iomgr/executor.cc +147 -95
  228. data/src/core/lib/iomgr/executor.h +55 -49
  229. data/src/core/lib/iomgr/fork_posix.cc +6 -5
  230. data/src/core/lib/{gprpp/atomic_with_std.h → iomgr/grpc_if_nametoindex.h} +8 -13
  231. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  232. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  233. data/src/core/lib/iomgr/internal_errqueue.cc +3 -5
  234. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  235. data/src/core/lib/iomgr/iomgr.cc +20 -13
  236. data/src/core/lib/iomgr/iomgr.h +15 -0
  237. data/src/core/lib/iomgr/iomgr_custom.cc +17 -3
  238. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  239. data/src/core/lib/iomgr/iomgr_internal.cc +10 -0
  240. data/src/core/lib/iomgr/iomgr_internal.h +12 -0
  241. data/src/core/lib/iomgr/iomgr_posix.cc +19 -2
  242. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  243. data/src/core/lib/iomgr/iomgr_windows.cc +18 -2
  244. data/src/core/lib/iomgr/lockfree_event.cc +4 -4
  245. data/src/core/lib/iomgr/port.h +35 -0
  246. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  247. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  248. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  249. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  250. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  251. data/src/core/lib/iomgr/socket_windows.h +8 -0
  252. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  253. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  254. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  255. data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
  256. data/src/core/lib/iomgr/tcp_custom.cc +10 -14
  257. data/src/core/lib/iomgr/tcp_posix.cc +256 -140
  258. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  259. data/src/core/lib/iomgr/tcp_server.h +24 -0
  260. data/src/core/lib/iomgr/tcp_server_custom.cc +14 -12
  261. data/src/core/lib/iomgr/tcp_server_posix.cc +86 -12
  262. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  263. data/src/core/lib/iomgr/tcp_server_windows.cc +13 -11
  264. data/src/core/lib/iomgr/tcp_uv.cc +5 -7
  265. data/src/core/lib/iomgr/tcp_windows.cc +8 -14
  266. data/src/core/lib/iomgr/timer.h +2 -1
  267. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  268. data/src/core/lib/iomgr/timer_manager.cc +20 -11
  269. data/src/core/lib/iomgr/udp_server.cc +8 -6
  270. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
  271. data/src/core/lib/json/json.cc +1 -4
  272. data/src/core/lib/profiling/basic_timers.cc +10 -4
  273. data/src/core/lib/security/context/security_context.cc +6 -7
  274. data/src/core/lib/security/context/security_context.h +3 -4
  275. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  276. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  277. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  278. data/src/core/lib/security/credentials/credentials.h +9 -1
  279. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -3
  280. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  281. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  282. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +2 -1
  283. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
  284. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  285. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +3 -3
  286. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +9 -8
  287. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  288. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  289. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  290. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +210 -0
  291. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
  292. data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
  293. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  294. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -12
  295. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  296. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  297. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  298. data/src/core/lib/security/security_connector/security_connector.h +3 -3
  299. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +39 -38
  300. data/src/core/lib/security/security_connector/ssl_utils.cc +164 -26
  301. data/src/core/lib/security/security_connector/ssl_utils.h +70 -1
  302. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
  303. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
  304. data/src/core/lib/security/transport/auth_filters.h +5 -2
  305. data/src/core/lib/security/transport/client_auth_filter.cc +55 -50
  306. data/src/core/lib/security/transport/secure_endpoint.cc +6 -6
  307. data/src/core/lib/security/transport/security_handshaker.cc +271 -303
  308. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  309. data/src/core/lib/security/transport/server_auth_filter.cc +3 -3
  310. data/src/core/lib/slice/b64.h +2 -2
  311. data/src/core/lib/slice/percent_encoding.cc +3 -3
  312. data/src/core/lib/slice/percent_encoding.h +3 -3
  313. data/src/core/lib/slice/slice.cc +174 -122
  314. data/src/core/lib/slice/slice_buffer.cc +54 -21
  315. data/src/core/lib/slice/slice_hash_table.h +4 -4
  316. data/src/core/lib/slice/slice_intern.cc +49 -107
  317. data/src/core/lib/slice/slice_internal.h +264 -3
  318. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  319. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  320. data/src/core/lib/slice/slice_utils.h +50 -0
  321. data/src/core/lib/slice/slice_weak_hash_table.h +6 -6
  322. data/src/core/lib/surface/api_trace.h +1 -1
  323. data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
  324. data/src/core/lib/surface/call.cc +67 -46
  325. data/src/core/lib/surface/call.h +7 -2
  326. data/src/core/lib/surface/call_details.cc +0 -1
  327. data/src/core/lib/surface/channel.cc +89 -97
  328. data/src/core/lib/surface/channel.h +60 -6
  329. data/src/core/lib/surface/channel_init.h +5 -0
  330. data/src/core/lib/surface/completion_queue.cc +221 -216
  331. data/src/core/lib/surface/completion_queue.h +2 -1
  332. data/src/core/lib/surface/init.cc +82 -33
  333. data/src/core/lib/surface/init.h +1 -0
  334. data/src/core/lib/surface/init_secure.cc +1 -1
  335. data/src/core/lib/surface/lame_client.cc +5 -7
  336. data/src/core/lib/surface/server.cc +42 -47
  337. data/src/core/lib/surface/validate_metadata.cc +14 -8
  338. data/src/core/lib/surface/validate_metadata.h +13 -2
  339. data/src/core/lib/surface/version.cc +1 -1
  340. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  341. data/src/core/lib/transport/bdp_estimator.h +2 -2
  342. data/src/core/lib/transport/connectivity_state.cc +10 -40
  343. data/src/core/lib/transport/connectivity_state.h +0 -8
  344. data/src/core/lib/transport/error_utils.cc +12 -0
  345. data/src/core/lib/transport/metadata.cc +258 -267
  346. data/src/core/lib/transport/metadata.h +227 -16
  347. data/src/core/lib/transport/metadata_batch.cc +1 -1
  348. data/src/core/lib/transport/metadata_batch.h +1 -1
  349. data/src/core/lib/transport/static_metadata.cc +477 -399
  350. data/src/core/lib/transport/static_metadata.h +273 -182
  351. data/src/core/lib/transport/status_metadata.cc +3 -3
  352. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  353. data/src/core/lib/transport/timeout_encoding.h +1 -1
  354. data/src/core/lib/transport/transport.cc +39 -72
  355. data/src/core/lib/transport/transport.h +59 -24
  356. data/src/core/lib/transport/transport_impl.h +1 -1
  357. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
  358. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
  359. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  360. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
  361. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
  362. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
  363. data/src/core/tsi/fake_transport_security.cc +4 -4
  364. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  365. data/src/core/tsi/ssl_transport_security.cc +12 -10
  366. data/src/core/tsi/ssl_transport_security.h +24 -4
  367. data/src/ruby/bin/math_pb.rb +18 -16
  368. data/src/ruby/ext/grpc/extconf.rb +12 -4
  369. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  370. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  371. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  372. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  373. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  374. data/src/ruby/ext/grpc/rb_grpc.c +23 -24
  375. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  376. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +24 -0
  377. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -0
  378. data/src/ruby/ext/grpc/rb_server.c +8 -4
  379. data/src/ruby/lib/grpc/errors.rb +22 -3
  380. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  381. data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
  382. data/src/ruby/lib/grpc/version.rb +1 -1
  383. data/src/ruby/pb/README.md +1 -1
  384. data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
  385. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
  386. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
  387. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
  388. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
  389. data/src/ruby/spec/errors_spec.rb +141 -0
  390. data/third_party/cares/cares/ares.h +12 -0
  391. data/third_party/cares/cares/ares_create_query.c +5 -1
  392. data/third_party/cares/cares/ares_data.c +74 -73
  393. data/third_party/cares/cares/ares_destroy.c +6 -1
  394. data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
  395. data/third_party/cares/cares/ares_gethostbyname.c +15 -4
  396. data/third_party/cares/cares/ares_getnameinfo.c +11 -0
  397. data/third_party/cares/cares/ares_init.c +274 -173
  398. data/third_party/cares/cares/ares_library_init.c +21 -3
  399. data/third_party/cares/cares/ares_options.c +6 -2
  400. data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
  401. data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
  402. data/third_party/cares/cares/ares_platform.c +7 -0
  403. data/third_party/cares/cares/ares_private.h +19 -11
  404. data/third_party/cares/cares/ares_process.c +27 -2
  405. data/third_party/cares/cares/ares_rules.h +1 -1
  406. data/third_party/cares/cares/ares_search.c +7 -0
  407. data/third_party/cares/cares/ares_send.c +6 -0
  408. data/third_party/cares/cares/ares_strsplit.c +174 -0
  409. data/third_party/cares/cares/ares_strsplit.h +43 -0
  410. data/third_party/cares/cares/ares_version.h +4 -4
  411. data/third_party/cares/cares/config-win32.h +1 -1
  412. data/third_party/cares/cares/inet_ntop.c +2 -3
  413. data/third_party/cares/config_darwin/ares_config.h +3 -0
  414. data/third_party/cares/config_freebsd/ares_config.h +3 -0
  415. data/third_party/cares/config_linux/ares_config.h +3 -0
  416. data/third_party/cares/config_openbsd/ares_config.h +3 -0
  417. metadata +83 -48
  418. data/src/core/ext/filters/client_channel/request_routing.cc +0 -936
  419. data/src/core/ext/filters/client_channel/request_routing.h +0 -177
  420. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  421. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  422. data/src/core/lib/channel/handshaker_factory.cc +0 -42
  423. data/src/core/lib/gpr/arena.cc +0 -192
  424. data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
  425. data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
  426. data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
  427. data/src/core/lib/transport/service_config.cc +0 -106
  428. data/src/core/lib/transport/service_config.h +0 -249
@@ -22,12 +22,12 @@
22
22
 
23
23
  #ifdef GRPC_POSIX_SOCKET_TCP
24
24
 
25
- #include "src/core/lib/iomgr/network_status_tracker.h"
26
25
  #include "src/core/lib/iomgr/tcp_posix.h"
27
26
 
28
27
  #include <errno.h>
29
28
  #include <limits.h>
30
29
  #include <netinet/in.h>
30
+ #include <netinet/tcp.h>
31
31
  #include <stdbool.h>
32
32
  #include <stdio.h>
33
33
  #include <stdlib.h>
@@ -35,6 +35,7 @@
35
35
  #include <sys/socket.h>
36
36
  #include <sys/types.h>
37
37
  #include <unistd.h>
38
+ #include <algorithm>
38
39
 
39
40
  #include <grpc/slice.h>
40
41
  #include <grpc/support/alloc.h>
@@ -55,6 +56,15 @@
55
56
  #include "src/core/lib/slice/slice_internal.h"
56
57
  #include "src/core/lib/slice/slice_string_helpers.h"
57
58
 
59
+ #ifndef SOL_TCP
60
+ #define SOL_TCP IPPROTO_TCP
61
+ #endif
62
+
63
+ #ifndef TCP_INQ
64
+ #define TCP_INQ 36
65
+ #define TCP_CM_INQ TCP_INQ
66
+ #endif
67
+
58
68
  #ifdef GRPC_HAVE_MSG_NOSIGNAL
59
69
  #define SENDMSG_FLAGS MSG_NOSIGNAL
60
70
  #else
@@ -89,8 +99,11 @@ struct grpc_tcp {
89
99
  grpc_slice_buffer last_read_buffer;
90
100
 
91
101
  grpc_slice_buffer* incoming_buffer;
102
+ int inq; /* bytes pending on the socket from the last read. */
103
+ bool inq_capable; /* cache whether kernel supports inq */
104
+
92
105
  grpc_slice_buffer* outgoing_buffer;
93
- /** byte within outgoing_buffer->slices[0] to write next */
106
+ /* byte within outgoing_buffer->slices[0] to write next */
94
107
  size_t outgoing_byte_idx;
95
108
 
96
109
  grpc_closure* read_cb;
@@ -127,9 +140,8 @@ struct grpc_tcp {
127
140
  bool socket_ts_enabled; /* True if timestamping options are set on the socket
128
141
  */
129
142
  bool ts_capable; /* Cache whether we can set timestamping options */
130
- gpr_atm
131
- stop_error_notification; /* Set to 1 if we do not want to be notified on
132
- errors anymore */
143
+ gpr_atm stop_error_notification; /* Set to 1 if we do not want to be notified
144
+ on errors anymore */
133
145
  };
134
146
 
135
147
  struct backup_poller {
@@ -151,7 +163,7 @@ static void tcp_drop_uncovered_then_handle_write(void* arg /* grpc_tcp */,
151
163
 
152
164
  static void done_poller(void* bp, grpc_error* error_ignored) {
153
165
  backup_poller* p = static_cast<backup_poller*>(bp);
154
- if (grpc_tcp_trace.enabled()) {
166
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
155
167
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p destroy", p);
156
168
  }
157
169
  grpc_pollset_destroy(BACKUP_POLLER_POLLSET(p));
@@ -160,7 +172,7 @@ static void done_poller(void* bp, grpc_error* error_ignored) {
160
172
 
161
173
  static void run_poller(void* bp, grpc_error* error_ignored) {
162
174
  backup_poller* p = static_cast<backup_poller*>(bp);
163
- if (grpc_tcp_trace.enabled()) {
175
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
164
176
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p run", p);
165
177
  }
166
178
  gpr_mu_lock(p->pollset_mu);
@@ -176,18 +188,18 @@ static void run_poller(void* bp, grpc_error* error_ignored) {
176
188
  gpr_atm_full_cas(&g_uncovered_notifications_pending, 1, 0)) {
177
189
  gpr_mu_lock(p->pollset_mu);
178
190
  bool cas_ok = gpr_atm_full_cas(&g_backup_poller, (gpr_atm)p, 0);
179
- if (grpc_tcp_trace.enabled()) {
191
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
180
192
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok);
181
193
  }
182
194
  gpr_mu_unlock(p->pollset_mu);
183
- if (grpc_tcp_trace.enabled()) {
195
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
184
196
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p shutdown", p);
185
197
  }
186
198
  grpc_pollset_shutdown(BACKUP_POLLER_POLLSET(p),
187
199
  GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p,
188
200
  grpc_schedule_on_exec_ctx));
189
201
  } else {
190
- if (grpc_tcp_trace.enabled()) {
202
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
191
203
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p reschedule", p);
192
204
  }
193
205
  GRPC_CLOSURE_SCHED(&p->run_poller, GRPC_ERROR_NONE);
@@ -197,8 +209,8 @@ static void run_poller(void* bp, grpc_error* error_ignored) {
197
209
  static void drop_uncovered(grpc_tcp* tcp) {
198
210
  backup_poller* p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller);
199
211
  gpr_atm old_count =
200
- gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1);
201
- if (grpc_tcp_trace.enabled()) {
212
+ gpr_atm_full_fetch_add(&g_uncovered_notifications_pending, -1);
213
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
202
214
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p uncover cnt %d->%d", p,
203
215
  static_cast<int>(old_count), static_cast<int>(old_count) - 1);
204
216
  }
@@ -216,7 +228,7 @@ static void cover_self(grpc_tcp* tcp) {
216
228
  backup_poller* p;
217
229
  gpr_atm old_count =
218
230
  gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2);
219
- if (grpc_tcp_trace.enabled()) {
231
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
220
232
  gpr_log(GPR_INFO, "BACKUP_POLLER: cover cnt %d->%d",
221
233
  static_cast<int>(old_count), 2 + static_cast<int>(old_count));
222
234
  }
@@ -224,22 +236,22 @@ static void cover_self(grpc_tcp* tcp) {
224
236
  GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED();
225
237
  p = static_cast<backup_poller*>(
226
238
  gpr_zalloc(sizeof(*p) + grpc_pollset_size()));
227
- if (grpc_tcp_trace.enabled()) {
239
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
228
240
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p create", p);
229
241
  }
230
242
  grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu);
231
243
  gpr_atm_rel_store(&g_backup_poller, (gpr_atm)p);
232
- GRPC_CLOSURE_SCHED(
233
- GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p,
234
- grpc_executor_scheduler(GRPC_EXECUTOR_LONG)),
235
- GRPC_ERROR_NONE);
244
+ GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&p->run_poller, run_poller, p,
245
+ grpc_core::Executor::Scheduler(
246
+ grpc_core::ExecutorJobType::LONG)),
247
+ GRPC_ERROR_NONE);
236
248
  } else {
237
249
  while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) ==
238
250
  nullptr) {
239
251
  // spin waiting for backup poller
240
252
  }
241
253
  }
242
- if (grpc_tcp_trace.enabled()) {
254
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
243
255
  gpr_log(GPR_INFO, "BACKUP_POLLER:%p add %p", p, tcp);
244
256
  }
245
257
  grpc_pollset_add_fd(BACKUP_POLLER_POLLSET(p), tcp->em_fd);
@@ -249,34 +261,24 @@ static void cover_self(grpc_tcp* tcp) {
249
261
  }
250
262
 
251
263
  static void notify_on_read(grpc_tcp* tcp) {
252
- if (grpc_tcp_trace.enabled()) {
264
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
253
265
  gpr_log(GPR_INFO, "TCP:%p notify_on_read", tcp);
254
266
  }
255
- GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp,
256
- grpc_schedule_on_exec_ctx);
257
267
  grpc_fd_notify_on_read(tcp->em_fd, &tcp->read_done_closure);
258
268
  }
259
269
 
260
270
  static void notify_on_write(grpc_tcp* tcp) {
261
- if (grpc_tcp_trace.enabled()) {
271
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
262
272
  gpr_log(GPR_INFO, "TCP:%p notify_on_write", tcp);
263
273
  }
264
- if (grpc_event_engine_run_in_background()) {
265
- // If there is a polling engine always running in the background, there is
266
- // no need to run the backup poller.
267
- GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_handle_write, tcp,
268
- grpc_schedule_on_exec_ctx);
269
- } else {
274
+ if (!grpc_event_engine_run_in_background()) {
270
275
  cover_self(tcp);
271
- GRPC_CLOSURE_INIT(&tcp->write_done_closure,
272
- tcp_drop_uncovered_then_handle_write, tcp,
273
- grpc_schedule_on_exec_ctx);
274
276
  }
275
277
  grpc_fd_notify_on_write(tcp->em_fd, &tcp->write_done_closure);
276
278
  }
277
279
 
278
280
  static void tcp_drop_uncovered_then_handle_write(void* arg, grpc_error* error) {
279
- if (grpc_tcp_trace.enabled()) {
281
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
280
282
  gpr_log(GPR_INFO, "TCP:%p got_write: %s", arg, grpc_error_string(error));
281
283
  }
282
284
  drop_uncovered(static_cast<grpc_tcp*>(arg));
@@ -345,6 +347,13 @@ static void tcp_free(grpc_tcp* tcp) {
345
347
  grpc_slice_buffer_destroy_internal(&tcp->last_read_buffer);
346
348
  grpc_resource_user_unref(tcp->resource_user);
347
349
  gpr_free(tcp->peer_string);
350
+ /* The lock is not really necessary here, since all refs have been released */
351
+ gpr_mu_lock(&tcp->tb_mu);
352
+ grpc_core::TracedBuffer::Shutdown(
353
+ &tcp->tb_head, tcp->outgoing_buffer_arg,
354
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
355
+ gpr_mu_unlock(&tcp->tb_mu);
356
+ tcp->outgoing_buffer_arg = nullptr;
348
357
  gpr_mu_destroy(&tcp->tb_mu);
349
358
  gpr_free(tcp);
350
359
  }
@@ -354,7 +363,7 @@ static void tcp_free(grpc_tcp* tcp) {
354
363
  #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__)
355
364
  static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file,
356
365
  int line) {
357
- if (grpc_tcp_trace.enabled()) {
366
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
358
367
  gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
359
368
  gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
360
369
  "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@@ -367,7 +376,7 @@ static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file,
367
376
 
368
377
  static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file,
369
378
  int line) {
370
- if (grpc_tcp_trace.enabled()) {
379
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
371
380
  gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
372
381
  gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
373
382
  "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@@ -388,16 +397,9 @@ static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); }
388
397
  #endif
389
398
 
390
399
  static void tcp_destroy(grpc_endpoint* ep) {
391
- grpc_network_status_unregister_endpoint(ep);
392
400
  grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
393
401
  grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
394
402
  if (grpc_event_engine_can_track_errors()) {
395
- gpr_mu_lock(&tcp->tb_mu);
396
- grpc_core::TracedBuffer::Shutdown(
397
- &tcp->tb_head, tcp->outgoing_buffer_arg,
398
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
399
- gpr_mu_unlock(&tcp->tb_mu);
400
- tcp->outgoing_buffer_arg = nullptr;
401
403
  gpr_atm_no_barrier_store(&tcp->stop_error_notification, true);
402
404
  grpc_fd_set_error(tcp->em_fd);
403
405
  }
@@ -407,17 +409,19 @@ static void tcp_destroy(grpc_endpoint* ep) {
407
409
  static void call_read_cb(grpc_tcp* tcp, grpc_error* error) {
408
410
  grpc_closure* cb = tcp->read_cb;
409
411
 
410
- if (grpc_tcp_trace.enabled()) {
412
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
411
413
  gpr_log(GPR_INFO, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg);
412
414
  size_t i;
413
415
  const char* str = grpc_error_string(error);
414
- gpr_log(GPR_INFO, "read: error=%s", str);
415
-
416
- for (i = 0; i < tcp->incoming_buffer->count; i++) {
417
- char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i],
418
- GPR_DUMP_HEX | GPR_DUMP_ASCII);
419
- gpr_log(GPR_INFO, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump);
420
- gpr_free(dump);
416
+ gpr_log(GPR_INFO, "READ %p (peer=%s) error=%s", tcp, tcp->peer_string, str);
417
+
418
+ if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
419
+ for (i = 0; i < tcp->incoming_buffer->count; i++) {
420
+ char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i],
421
+ GPR_DUMP_HEX | GPR_DUMP_ASCII);
422
+ gpr_log(GPR_DEBUG, "DATA: %s", dump);
423
+ gpr_free(dump);
424
+ }
421
425
  }
422
426
  }
423
427
 
@@ -431,74 +435,145 @@ static void tcp_do_read(grpc_tcp* tcp) {
431
435
  GPR_TIMER_SCOPE("tcp_do_read", 0);
432
436
  struct msghdr msg;
433
437
  struct iovec iov[MAX_READ_IOVEC];
438
+ char cmsgbuf[24 /*CMSG_SPACE(sizeof(int))*/];
434
439
  ssize_t read_bytes;
435
- size_t i;
440
+ size_t total_read_bytes = 0;
436
441
 
437
- GPR_ASSERT(tcp->incoming_buffer->count <= MAX_READ_IOVEC);
438
-
439
- for (i = 0; i < tcp->incoming_buffer->count; i++) {
442
+ size_t iov_len =
443
+ std::min<size_t>(MAX_READ_IOVEC, tcp->incoming_buffer->count);
444
+ for (size_t i = 0; i < iov_len; i++) {
440
445
  iov[i].iov_base = GRPC_SLICE_START_PTR(tcp->incoming_buffer->slices[i]);
441
446
  iov[i].iov_len = GRPC_SLICE_LENGTH(tcp->incoming_buffer->slices[i]);
442
447
  }
443
448
 
444
- msg.msg_name = nullptr;
445
- msg.msg_namelen = 0;
446
- msg.msg_iov = iov;
447
- msg.msg_iovlen = static_cast<msg_iovlen_type>(tcp->incoming_buffer->count);
448
- msg.msg_control = nullptr;
449
- msg.msg_controllen = 0;
450
- msg.msg_flags = 0;
451
-
452
- GRPC_STATS_INC_TCP_READ_OFFER(tcp->incoming_buffer->length);
453
- GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(tcp->incoming_buffer->count);
454
-
455
449
  do {
456
- GPR_TIMER_SCOPE("recvmsg", 0);
457
- GRPC_STATS_INC_SYSCALL_READ();
458
- read_bytes = recvmsg(tcp->fd, &msg, 0);
459
- } while (read_bytes < 0 && errno == EINTR);
460
-
461
- if (read_bytes < 0) {
462
- /* NB: After calling call_read_cb a parallel call of the read handler may
463
- * be running. */
464
- if (errno == EAGAIN) {
465
- finish_estimate(tcp);
466
- /* We've consumed the edge, request a new one */
467
- notify_on_read(tcp);
450
+ /* Assume there is something on the queue. If we receive TCP_INQ from
451
+ * kernel, we will update this value, otherwise, we have to assume there is
452
+ * always something to read until we get EAGAIN. */
453
+ tcp->inq = 1;
454
+
455
+ msg.msg_name = nullptr;
456
+ msg.msg_namelen = 0;
457
+ msg.msg_iov = iov;
458
+ msg.msg_iovlen = static_cast<msg_iovlen_type>(iov_len);
459
+ if (tcp->inq_capable) {
460
+ msg.msg_control = cmsgbuf;
461
+ msg.msg_controllen = sizeof(cmsgbuf);
468
462
  } else {
463
+ msg.msg_control = nullptr;
464
+ msg.msg_controllen = 0;
465
+ }
466
+ msg.msg_flags = 0;
467
+
468
+ GRPC_STATS_INC_TCP_READ_OFFER(tcp->incoming_buffer->length);
469
+ GRPC_STATS_INC_TCP_READ_OFFER_IOV_SIZE(tcp->incoming_buffer->count);
470
+
471
+ do {
472
+ GPR_TIMER_SCOPE("recvmsg", 0);
473
+ GRPC_STATS_INC_SYSCALL_READ();
474
+ read_bytes = recvmsg(tcp->fd, &msg, 0);
475
+ } while (read_bytes < 0 && errno == EINTR);
476
+
477
+ /* We have read something in previous reads. We need to deliver those
478
+ * bytes to the upper layer. */
479
+ if (read_bytes <= 0 && total_read_bytes > 0) {
480
+ tcp->inq = 1;
481
+ break;
482
+ }
483
+
484
+ if (read_bytes < 0) {
485
+ /* NB: After calling call_read_cb a parallel call of the read handler may
486
+ * be running. */
487
+ if (errno == EAGAIN) {
488
+ finish_estimate(tcp);
489
+ tcp->inq = 0;
490
+ /* We've consumed the edge, request a new one */
491
+ notify_on_read(tcp);
492
+ } else {
493
+ grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer);
494
+ call_read_cb(tcp,
495
+ tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp));
496
+ TCP_UNREF(tcp, "read");
497
+ }
498
+ return;
499
+ }
500
+ if (read_bytes == 0) {
501
+ /* 0 read size ==> end of stream
502
+ *
503
+ * We may have read something, i.e., total_read_bytes > 0, but
504
+ * since the connection is closed we will drop the data here, because we
505
+ * can't call the callback multiple times. */
469
506
  grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer);
470
- call_read_cb(tcp,
471
- tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp));
507
+ call_read_cb(
508
+ tcp, tcp_annotate_error(
509
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp));
472
510
  TCP_UNREF(tcp, "read");
511
+ return;
473
512
  }
474
- } else if (read_bytes == 0) {
475
- /* 0 read size ==> end of stream */
476
- grpc_slice_buffer_reset_and_unref_internal(tcp->incoming_buffer);
477
- call_read_cb(
478
- tcp, tcp_annotate_error(
479
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp));
480
- TCP_UNREF(tcp, "read");
481
- } else {
513
+
482
514
  GRPC_STATS_INC_TCP_READ_SIZE(read_bytes);
483
515
  add_to_estimate(tcp, static_cast<size_t>(read_bytes));
484
- GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length);
485
- if (static_cast<size_t>(read_bytes) == tcp->incoming_buffer->length) {
486
- finish_estimate(tcp);
487
- } else if (static_cast<size_t>(read_bytes) < tcp->incoming_buffer->length) {
488
- grpc_slice_buffer_trim_end(
489
- tcp->incoming_buffer,
490
- tcp->incoming_buffer->length - static_cast<size_t>(read_bytes),
491
- &tcp->last_read_buffer);
516
+ GPR_DEBUG_ASSERT((size_t)read_bytes <=
517
+ tcp->incoming_buffer->length - total_read_bytes);
518
+
519
+ #ifdef GRPC_HAVE_TCP_INQ
520
+ if (tcp->inq_capable) {
521
+ GPR_DEBUG_ASSERT(!(msg.msg_flags & MSG_CTRUNC));
522
+ struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
523
+ for (; cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
524
+ if (cmsg->cmsg_level == SOL_TCP && cmsg->cmsg_type == TCP_CM_INQ &&
525
+ cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
526
+ tcp->inq = *reinterpret_cast<int*>(CMSG_DATA(cmsg));
527
+ }
528
+ }
492
529
  }
493
- GPR_ASSERT((size_t)read_bytes == tcp->incoming_buffer->length);
494
- call_read_cb(tcp, GRPC_ERROR_NONE);
495
- TCP_UNREF(tcp, "read");
530
+ #endif /* GRPC_HAVE_TCP_INQ */
531
+
532
+ total_read_bytes += read_bytes;
533
+ if (tcp->inq == 0 || total_read_bytes == tcp->incoming_buffer->length) {
534
+ /* We have filled incoming_buffer, and we cannot read any more. */
535
+ break;
536
+ }
537
+
538
+ /* We had a partial read, and still have space to read more data.
539
+ * So, adjust IOVs and try to read more. */
540
+ size_t remaining = read_bytes;
541
+ size_t j = 0;
542
+ for (size_t i = 0; i < iov_len; i++) {
543
+ if (remaining >= iov[i].iov_len) {
544
+ remaining -= iov[i].iov_len;
545
+ continue;
546
+ }
547
+ if (remaining > 0) {
548
+ iov[j].iov_base = static_cast<char*>(iov[i].iov_base) + remaining;
549
+ iov[j].iov_len = iov[i].iov_len - remaining;
550
+ remaining = 0;
551
+ } else {
552
+ iov[j].iov_base = iov[i].iov_base;
553
+ iov[j].iov_len = iov[i].iov_len;
554
+ }
555
+ ++j;
556
+ }
557
+ iov_len = j;
558
+ } while (true);
559
+
560
+ if (tcp->inq == 0) {
561
+ finish_estimate(tcp);
562
+ }
563
+
564
+ GPR_DEBUG_ASSERT(total_read_bytes > 0);
565
+ if (total_read_bytes < tcp->incoming_buffer->length) {
566
+ grpc_slice_buffer_trim_end(tcp->incoming_buffer,
567
+ tcp->incoming_buffer->length - total_read_bytes,
568
+ &tcp->last_read_buffer);
496
569
  }
570
+ call_read_cb(tcp, GRPC_ERROR_NONE);
571
+ TCP_UNREF(tcp, "read");
497
572
  }
498
573
 
499
574
  static void tcp_read_allocation_done(void* tcpp, grpc_error* error) {
500
575
  grpc_tcp* tcp = static_cast<grpc_tcp*>(tcpp);
501
- if (grpc_tcp_trace.enabled()) {
576
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
502
577
  gpr_log(GPR_INFO, "TCP:%p read_allocation_done: %s", tcp,
503
578
  grpc_error_string(error));
504
579
  }
@@ -514,15 +589,16 @@ static void tcp_read_allocation_done(void* tcpp, grpc_error* error) {
514
589
 
515
590
  static void tcp_continue_read(grpc_tcp* tcp) {
516
591
  size_t target_read_size = get_target_read_size(tcp);
517
- if (tcp->incoming_buffer->length < target_read_size / 2 &&
592
+ /* Wait for allocation only when there is no buffer left. */
593
+ if (tcp->incoming_buffer->length == 0 &&
518
594
  tcp->incoming_buffer->count < MAX_READ_IOVEC) {
519
- if (grpc_tcp_trace.enabled()) {
595
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
520
596
  gpr_log(GPR_INFO, "TCP:%p alloc_slices", tcp);
521
597
  }
522
598
  grpc_resource_user_alloc_slices(&tcp->slice_allocator, target_read_size, 1,
523
599
  tcp->incoming_buffer);
524
600
  } else {
525
- if (grpc_tcp_trace.enabled()) {
601
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
526
602
  gpr_log(GPR_INFO, "TCP:%p do_read", tcp);
527
603
  }
528
604
  tcp_do_read(tcp);
@@ -531,7 +607,7 @@ static void tcp_continue_read(grpc_tcp* tcp) {
531
607
 
532
608
  static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) {
533
609
  grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
534
- if (grpc_tcp_trace.enabled()) {
610
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
535
611
  gpr_log(GPR_INFO, "TCP:%p got_read: %s", tcp, grpc_error_string(error));
536
612
  }
537
613
 
@@ -546,7 +622,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) {
546
622
  }
547
623
 
548
624
  static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer,
549
- grpc_closure* cb) {
625
+ grpc_closure* cb, bool urgent) {
550
626
  grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
551
627
  GPR_ASSERT(tcp->read_cb == nullptr);
552
628
  tcp->read_cb = cb;
@@ -559,6 +635,11 @@ static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer,
559
635
  * the polling engine */
560
636
  tcp->is_first_read = false;
561
637
  notify_on_read(tcp);
638
+ } else if (!urgent && tcp->inq == 0) {
639
+ /* Upper layer asked to read more but we know there is no pending data
640
+ * to read from previous reads. So, wait for POLLIN.
641
+ */
642
+ notify_on_read(tcp);
562
643
  } else {
563
644
  /* Not the first time. We may or may not have more bytes available. In any
564
645
  * case call tcp->read_done_closure (i.e tcp_handle_read()) which does the
@@ -596,6 +677,7 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
596
677
  static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
597
678
 
598
679
  #ifdef GRPC_LINUX_ERRQUEUE
680
+
599
681
  static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
600
682
  size_t sending_length,
601
683
  ssize_t* sent_length) {
@@ -603,8 +685,7 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
603
685
  uint32_t opt = grpc_core::kTimestampingSocketOptions;
604
686
  if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING,
605
687
  static_cast<void*>(&opt), sizeof(opt)) != 0) {
606
- grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
607
- if (grpc_tcp_trace.enabled()) {
688
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
608
689
  gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket.");
609
690
  }
610
691
  return false;
@@ -634,7 +715,7 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
634
715
  gpr_mu_lock(&tcp->tb_mu);
635
716
  grpc_core::TracedBuffer::AddNewEntry(
636
717
  &tcp->tb_head, static_cast<uint32_t>(tcp->bytes_counter + length),
637
- tcp->outgoing_buffer_arg);
718
+ tcp->fd, tcp->outgoing_buffer_arg);
638
719
  gpr_mu_unlock(&tcp->tb_mu);
639
720
  tcp->outgoing_buffer_arg = nullptr;
640
721
  }
@@ -651,17 +732,31 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
651
732
  struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
652
733
  struct cmsghdr* cmsg) {
653
734
  auto next_cmsg = CMSG_NXTHDR(msg, cmsg);
735
+ cmsghdr* opt_stats = nullptr;
654
736
  if (next_cmsg == nullptr) {
655
- if (grpc_tcp_trace.enabled()) {
737
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
656
738
  gpr_log(GPR_ERROR, "Received timestamp without extended error");
657
739
  }
658
740
  return cmsg;
659
741
  }
660
742
 
743
+ /* Check if next_cmsg is an OPT_STATS msg */
744
+ if (next_cmsg->cmsg_level == SOL_SOCKET &&
745
+ next_cmsg->cmsg_type == SCM_TIMESTAMPING_OPT_STATS) {
746
+ opt_stats = next_cmsg;
747
+ next_cmsg = CMSG_NXTHDR(msg, opt_stats);
748
+ if (next_cmsg == nullptr) {
749
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
750
+ gpr_log(GPR_ERROR, "Received timestamp without extended error");
751
+ }
752
+ return opt_stats;
753
+ }
754
+ }
755
+
661
756
  if (!(next_cmsg->cmsg_level == SOL_IP || next_cmsg->cmsg_level == SOL_IPV6) ||
662
757
  !(next_cmsg->cmsg_type == IP_RECVERR ||
663
758
  next_cmsg->cmsg_type == IPV6_RECVERR)) {
664
- if (grpc_tcp_trace.enabled()) {
759
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
665
760
  gpr_log(GPR_ERROR, "Unexpected control message");
666
761
  }
667
762
  return cmsg;
@@ -679,7 +774,8 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
679
774
  * to protect the traced buffer list. A lock free list might be better. Using
680
775
  * a simple mutex for now. */
681
776
  gpr_mu_lock(&tcp->tb_mu);
682
- grpc_core::TracedBuffer::ProcessTimestamp(&tcp->tb_head, serr, tss);
777
+ grpc_core::TracedBuffer::ProcessTimestamp(&tcp->tb_head, serr, opt_stats,
778
+ tss);
683
779
  gpr_mu_unlock(&tcp->tb_mu);
684
780
  return next_cmsg;
685
781
  }
@@ -699,9 +795,15 @@ static void process_errors(grpc_tcp* tcp) {
699
795
  msg.msg_iovlen = 0;
700
796
  msg.msg_flags = 0;
701
797
 
798
+ /* Allocate enough space so we don't need to keep increasing this as size
799
+ * of OPT_STATS increase */
800
+ constexpr size_t cmsg_alloc_space =
801
+ CMSG_SPACE(sizeof(grpc_core::scm_timestamping)) +
802
+ CMSG_SPACE(sizeof(sock_extended_err) + sizeof(sockaddr_in)) +
803
+ CMSG_SPACE(32 * NLA_ALIGN(NLA_HDRLEN + sizeof(uint64_t)));
804
+ /* Allocate aligned space for cmsgs received along with timestamps */
702
805
  union {
703
- char rbuf[1024 /*CMSG_SPACE(sizeof(scm_timestamping)) +
704
- CMSG_SPACE(sizeof(sock_extended_err) + sizeof(sockaddr_in))*/];
806
+ char rbuf[cmsg_alloc_space];
705
807
  struct cmsghdr align;
706
808
  } aligned_buf;
707
809
  memset(&aligned_buf, 0, sizeof(aligned_buf));
@@ -721,10 +823,8 @@ static void process_errors(grpc_tcp* tcp) {
721
823
  if (r == -1) {
722
824
  return;
723
825
  }
724
- if (grpc_tcp_trace.enabled()) {
725
- if ((msg.msg_flags & MSG_CTRUNC) == 1) {
726
- gpr_log(GPR_INFO, "Error message was truncated.");
727
- }
826
+ if ((msg.msg_flags & MSG_CTRUNC) != 0) {
827
+ gpr_log(GPR_ERROR, "Error message was truncated.");
728
828
  }
729
829
 
730
830
  if (msg.msg_controllen == 0) {
@@ -738,7 +838,7 @@ static void process_errors(grpc_tcp* tcp) {
738
838
  cmsg->cmsg_type != SCM_TIMESTAMPING) {
739
839
  /* Got a control message that is not a timestamp. Don't know how to
740
840
  * handle this. */
741
- if (grpc_tcp_trace.enabled()) {
841
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
742
842
  gpr_log(GPR_INFO,
743
843
  "unknown control message cmsg_level:%d cmsg_type:%d",
744
844
  cmsg->cmsg_level, cmsg->cmsg_type);
@@ -756,7 +856,7 @@ static void process_errors(grpc_tcp* tcp) {
756
856
 
757
857
  static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
758
858
  grpc_tcp* tcp = static_cast<grpc_tcp*>(arg);
759
- if (grpc_tcp_trace.enabled()) {
859
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
760
860
  gpr_log(GPR_INFO, "TCP:%p got_error: %s", tcp, grpc_error_string(error));
761
861
  }
762
862
 
@@ -775,8 +875,6 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
775
875
  * ready. */
776
876
  grpc_fd_set_readable(tcp->em_fd);
777
877
  grpc_fd_set_writable(tcp->em_fd);
778
- GRPC_CLOSURE_INIT(&tcp->error_closure, tcp_handle_error, tcp,
779
- grpc_schedule_on_exec_ctx);
780
878
  grpc_fd_notify_on_error(tcp->em_fd, &tcp->error_closure);
781
879
  }
782
880
 
@@ -881,8 +979,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
881
979
  // unref all and forget about all slices that have been written to this
882
980
  // point
883
981
  for (size_t idx = 0; idx < unwind_slice_idx; ++idx) {
884
- grpc_slice_unref_internal(
885
- grpc_slice_buffer_take_first(tcp->outgoing_buffer));
982
+ grpc_slice_buffer_remove_first(tcp->outgoing_buffer);
886
983
  }
887
984
  return false;
888
985
  } else if (errno == EPIPE) {
@@ -935,14 +1032,14 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) {
935
1032
  }
936
1033
 
937
1034
  if (!tcp_flush(tcp, &error)) {
938
- if (grpc_tcp_trace.enabled()) {
1035
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
939
1036
  gpr_log(GPR_INFO, "write: delayed");
940
1037
  }
941
1038
  notify_on_write(tcp);
942
1039
  } else {
943
1040
  cb = tcp->write_cb;
944
1041
  tcp->write_cb = nullptr;
945
- if (grpc_tcp_trace.enabled()) {
1042
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
946
1043
  const char* str = grpc_error_string(error);
947
1044
  gpr_log(GPR_INFO, "write: %s", str);
948
1045
  }
@@ -957,14 +1054,17 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
957
1054
  grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
958
1055
  grpc_error* error = GRPC_ERROR_NONE;
959
1056
 
960
- if (grpc_tcp_trace.enabled()) {
1057
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
961
1058
  size_t i;
962
1059
 
963
1060
  for (i = 0; i < buf->count; i++) {
964
- char* data =
965
- grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
966
- gpr_log(GPR_INFO, "WRITE %p (peer=%s): %s", tcp, tcp->peer_string, data);
967
- gpr_free(data);
1061
+ gpr_log(GPR_INFO, "WRITE %p (peer=%s)", tcp, tcp->peer_string);
1062
+ if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1063
+ char* data =
1064
+ grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
1065
+ gpr_log(GPR_DEBUG, "DATA: %s", data);
1066
+ gpr_free(data);
1067
+ }
968
1068
  }
969
1069
  }
970
1070
 
@@ -989,12 +1089,12 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
989
1089
  if (!tcp_flush(tcp, &error)) {
990
1090
  TCP_REF(tcp, "write");
991
1091
  tcp->write_cb = cb;
992
- if (grpc_tcp_trace.enabled()) {
1092
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
993
1093
  gpr_log(GPR_INFO, "write: delayed");
994
1094
  }
995
1095
  notify_on_write(tcp);
996
1096
  } else {
997
- if (grpc_tcp_trace.enabled()) {
1097
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
998
1098
  const char* str = grpc_error_string(error);
999
1099
  gpr_log(GPR_INFO, "write: %s", str);
1000
1100
  }
@@ -1131,11 +1231,34 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
1131
1231
  tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string);
1132
1232
  grpc_resource_user_slice_allocator_init(
1133
1233
  &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp);
1134
- /* Tell network status tracker about new endpoint */
1135
- grpc_network_status_register_endpoint(&tcp->base);
1136
1234
  grpc_resource_quota_unref_internal(resource_quota);
1137
1235
  gpr_mu_init(&tcp->tb_mu);
1138
1236
  tcp->tb_head = nullptr;
1237
+ GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp,
1238
+ grpc_schedule_on_exec_ctx);
1239
+ if (grpc_event_engine_run_in_background()) {
1240
+ // If there is a polling engine always running in the background, there is
1241
+ // no need to run the backup poller.
1242
+ GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_handle_write, tcp,
1243
+ grpc_schedule_on_exec_ctx);
1244
+ } else {
1245
+ GRPC_CLOSURE_INIT(&tcp->write_done_closure,
1246
+ tcp_drop_uncovered_then_handle_write, tcp,
1247
+ grpc_schedule_on_exec_ctx);
1248
+ }
1249
+ /* Always assume there is something on the queue to read. */
1250
+ tcp->inq = 1;
1251
+ #ifdef GRPC_HAVE_TCP_INQ
1252
+ int one = 1;
1253
+ if (setsockopt(tcp->fd, SOL_TCP, TCP_INQ, &one, sizeof(one)) == 0) {
1254
+ tcp->inq_capable = true;
1255
+ } else {
1256
+ gpr_log(GPR_DEBUG, "cannot set inq fd=%d errno=%d", tcp->fd, errno);
1257
+ tcp->inq_capable = false;
1258
+ }
1259
+ #else
1260
+ tcp->inq_capable = false;
1261
+ #endif /* GRPC_HAVE_TCP_INQ */
1139
1262
  /* Start being notified on errors if event engine can track errors. */
1140
1263
  if (grpc_event_engine_can_track_errors()) {
1141
1264
  /* Grab a ref to tcp so that we can safely access the tcp struct when
@@ -1159,7 +1282,6 @@ int grpc_tcp_fd(grpc_endpoint* ep) {
1159
1282
 
1160
1283
  void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd,
1161
1284
  grpc_closure* done) {
1162
- grpc_network_status_unregister_endpoint(ep);
1163
1285
  grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
1164
1286
  GPR_ASSERT(ep->vtable == &vtable);
1165
1287
  tcp->release_fd = fd;
@@ -1167,12 +1289,6 @@ void grpc_tcp_destroy_and_release_fd(grpc_endpoint* ep, int* fd,
1167
1289
  grpc_slice_buffer_reset_and_unref_internal(&tcp->last_read_buffer);
1168
1290
  if (grpc_event_engine_can_track_errors()) {
1169
1291
  /* Stop errors notification. */
1170
- gpr_mu_lock(&tcp->tb_mu);
1171
- grpc_core::TracedBuffer::Shutdown(
1172
- &tcp->tb_head, tcp->outgoing_buffer_arg,
1173
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
1174
- gpr_mu_unlock(&tcp->tb_mu);
1175
- tcp->outgoing_buffer_arg = nullptr;
1176
1292
  gpr_atm_no_barrier_store(&tcp->stop_error_notification, true);
1177
1293
  grpc_fd_set_error(tcp->em_fd);
1178
1294
  }