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
@@ -41,9 +41,9 @@
41
41
  #include <grpc/support/alloc.h>
42
42
  #include <grpc/support/string_util.h>
43
43
 
44
- #include "src/core/ext/client_channel/connector.h"
45
- #include "src/core/ext/client_channel/http_connect_handshaker.h"
46
- #include "src/core/ext/client_channel/subchannel.h"
44
+ #include "src/core/ext/filters/client_channel/connector.h"
45
+ #include "src/core/ext/filters/client_channel/http_connect_handshaker.h"
46
+ #include "src/core/ext/filters/client_channel/subchannel.h"
47
47
  #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
48
48
  #include "src/core/lib/channel/channel_args.h"
49
49
  #include "src/core/lib/channel/handshaker.h"
@@ -63,8 +63,6 @@ typedef struct {
63
63
  grpc_closure *notify;
64
64
  grpc_connect_in_args args;
65
65
  grpc_connect_out_args *result;
66
- grpc_closure initial_string_sent;
67
- grpc_slice_buffer initial_string_buffer;
68
66
 
69
67
  grpc_endpoint *endpoint; // Non-NULL until handshaking starts.
70
68
 
@@ -82,7 +80,6 @@ static void chttp2_connector_unref(grpc_exec_ctx *exec_ctx,
82
80
  grpc_connector *con) {
83
81
  chttp2_connector *c = (chttp2_connector *)con;
84
82
  if (gpr_unref(&c->refs)) {
85
- /* c->initial_string_buffer does not need to be destroyed */
86
83
  gpr_mu_destroy(&c->mu);
87
84
  // If handshaking is not yet in progress, destroy the endpoint.
88
85
  // Otherwise, the handshaker will do this for us.
@@ -116,7 +113,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
116
113
  gpr_mu_lock(&c->mu);
117
114
  if (error != GRPC_ERROR_NONE || c->shutdown) {
118
115
  if (error == GRPC_ERROR_NONE) {
119
- error = GRPC_ERROR_CREATE("connector shutdown");
116
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("connector shutdown");
120
117
  // We were shut down after handshaking completed successfully, so
121
118
  // destroy the endpoint here.
122
119
  // TODO(ctiller): It is currently necessary to shutdown endpoints
@@ -160,28 +157,6 @@ static void start_handshake_locked(grpc_exec_ctx *exec_ctx,
160
157
  c->endpoint = NULL; // Endpoint handed off to handshake manager.
161
158
  }
162
159
 
163
- static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
164
- grpc_error *error) {
165
- chttp2_connector *c = arg;
166
- gpr_mu_lock(&c->mu);
167
- if (error != GRPC_ERROR_NONE || c->shutdown) {
168
- if (error == GRPC_ERROR_NONE) {
169
- error = GRPC_ERROR_CREATE("connector shutdown");
170
- } else {
171
- error = GRPC_ERROR_REF(error);
172
- }
173
- memset(c->result, 0, sizeof(*c->result));
174
- grpc_closure *notify = c->notify;
175
- c->notify = NULL;
176
- grpc_closure_sched(exec_ctx, notify, error);
177
- gpr_mu_unlock(&c->mu);
178
- chttp2_connector_unref(exec_ctx, arg);
179
- } else {
180
- start_handshake_locked(exec_ctx, c);
181
- gpr_mu_unlock(&c->mu);
182
- }
183
- }
184
-
185
160
  static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
186
161
  chttp2_connector *c = arg;
187
162
  gpr_mu_lock(&c->mu);
@@ -189,7 +164,7 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
189
164
  c->connecting = false;
190
165
  if (error != GRPC_ERROR_NONE || c->shutdown) {
191
166
  if (error == GRPC_ERROR_NONE) {
192
- error = GRPC_ERROR_CREATE("connector shutdown");
167
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("connector shutdown");
193
168
  } else {
194
169
  error = GRPC_ERROR_REF(error);
195
170
  }
@@ -204,17 +179,7 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
204
179
  chttp2_connector_unref(exec_ctx, arg);
205
180
  } else {
206
181
  GPR_ASSERT(c->endpoint != NULL);
207
- if (!GRPC_SLICE_IS_EMPTY(c->args.initial_connect_string)) {
208
- grpc_closure_init(&c->initial_string_sent, on_initial_connect_string_sent,
209
- c, grpc_schedule_on_exec_ctx);
210
- grpc_slice_buffer_init(&c->initial_string_buffer);
211
- grpc_slice_buffer_add(&c->initial_string_buffer,
212
- c->args.initial_connect_string);
213
- grpc_endpoint_write(exec_ctx, c->endpoint, &c->initial_string_buffer,
214
- &c->initial_string_sent);
215
- } else {
216
- start_handshake_locked(exec_ctx, c);
217
- }
182
+ start_handshake_locked(exec_ctx, c);
218
183
  gpr_mu_unlock(&c->mu);
219
184
  }
220
185
  }
@@ -34,7 +34,7 @@
34
34
  #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H
35
35
  #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H
36
36
 
37
- #include "src/core/ext/client_channel/connector.h"
37
+ #include "src/core/ext/filters/client_channel/connector.h"
38
38
 
39
39
  grpc_connector* grpc_chttp2_connector_create();
40
40
 
@@ -38,8 +38,8 @@
38
38
  #include <grpc/support/alloc.h>
39
39
  #include <grpc/support/string_util.h>
40
40
 
41
- #include "src/core/ext/client_channel/client_channel.h"
42
- #include "src/core/ext/client_channel/resolver_registry.h"
41
+ #include "src/core/ext/filters/client_channel/client_channel.h"
42
+ #include "src/core/ext/filters/client_channel/resolver_registry.h"
43
43
  #include "src/core/ext/transport/chttp2/client/chttp2_connector.h"
44
44
  #include "src/core/lib/channel/channel_args.h"
45
45
  #include "src/core/lib/surface/api_trace.h"
@@ -38,9 +38,9 @@
38
38
  #include <grpc/support/alloc.h>
39
39
  #include <grpc/support/string_util.h>
40
40
 
41
- #include "src/core/ext/client_channel/client_channel.h"
42
- #include "src/core/ext/client_channel/resolver_registry.h"
43
- #include "src/core/ext/client_channel/uri_parser.h"
41
+ #include "src/core/ext/filters/client_channel/client_channel.h"
42
+ #include "src/core/ext/filters/client_channel/resolver_registry.h"
43
+ #include "src/core/ext/filters/client_channel/uri_parser.h"
44
44
  #include "src/core/ext/transport/chttp2/client/chttp2_connector.h"
45
45
  #include "src/core/lib/channel/channel_args.h"
46
46
  #include "src/core/lib/iomgr/sockaddr_utils.h"
@@ -256,7 +256,7 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx,
256
256
  char *msg;
257
257
  gpr_asprintf(&msg, "No address added out of total %" PRIuPTR " resolved",
258
258
  naddrs);
259
- err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, naddrs);
259
+ err = GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(msg, errors, naddrs);
260
260
  gpr_free(msg);
261
261
  goto error;
262
262
  } else if (count != naddrs) {
@@ -264,7 +264,7 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx,
264
264
  gpr_asprintf(&msg, "Only %" PRIuPTR
265
265
  " addresses added out of total %" PRIuPTR " resolved",
266
266
  count, naddrs);
267
- err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, naddrs);
267
+ err = GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(msg, errors, naddrs);
268
268
  gpr_free(msg);
269
269
 
270
270
  const char *warning_message = grpc_error_string(err);
@@ -57,12 +57,9 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server,
57
57
  char *name;
58
58
  gpr_asprintf(&name, "fd:%d", fd);
59
59
 
60
- grpc_resource_quota *resource_quota = grpc_resource_quota_from_channel_args(
61
- grpc_server_get_channel_args(server));
62
60
  grpc_endpoint *server_endpoint =
63
- grpc_tcp_create(grpc_fd_create(fd, name), resource_quota,
64
- GRPC_TCP_DEFAULT_READ_SLICE_SIZE, name);
65
- grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
61
+ grpc_tcp_create(&exec_ctx, grpc_fd_create(fd, name),
62
+ grpc_server_get_channel_args(server), name);
66
63
 
67
64
  gpr_free(name);
68
65
 
@@ -61,7 +61,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
61
61
  3, (server, addr, creds));
62
62
  // Create security context.
63
63
  if (creds == NULL) {
64
- err = GRPC_ERROR_CREATE(
64
+ err = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
65
65
  "No credentials specified for secure server port (creds==NULL)");
66
66
  goto done;
67
67
  }
@@ -72,7 +72,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
72
72
  gpr_asprintf(&msg,
73
73
  "Unable to create secure server with credentials of type %s.",
74
74
  creds->type);
75
- err = grpc_error_set_int(GRPC_ERROR_CREATE(msg),
75
+ err = grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg),
76
76
  GRPC_ERROR_INT_SECURITY_STATUS, status);
77
77
  gpr_free(msg);
78
78
  goto done;
@@ -69,9 +69,23 @@
69
69
  #define MAX_WRITE_BUFFER_SIZE (64 * 1024 * 1024)
70
70
  #define DEFAULT_MAX_HEADER_LIST_SIZE (16 * 1024)
71
71
 
72
- #define DEFAULT_KEEPALIVE_TIME_SECOND INT_MAX
73
- #define DEFAULT_KEEPALIVE_TIMEOUT_SECOND 20
72
+ #define DEFAULT_CLIENT_KEEPALIVE_TIME_MS INT_MAX
73
+ #define DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS 20000 /* 20 seconds */
74
+ #define DEFAULT_SERVER_KEEPALIVE_TIME_MS 7200000 /* 2 hours */
75
+ #define DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS 20000 /* 20 seconds */
74
76
  #define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS false
77
+ #define KEEPALIVE_TIME_BACKOFF_MULTIPLIER 2
78
+
79
+ static int g_default_client_keepalive_time_ms =
80
+ DEFAULT_CLIENT_KEEPALIVE_TIME_MS;
81
+ static int g_default_client_keepalive_timeout_ms =
82
+ DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS;
83
+ static int g_default_server_keepalive_time_ms =
84
+ DEFAULT_SERVER_KEEPALIVE_TIME_MS;
85
+ static int g_default_server_keepalive_timeout_ms =
86
+ DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS;
87
+ static bool g_default_keepalive_permit_without_calls =
88
+ DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS;
75
89
 
76
90
  #define MAX_CLIENT_STREAM_ID 0x7fffffffu
77
91
  int grpc_http_trace = 0;
@@ -142,9 +156,13 @@ static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
142
156
  grpc_chttp2_ping_type ping_type,
143
157
  grpc_closure *on_initiate,
144
158
  grpc_closure *on_complete);
159
+ static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
160
+ grpc_error *error);
145
161
 
146
162
  #define DEFAULT_MIN_TIME_BETWEEN_PINGS_MS 0
147
163
  #define DEFAULT_MAX_PINGS_BETWEEN_DATA 3
164
+ #define DEFAULT_MAX_PING_STRIKES 2
165
+ #define DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS 300000 /* 5 minutes */
148
166
 
149
167
  /** keepalive-relevant functions */
150
168
  static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
@@ -187,7 +205,8 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx,
187
205
 
188
206
  GRPC_COMBINER_UNREF(exec_ctx, t->combiner, "chttp2_transport");
189
207
 
190
- cancel_pings(exec_ctx, t, GRPC_ERROR_CREATE("Transport destroyed"));
208
+ cancel_pings(exec_ctx, t,
209
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"));
191
210
 
192
211
  while (t->write_cb_pool) {
193
212
  grpc_chttp2_write_cb *next = t->write_cb_pool->next;
@@ -266,6 +285,8 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
266
285
  grpc_closure_init(&t->destructive_reclaimer_locked,
267
286
  destructive_reclaimer_locked, t,
268
287
  grpc_combiner_scheduler(t->combiner, false));
288
+ grpc_closure_init(&t->retry_initiate_ping_locked, retry_initiate_ping_locked,
289
+ t, grpc_combiner_scheduler(t->combiner, false));
269
290
  grpc_closure_init(&t->start_bdp_ping_locked, start_bdp_ping_locked, t,
270
291
  grpc_combiner_scheduler(t->combiner, false));
271
292
  grpc_closure_init(&t->finish_bdp_ping_locked, finish_bdp_ping_locked, t,
@@ -335,24 +356,43 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
335
356
  DEFAULT_WINDOW);
336
357
  push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
337
358
  DEFAULT_MAX_HEADER_LIST_SIZE);
359
+ push_setting(exec_ctx, t,
360
+ GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1);
338
361
 
339
362
  t->ping_policy = (grpc_chttp2_repeated_ping_policy){
340
363
  .max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA,
341
364
  .min_time_between_pings =
342
365
  gpr_time_from_millis(DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, GPR_TIMESPAN),
366
+ .max_ping_strikes = DEFAULT_MAX_PING_STRIKES,
367
+ .min_ping_interval_without_data = gpr_time_from_millis(
368
+ DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, GPR_TIMESPAN),
343
369
  };
344
370
 
345
- /* client-side keepalive setting */
346
- t->keepalive_time =
347
- DEFAULT_KEEPALIVE_TIME_SECOND == INT_MAX
348
- ? gpr_inf_future(GPR_TIMESPAN)
349
- : gpr_time_from_seconds(DEFAULT_KEEPALIVE_TIME_SECOND, GPR_TIMESPAN);
350
- t->keepalive_timeout =
351
- DEFAULT_KEEPALIVE_TIMEOUT_SECOND == INT_MAX
352
- ? gpr_inf_future(GPR_TIMESPAN)
353
- : gpr_time_from_seconds(DEFAULT_KEEPALIVE_TIMEOUT_SECOND,
354
- GPR_TIMESPAN);
355
- t->keepalive_permit_without_calls = DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS;
371
+ /* Keepalive setting */
372
+ if (t->is_client) {
373
+ t->keepalive_time =
374
+ g_default_client_keepalive_time_ms == INT_MAX
375
+ ? gpr_inf_future(GPR_TIMESPAN)
376
+ : gpr_time_from_millis(g_default_client_keepalive_time_ms,
377
+ GPR_TIMESPAN);
378
+ t->keepalive_timeout =
379
+ g_default_client_keepalive_timeout_ms == INT_MAX
380
+ ? gpr_inf_future(GPR_TIMESPAN)
381
+ : gpr_time_from_millis(g_default_client_keepalive_timeout_ms,
382
+ GPR_TIMESPAN);
383
+ } else {
384
+ t->keepalive_time =
385
+ g_default_server_keepalive_time_ms == INT_MAX
386
+ ? gpr_inf_future(GPR_TIMESPAN)
387
+ : gpr_time_from_millis(g_default_server_keepalive_time_ms,
388
+ GPR_TIMESPAN);
389
+ t->keepalive_timeout =
390
+ g_default_server_keepalive_timeout_ms == INT_MAX
391
+ ? gpr_inf_future(GPR_TIMESPAN)
392
+ : gpr_time_from_millis(g_default_server_keepalive_timeout_ms,
393
+ GPR_TIMESPAN);
394
+ }
395
+ t->keepalive_permit_without_calls = g_default_keepalive_permit_without_calls;
356
396
 
357
397
  if (channel_args) {
358
398
  for (i = 0; i < channel_args->num_args; i++) {
@@ -384,6 +424,11 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
384
424
  t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer(
385
425
  &channel_args->args[i],
386
426
  (grpc_integer_options){DEFAULT_MAX_PINGS_BETWEEN_DATA, 0, INT_MAX});
427
+ } else if (0 == strcmp(channel_args->args[i].key,
428
+ GRPC_ARG_HTTP2_MAX_PING_STRIKES)) {
429
+ t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer(
430
+ &channel_args->args[i],
431
+ (grpc_integer_options){DEFAULT_MAX_PING_STRIKES, 0, INT_MAX});
387
432
  } else if (0 == strcmp(channel_args->args[i].key,
388
433
  GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS)) {
389
434
  t->ping_policy.min_time_between_pings = gpr_time_from_millis(
@@ -392,6 +437,15 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
392
437
  (grpc_integer_options){DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, 0,
393
438
  INT_MAX}),
394
439
  GPR_TIMESPAN);
440
+ } else if (0 ==
441
+ strcmp(channel_args->args[i].key,
442
+ GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS)) {
443
+ t->ping_policy.min_ping_interval_without_data = gpr_time_from_millis(
444
+ grpc_channel_arg_get_integer(
445
+ &channel_args->args[i],
446
+ (grpc_integer_options){
447
+ DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, 0, INT_MAX}),
448
+ GPR_TIMESPAN);
395
449
  } else if (0 == strcmp(channel_args->args[i].key,
396
450
  GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) {
397
451
  t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer(
@@ -402,24 +456,29 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
402
456
  t->enable_bdp_probe = grpc_channel_arg_get_integer(
403
457
  &channel_args->args[i], (grpc_integer_options){1, 0, 1});
404
458
  } else if (0 == strcmp(channel_args->args[i].key,
405
- GRPC_ARG_HTTP2_KEEPALIVE_TIME)) {
459
+ GRPC_ARG_KEEPALIVE_TIME_MS)) {
406
460
  const int value = grpc_channel_arg_get_integer(
407
461
  &channel_args->args[i],
408
- (grpc_integer_options){DEFAULT_KEEPALIVE_TIME_SECOND, 1, INT_MAX});
462
+ (grpc_integer_options){t->is_client
463
+ ? g_default_client_keepalive_time_ms
464
+ : g_default_server_keepalive_time_ms,
465
+ 1, INT_MAX});
409
466
  t->keepalive_time = value == INT_MAX
410
467
  ? gpr_inf_future(GPR_TIMESPAN)
411
- : gpr_time_from_seconds(value, GPR_TIMESPAN);
468
+ : gpr_time_from_millis(value, GPR_TIMESPAN);
412
469
  } else if (0 == strcmp(channel_args->args[i].key,
413
- GRPC_ARG_HTTP2_KEEPALIVE_TIMEOUT)) {
470
+ GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
414
471
  const int value = grpc_channel_arg_get_integer(
415
472
  &channel_args->args[i],
416
- (grpc_integer_options){DEFAULT_KEEPALIVE_TIMEOUT_SECOND, 0,
417
- INT_MAX});
473
+ (grpc_integer_options){t->is_client
474
+ ? g_default_client_keepalive_timeout_ms
475
+ : g_default_server_keepalive_timeout_ms,
476
+ 0, INT_MAX});
418
477
  t->keepalive_timeout = value == INT_MAX
419
478
  ? gpr_inf_future(GPR_TIMESPAN)
420
- : gpr_time_from_seconds(value, GPR_TIMESPAN);
479
+ : gpr_time_from_millis(value, GPR_TIMESPAN);
421
480
  } else if (0 == strcmp(channel_args->args[i].key,
422
- GRPC_ARG_HTTP2_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
481
+ GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
423
482
  t->keepalive_permit_without_calls =
424
483
  (uint32_t)grpc_channel_arg_get_integer(
425
484
  &channel_args->args[i], (grpc_integer_options){0, 0, 1});
@@ -429,26 +488,31 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
429
488
  grpc_chttp2_setting_id setting_id;
430
489
  grpc_integer_options integer_options;
431
490
  bool availability[2] /* server, client */;
432
- } settings_map[] = {{GRPC_ARG_MAX_CONCURRENT_STREAMS,
433
- GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
434
- {-1, 0, INT32_MAX},
435
- {true, false}},
436
- {GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER,
437
- GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
438
- {-1, 0, INT32_MAX},
439
- {true, true}},
440
- {GRPC_ARG_MAX_METADATA_SIZE,
441
- GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
442
- {-1, 0, INT32_MAX},
443
- {true, true}},
444
- {GRPC_ARG_HTTP2_MAX_FRAME_SIZE,
445
- GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE,
446
- {-1, 16384, 16777215},
447
- {true, true}},
448
- {GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES,
449
- GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
450
- {-1, 5, INT32_MAX},
451
- {true, true}}};
491
+ } settings_map[] = {
492
+ {GRPC_ARG_MAX_CONCURRENT_STREAMS,
493
+ GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
494
+ {-1, 0, INT32_MAX},
495
+ {true, false}},
496
+ {GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER,
497
+ GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
498
+ {-1, 0, INT32_MAX},
499
+ {true, true}},
500
+ {GRPC_ARG_MAX_METADATA_SIZE,
501
+ GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
502
+ {-1, 0, INT32_MAX},
503
+ {true, true}},
504
+ {GRPC_ARG_HTTP2_MAX_FRAME_SIZE,
505
+ GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE,
506
+ {-1, 16384, 16777215},
507
+ {true, true}},
508
+ {GRPC_ARG_HTTP2_ENABLE_TRUE_BINARY,
509
+ GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA,
510
+ {1, 0, 1},
511
+ {true, true}},
512
+ {GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES,
513
+ GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
514
+ {-1, 5, INT32_MAX},
515
+ {true, true}}};
452
516
  for (j = 0; j < (int)GPR_ARRAY_SIZE(settings_map); j++) {
453
517
  if (0 == strcmp(channel_args->args[i].key,
454
518
  settings_map[j].channel_arg_name)) {
@@ -473,9 +537,13 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
473
537
 
474
538
  t->ping_state.pings_before_data_required =
475
539
  t->ping_policy.max_pings_without_data;
540
+ t->ping_state.is_delayed_ping_timer_set = false;
476
541
 
477
- /** Start client-side keepalive pings */
478
- if (t->is_client) {
542
+ t->ping_recv_state.last_ping_recv_time = gpr_inf_past(GPR_CLOCK_MONOTONIC);
543
+ t->ping_recv_state.ping_strikes = 0;
544
+
545
+ /* Start keepalive pings */
546
+ if (gpr_time_cmp(t->keepalive_time, gpr_inf_future(GPR_TIMESPAN)) != 0) {
479
547
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
480
548
  GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
481
549
  grpc_timer_init(
@@ -494,8 +562,9 @@ static void destroy_transport_locked(grpc_exec_ctx *exec_ctx, void *tp,
494
562
  t->destroying = 1;
495
563
  close_transport_locked(
496
564
  exec_ctx, t,
497
- grpc_error_set_int(GRPC_ERROR_CREATE("Transport destroyed"),
498
- GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state));
565
+ grpc_error_set_int(
566
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"),
567
+ GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state));
499
568
  GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destroy");
500
569
  }
501
570
 
@@ -518,7 +587,8 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx,
518
587
  if (t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE) {
519
588
  if (t->close_transport_on_writes_finished == NULL) {
520
589
  t->close_transport_on_writes_finished =
521
- GRPC_ERROR_CREATE("Delayed close due to in-progress write");
590
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
591
+ "Delayed close due to in-progress write");
522
592
  }
523
593
  t->close_transport_on_writes_finished =
524
594
  grpc_error_add_child(t->close_transport_on_writes_finished, error);
@@ -575,7 +645,7 @@ void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s) {
575
645
 
576
646
  static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
577
647
  grpc_stream *gs, grpc_stream_refcount *refcount,
578
- const void *server_data) {
648
+ const void *server_data, gpr_arena *arena) {
579
649
  GPR_TIMER_BEGIN("init_stream", 0);
580
650
  grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
581
651
  grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
@@ -588,8 +658,8 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
588
658
  gpr_ref_init(&s->active_streams, 1);
589
659
  GRPC_CHTTP2_STREAM_REF(s, "chttp2");
590
660
 
591
- grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[0]);
592
- grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[1]);
661
+ grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[0], arena);
662
+ grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[1], arena);
593
663
  grpc_chttp2_data_parser_init(&s->data_parser);
594
664
  grpc_slice_buffer_init(&s->flow_controlled_buffer);
595
665
  s->deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
@@ -665,16 +735,17 @@ static void destroy_stream_locked(grpc_exec_ctx *exec_ctx, void *sp,
665
735
 
666
736
  GPR_TIMER_END("destroy_stream", 0);
667
737
 
668
- gpr_free(s->destroy_stream_arg);
738
+ grpc_closure_sched(exec_ctx, s->destroy_stream_arg, GRPC_ERROR_NONE);
669
739
  }
670
740
 
671
741
  static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
672
- grpc_stream *gs, void *and_free_memory) {
742
+ grpc_stream *gs,
743
+ grpc_closure *then_schedule_closure) {
673
744
  GPR_TIMER_BEGIN("destroy_stream", 0);
674
745
  grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
675
746
  grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
676
747
 
677
- s->destroy_stream_arg = and_free_memory;
748
+ s->destroy_stream_arg = then_schedule_closure;
678
749
  grpc_closure_sched(
679
750
  exec_ctx, grpc_closure_init(&s->destroy_stream, destroy_stream_locked, s,
680
751
  grpc_combiner_scheduler(t->combiner, false)),
@@ -833,7 +904,8 @@ static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *tp,
833
904
  if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) {
834
905
  t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT;
835
906
  if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
836
- close_transport_locked(exec_ctx, t, GRPC_ERROR_CREATE("goaway sent"));
907
+ close_transport_locked(
908
+ exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent"));
837
909
  }
838
910
  }
839
911
 
@@ -897,22 +969,39 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx,
897
969
  grpc_chttp2_transport *t,
898
970
  uint32_t goaway_error,
899
971
  grpc_slice goaway_text) {
900
- char *msg = grpc_dump_slice(goaway_text, GPR_DUMP_HEX | GPR_DUMP_ASCII);
901
- GRPC_CHTTP2_IF_TRACING(
902
- gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg));
903
- grpc_slice_unref_internal(exec_ctx, goaway_text);
972
+ // GRPC_CHTTP2_IF_TRACING(
973
+ // gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg));
904
974
  t->seen_goaway = 1;
975
+
976
+ /* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug
977
+ * data equal to “too_many_pings”, it should log the occurrence at a log level
978
+ * that is enabled by default and double the configured KEEPALIVE_TIME used
979
+ * for new connections on that channel. */
980
+ if (t->is_client && goaway_error == GRPC_HTTP2_ENHANCE_YOUR_CALM &&
981
+ grpc_slice_str_cmp(goaway_text, "too_many_pings") == 0) {
982
+ gpr_log(GPR_ERROR,
983
+ "Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug "
984
+ "data equal to \"too_many_pings\"");
985
+ double current_keepalive_time_ms =
986
+ gpr_timespec_to_micros(t->keepalive_time) / 1000;
987
+ t->keepalive_time =
988
+ current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER
989
+ ? gpr_inf_future(GPR_TIMESPAN)
990
+ : gpr_time_from_millis((int64_t)(current_keepalive_time_ms *
991
+ KEEPALIVE_TIME_BACKOFF_MULTIPLIER),
992
+ GPR_TIMESPAN);
993
+ }
994
+
905
995
  /* lie: use transient failure from the transport to indicate goaway has been
906
996
  * received */
907
997
  connectivity_state_set(
908
998
  exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
909
999
  grpc_error_set_str(
910
- grpc_error_set_int(GRPC_ERROR_CREATE("GOAWAY received"),
911
- GRPC_ERROR_INT_HTTP2_ERROR,
912
- (intptr_t)goaway_error),
913
- GRPC_ERROR_STR_RAW_BYTES, msg),
1000
+ grpc_error_set_int(
1001
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"),
1002
+ GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error),
1003
+ GRPC_ERROR_STR_RAW_BYTES, goaway_text),
914
1004
  "got_goaway");
915
- gpr_free(msg);
916
1005
  }
917
1006
 
918
1007
  static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx,
@@ -935,9 +1024,10 @@ static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx,
935
1024
  t->next_stream_id += 2;
936
1025
 
937
1026
  if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) {
938
- connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
939
- GRPC_ERROR_CREATE("Stream IDs exhausted"),
940
- "no_more_stream_ids");
1027
+ connectivity_state_set(
1028
+ exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
1029
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"),
1030
+ "no_more_stream_ids");
941
1031
  }
942
1032
 
943
1033
  grpc_chttp2_stream_map_add(&t->stream_map, s->id, s);
@@ -951,9 +1041,9 @@ static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx,
951
1041
  grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) {
952
1042
  grpc_chttp2_cancel_stream(
953
1043
  exec_ctx, t, s,
954
- grpc_error_set_int(GRPC_ERROR_CREATE("Stream IDs exhausted"),
955
- GRPC_ERROR_INT_GRPC_STATUS,
956
- GRPC_STATUS_UNAVAILABLE));
1044
+ grpc_error_set_int(
1045
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"),
1046
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE));
957
1047
  }
958
1048
  }
959
1049
 
@@ -1002,11 +1092,11 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx,
1002
1092
  }
1003
1093
  if (error != GRPC_ERROR_NONE) {
1004
1094
  if (closure->error_data.error == GRPC_ERROR_NONE) {
1005
- closure->error_data.error =
1006
- GRPC_ERROR_CREATE("Error in HTTP transport completing operation");
1007
- closure->error_data.error =
1008
- grpc_error_set_str(closure->error_data.error,
1009
- GRPC_ERROR_STR_TARGET_ADDRESS, t->peer_string);
1095
+ closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1096
+ "Error in HTTP transport completing operation");
1097
+ closure->error_data.error = grpc_error_set_str(
1098
+ closure->error_data.error, GRPC_ERROR_STR_TARGET_ADDRESS,
1099
+ grpc_slice_from_copied_string(t->peer_string));
1010
1100
  }
1011
1101
  closure->error_data.error =
1012
1102
  grpc_error_add_child(closure->error_data.error, error);
@@ -1086,7 +1176,7 @@ static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx,
1086
1176
  return; /* early out */
1087
1177
  } else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message,
1088
1178
  &s->fetching_slice, UINT32_MAX,
1089
- &s->complete_fetch)) {
1179
+ &s->complete_fetch_locked)) {
1090
1180
  add_fetched_slice_locked(exec_ctx, t, s);
1091
1181
  }
1092
1182
  }
@@ -1124,20 +1214,23 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1124
1214
  grpc_error *error_ignored) {
1125
1215
  GPR_TIMER_BEGIN("perform_stream_op_locked", 0);
1126
1216
 
1127
- grpc_transport_stream_op *op = stream_op;
1128
- grpc_chttp2_transport *t = op->handler_private.args[0];
1129
- grpc_chttp2_stream *s = op->handler_private.args[1];
1217
+ grpc_transport_stream_op_batch *op = stream_op;
1218
+ grpc_chttp2_stream *s = op->handler_private.extra_arg;
1219
+ grpc_transport_stream_op_batch_payload *op_payload = op->payload;
1220
+ grpc_chttp2_transport *t = s->t;
1130
1221
 
1131
1222
  if (grpc_http_trace) {
1132
- char *str = grpc_transport_stream_op_string(op);
1223
+ char *str = grpc_transport_stream_op_batch_string(op);
1133
1224
  gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str,
1134
1225
  op->on_complete);
1135
1226
  gpr_free(str);
1136
1227
  if (op->send_initial_metadata) {
1137
- log_metadata(op->send_initial_metadata, s->id, t->is_client, true);
1228
+ log_metadata(op_payload->send_initial_metadata.send_initial_metadata,
1229
+ s->id, t->is_client, true);
1138
1230
  }
1139
1231
  if (op->send_trailing_metadata) {
1140
- log_metadata(op->send_trailing_metadata, s->id, t->is_client, false);
1232
+ log_metadata(op_payload->send_trailing_metadata.send_trailing_metadata,
1233
+ s->id, t->is_client, false);
1141
1234
  }
1142
1235
  }
1143
1236
 
@@ -1152,23 +1245,25 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1152
1245
  on_complete->next_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT;
1153
1246
  on_complete->error_data.error = GRPC_ERROR_NONE;
1154
1247
 
1155
- if (op->collect_stats != NULL) {
1248
+ if (op->collect_stats) {
1156
1249
  GPR_ASSERT(s->collecting_stats == NULL);
1157
- s->collecting_stats = op->collect_stats;
1250
+ s->collecting_stats = op_payload->collect_stats.collect_stats;
1158
1251
  on_complete->next_data.scratch |= CLOSURE_BARRIER_STATS_BIT;
1159
1252
  }
1160
1253
 
1161
- if (op->cancel_error != GRPC_ERROR_NONE) {
1162
- grpc_chttp2_cancel_stream(exec_ctx, t, s, op->cancel_error);
1254
+ if (op->cancel_stream) {
1255
+ grpc_chttp2_cancel_stream(exec_ctx, t, s,
1256
+ op_payload->cancel_stream.cancel_error);
1163
1257
  }
1164
1258
 
1165
- if (op->send_initial_metadata != NULL) {
1259
+ if (op->send_initial_metadata) {
1166
1260
  GPR_ASSERT(s->send_initial_metadata_finished == NULL);
1167
1261
  on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
1168
1262
  s->send_initial_metadata_finished = add_closure_barrier(on_complete);
1169
- s->send_initial_metadata = op->send_initial_metadata;
1263
+ s->send_initial_metadata =
1264
+ op_payload->send_initial_metadata.send_initial_metadata;
1170
1265
  const size_t metadata_size =
1171
- grpc_metadata_batch_size(op->send_initial_metadata);
1266
+ grpc_metadata_batch_size(s->send_initial_metadata);
1172
1267
  const size_t metadata_peer_limit =
1173
1268
  t->settings[GRPC_PEER_SETTINGS]
1174
1269
  [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
@@ -1181,14 +1276,15 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1181
1276
  exec_ctx, t, s,
1182
1277
  grpc_error_set_int(
1183
1278
  grpc_error_set_int(
1184
- grpc_error_set_int(
1185
- GRPC_ERROR_CREATE("to-be-sent initial metadata size "
1186
- "exceeds peer limit"),
1187
- GRPC_ERROR_INT_SIZE, (intptr_t)metadata_size),
1279
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1280
+ "to-be-sent initial metadata size "
1281
+ "exceeds peer limit"),
1282
+ GRPC_ERROR_INT_SIZE,
1283
+ (intptr_t)metadata_size),
1188
1284
  GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit),
1189
1285
  GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
1190
1286
  } else {
1191
- if (contains_non_ok_status(op->send_initial_metadata)) {
1287
+ if (contains_non_ok_status(s->send_initial_metadata)) {
1192
1288
  s->seen_error = true;
1193
1289
  }
1194
1290
  if (!s->write_closed) {
@@ -1200,21 +1296,27 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1200
1296
  } else {
1201
1297
  grpc_chttp2_cancel_stream(
1202
1298
  exec_ctx, t, s,
1203
- grpc_error_set_int(GRPC_ERROR_CREATE("Transport closed"),
1204
- GRPC_ERROR_INT_GRPC_STATUS,
1205
- GRPC_STATUS_UNAVAILABLE));
1299
+ grpc_error_set_int(
1300
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed"),
1301
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE));
1206
1302
  }
1207
1303
  } else {
1208
1304
  GPR_ASSERT(s->id != 0);
1209
- grpc_chttp2_become_writable(exec_ctx, t, s,
1210
- GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED,
1305
+ grpc_chttp2_stream_write_type write_type =
1306
+ GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED;
1307
+ if (op->send_message &&
1308
+ (op->payload->send_message.send_message->flags &
1309
+ GRPC_WRITE_BUFFER_HINT)) {
1310
+ write_type = GRPC_CHTTP2_STREAM_WRITE_PIGGYBACK;
1311
+ }
1312
+ grpc_chttp2_become_writable(exec_ctx, t, s, write_type,
1211
1313
  "op.send_initial_metadata");
1212
1314
  }
1213
1315
  } else {
1214
1316
  s->send_initial_metadata = NULL;
1215
1317
  grpc_chttp2_complete_closure_step(
1216
1318
  exec_ctx, t, s, &s->send_initial_metadata_finished,
1217
- GRPC_ERROR_CREATE_REFERENCING(
1319
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
1218
1320
  "Attempt to send initial metadata after stream was closed",
1219
1321
  &s->write_closed_error, 1),
1220
1322
  "send_initial_metadata_finished");
@@ -1222,13 +1324,13 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1222
1324
  }
1223
1325
  }
1224
1326
 
1225
- if (op->send_message != NULL) {
1327
+ if (op->send_message) {
1226
1328
  on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
1227
1329
  s->fetching_send_message_finished = add_closure_barrier(op->on_complete);
1228
1330
  if (s->write_closed) {
1229
1331
  grpc_chttp2_complete_closure_step(
1230
1332
  exec_ctx, t, s, &s->fetching_send_message_finished,
1231
- GRPC_ERROR_CREATE_REFERENCING(
1333
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
1232
1334
  "Attempt to send message after stream was closed",
1233
1335
  &s->write_closed_error, 1),
1234
1336
  "fetching_send_message_finished");
@@ -1236,14 +1338,14 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1236
1338
  GPR_ASSERT(s->fetching_send_message == NULL);
1237
1339
  uint8_t *frame_hdr =
1238
1340
  grpc_slice_buffer_tiny_add(&s->flow_controlled_buffer, 5);
1239
- uint32_t flags = op->send_message->flags;
1341
+ uint32_t flags = op_payload->send_message.send_message->flags;
1240
1342
  frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0;
1241
- size_t len = op->send_message->length;
1343
+ size_t len = op_payload->send_message.send_message->length;
1242
1344
  frame_hdr[1] = (uint8_t)(len >> 24);
1243
1345
  frame_hdr[2] = (uint8_t)(len >> 16);
1244
1346
  frame_hdr[3] = (uint8_t)(len >> 8);
1245
1347
  frame_hdr[4] = (uint8_t)(len);
1246
- s->fetching_send_message = op->send_message;
1348
+ s->fetching_send_message = op_payload->send_message.send_message;
1247
1349
  s->fetched_send_message_length = 0;
1248
1350
  s->next_message_end_offset = s->flow_controlled_bytes_written +
1249
1351
  (int64_t)s->flow_controlled_buffer.length +
@@ -1260,14 +1362,15 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1260
1362
  }
1261
1363
  }
1262
1364
 
1263
- if (op->send_trailing_metadata != NULL) {
1365
+ if (op->send_trailing_metadata) {
1264
1366
  GPR_ASSERT(s->send_trailing_metadata_finished == NULL);
1265
1367
  on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
1266
1368
  s->send_trailing_metadata_finished = add_closure_barrier(on_complete);
1267
- s->send_trailing_metadata = op->send_trailing_metadata;
1369
+ s->send_trailing_metadata =
1370
+ op_payload->send_trailing_metadata.send_trailing_metadata;
1268
1371
  s->write_buffering = false;
1269
1372
  const size_t metadata_size =
1270
- grpc_metadata_batch_size(op->send_trailing_metadata);
1373
+ grpc_metadata_batch_size(s->send_trailing_metadata);
1271
1374
  const size_t metadata_peer_limit =
1272
1375
  t->settings[GRPC_PEER_SETTINGS]
1273
1376
  [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
@@ -1276,24 +1379,27 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1276
1379
  exec_ctx, t, s,
1277
1380
  grpc_error_set_int(
1278
1381
  grpc_error_set_int(
1279
- grpc_error_set_int(
1280
- GRPC_ERROR_CREATE("to-be-sent trailing metadata size "
1281
- "exceeds peer limit"),
1282
- GRPC_ERROR_INT_SIZE, (intptr_t)metadata_size),
1382
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1383
+ "to-be-sent trailing metadata size "
1384
+ "exceeds peer limit"),
1385
+ GRPC_ERROR_INT_SIZE,
1386
+ (intptr_t)metadata_size),
1283
1387
  GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit),
1284
1388
  GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
1285
1389
  } else {
1286
- if (contains_non_ok_status(op->send_trailing_metadata)) {
1390
+ if (contains_non_ok_status(s->send_trailing_metadata)) {
1287
1391
  s->seen_error = true;
1288
1392
  }
1289
1393
  if (s->write_closed) {
1290
1394
  s->send_trailing_metadata = NULL;
1291
1395
  grpc_chttp2_complete_closure_step(
1292
1396
  exec_ctx, t, s, &s->send_trailing_metadata_finished,
1293
- grpc_metadata_batch_is_empty(op->send_trailing_metadata)
1397
+ grpc_metadata_batch_is_empty(
1398
+ op->payload->send_trailing_metadata.send_trailing_metadata)
1294
1399
  ? GRPC_ERROR_NONE
1295
- : GRPC_ERROR_CREATE("Attempt to send trailing metadata after "
1296
- "stream was closed"),
1400
+ : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1401
+ "Attempt to send trailing metadata after "
1402
+ "stream was closed"),
1297
1403
  "send_trailing_metadata_finished");
1298
1404
  } else if (s->id != 0) {
1299
1405
  /* TODO(ctiller): check if there's flow control for any outstanding
@@ -1305,17 +1411,19 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1305
1411
  }
1306
1412
  }
1307
1413
 
1308
- if (op->recv_initial_metadata != NULL) {
1414
+ if (op->recv_initial_metadata) {
1309
1415
  GPR_ASSERT(s->recv_initial_metadata_ready == NULL);
1310
- s->recv_initial_metadata_ready = op->recv_initial_metadata_ready;
1311
- s->recv_initial_metadata = op->recv_initial_metadata;
1416
+ s->recv_initial_metadata_ready =
1417
+ op_payload->recv_initial_metadata.recv_initial_metadata_ready;
1418
+ s->recv_initial_metadata =
1419
+ op_payload->recv_initial_metadata.recv_initial_metadata;
1312
1420
  grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s);
1313
1421
  }
1314
1422
 
1315
- if (op->recv_message != NULL) {
1423
+ if (op->recv_message) {
1316
1424
  GPR_ASSERT(s->recv_message_ready == NULL);
1317
- s->recv_message_ready = op->recv_message_ready;
1318
- s->recv_message = op->recv_message;
1425
+ s->recv_message_ready = op_payload->recv_message.recv_message_ready;
1426
+ s->recv_message = op_payload->recv_message.recv_message;
1319
1427
  if (s->id != 0 &&
1320
1428
  (s->incoming_frames.head == NULL || s->incoming_frames.head->is_tail)) {
1321
1429
  incoming_byte_stream_update_flow_control(exec_ctx, t, s, 5, 0);
@@ -1323,10 +1431,11 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1323
1431
  grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
1324
1432
  }
1325
1433
 
1326
- if (op->recv_trailing_metadata != NULL) {
1434
+ if (op->recv_trailing_metadata) {
1327
1435
  GPR_ASSERT(s->recv_trailing_metadata_finished == NULL);
1328
1436
  s->recv_trailing_metadata_finished = add_closure_barrier(on_complete);
1329
- s->recv_trailing_metadata = op->recv_trailing_metadata;
1437
+ s->recv_trailing_metadata =
1438
+ op_payload->recv_trailing_metadata.recv_trailing_metadata;
1330
1439
  s->final_metadata_requested = true;
1331
1440
  grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
1332
1441
  }
@@ -1339,19 +1448,19 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
1339
1448
  }
1340
1449
 
1341
1450
  static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
1342
- grpc_stream *gs, grpc_transport_stream_op *op) {
1451
+ grpc_stream *gs,
1452
+ grpc_transport_stream_op_batch *op) {
1343
1453
  GPR_TIMER_BEGIN("perform_stream_op", 0);
1344
1454
  grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
1345
1455
  grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
1346
1456
 
1347
1457
  if (grpc_http_trace) {
1348
- char *str = grpc_transport_stream_op_string(op);
1458
+ char *str = grpc_transport_stream_op_batch_string(op);
1349
1459
  gpr_log(GPR_DEBUG, "perform_stream_op[s=%p/%d]: %s", s, s->id, str);
1350
1460
  gpr_free(str);
1351
1461
  }
1352
1462
 
1353
- op->handler_private.args[0] = gt;
1354
- op->handler_private.args[1] = gs;
1463
+ op->handler_private.extra_arg = gs;
1355
1464
  GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op");
1356
1465
  grpc_closure_sched(
1357
1466
  exec_ctx,
@@ -1388,6 +1497,13 @@ static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1388
1497
  }
1389
1498
  }
1390
1499
 
1500
+ static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
1501
+ grpc_error *error) {
1502
+ grpc_chttp2_transport *t = tp;
1503
+ t->ping_state.is_delayed_ping_timer_set = false;
1504
+ grpc_chttp2_initiate_write(exec_ctx, t, false, "retry_send_ping");
1505
+ }
1506
+
1391
1507
  void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1392
1508
  uint64_t id) {
1393
1509
  grpc_chttp2_ping_queue *pq =
@@ -1408,20 +1524,35 @@ static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1408
1524
  grpc_error *error) {
1409
1525
  t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED;
1410
1526
  grpc_http2_error_code http_error;
1411
- const char *msg;
1412
- grpc_error_get_status(error, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL, &msg,
1413
- &http_error);
1527
+ grpc_slice slice;
1528
+ grpc_error_get_status(error, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL,
1529
+ &slice, &http_error);
1414
1530
  grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error,
1415
- grpc_slice_from_copied_string(msg), &t->qbuf);
1531
+ grpc_slice_ref_internal(slice), &t->qbuf);
1416
1532
  grpc_chttp2_initiate_write(exec_ctx, t, false, "goaway_sent");
1417
1533
  GRPC_ERROR_UNREF(error);
1418
1534
  }
1419
1535
 
1536
+ void grpc_chttp2_add_ping_strike(grpc_exec_ctx *exec_ctx,
1537
+ grpc_chttp2_transport *t) {
1538
+ gpr_log(GPR_DEBUG, "PING strike");
1539
+ if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes &&
1540
+ t->ping_policy.max_ping_strikes != 0) {
1541
+ send_goaway(exec_ctx, t,
1542
+ grpc_error_set_int(
1543
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"),
1544
+ GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
1545
+ /*The transport will be closed after the write is done */
1546
+ close_transport_locked(
1547
+ exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"));
1548
+ }
1549
+ }
1550
+
1420
1551
  static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx,
1421
1552
  void *stream_op,
1422
1553
  grpc_error *error_ignored) {
1423
1554
  grpc_transport_op *op = stream_op;
1424
- grpc_chttp2_transport *t = op->transport_private.args[0];
1555
+ grpc_chttp2_transport *t = op->handler_private.extra_arg;
1425
1556
  grpc_error *close_transport = op->disconnect_with_error;
1426
1557
 
1427
1558
  if (op->on_connectivity_state_change != NULL) {
@@ -1467,10 +1598,10 @@ static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
1467
1598
  grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
1468
1599
  char *msg = grpc_transport_op_string(op);
1469
1600
  gpr_free(msg);
1470
- op->transport_private.args[0] = gt;
1601
+ op->handler_private.extra_arg = gt;
1471
1602
  GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op");
1472
1603
  grpc_closure_sched(
1473
- exec_ctx, grpc_closure_init(&op->transport_private.closure,
1604
+ exec_ctx, grpc_closure_init(&op->handler_private.closure,
1474
1605
  perform_transport_op_locked, op,
1475
1606
  grpc_combiner_scheduler(t->combiner, false)),
1476
1607
  GRPC_ERROR_NONE);
@@ -1572,7 +1703,7 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1572
1703
  if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SENT) {
1573
1704
  close_transport_locked(
1574
1705
  exec_ctx, t,
1575
- GRPC_ERROR_CREATE_REFERENCING(
1706
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
1576
1707
  "Last stream closed after sending GOAWAY", &error, 1));
1577
1708
  }
1578
1709
  }
@@ -1613,8 +1744,8 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx,
1613
1744
  void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1614
1745
  grpc_chttp2_stream *s, grpc_error *error) {
1615
1746
  grpc_status_code status;
1616
- const char *msg;
1617
- grpc_error_get_status(error, s->deadline, &status, &msg, NULL);
1747
+ grpc_slice slice;
1748
+ grpc_error_get_status(error, s->deadline, &status, &slice, NULL);
1618
1749
 
1619
1750
  if (status != GRPC_STATUS_OK) {
1620
1751
  s->seen_error = true;
@@ -1629,15 +1760,19 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1629
1760
  s->recv_trailing_metadata_finished != NULL) {
1630
1761
  char status_string[GPR_LTOA_MIN_BUFSIZE];
1631
1762
  gpr_ltoa(status, status_string);
1632
- grpc_chttp2_incoming_metadata_buffer_replace_or_add(
1633
- exec_ctx, &s->metadata_buffer[1],
1634
- grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS,
1635
- grpc_slice_from_copied_string(status_string)));
1636
- if (msg != NULL) {
1637
- grpc_chttp2_incoming_metadata_buffer_replace_or_add(
1638
- exec_ctx, &s->metadata_buffer[1],
1639
- grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
1640
- grpc_slice_from_copied_string(msg)));
1763
+ GRPC_LOG_IF_ERROR("add_status",
1764
+ grpc_chttp2_incoming_metadata_buffer_replace_or_add(
1765
+ exec_ctx, &s->metadata_buffer[1],
1766
+ grpc_mdelem_from_slices(
1767
+ exec_ctx, GRPC_MDSTR_GRPC_STATUS,
1768
+ grpc_slice_from_copied_string(status_string))));
1769
+ if (!GRPC_SLICE_IS_EMPTY(slice)) {
1770
+ GRPC_LOG_IF_ERROR(
1771
+ "add_status_message",
1772
+ grpc_chttp2_incoming_metadata_buffer_replace_or_add(
1773
+ exec_ctx, &s->metadata_buffer[1],
1774
+ grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
1775
+ grpc_slice_ref_internal(slice))));
1641
1776
  }
1642
1777
  s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE;
1643
1778
  grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
@@ -1666,7 +1801,8 @@ static grpc_error *removal_error(grpc_error *extra_error, grpc_chttp2_stream *s,
1666
1801
  add_error(extra_error, refs, &nrefs);
1667
1802
  grpc_error *error = GRPC_ERROR_NONE;
1668
1803
  if (nrefs > 0) {
1669
- error = GRPC_ERROR_CREATE_REFERENCING(master_error_msg, refs, nrefs);
1804
+ error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(master_error_msg,
1805
+ refs, nrefs);
1670
1806
  }
1671
1807
  GRPC_ERROR_UNREF(extra_error);
1672
1808
  return error;
@@ -1760,12 +1896,14 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1760
1896
  grpc_chttp2_stream *s, grpc_error *error) {
1761
1897
  grpc_slice hdr;
1762
1898
  grpc_slice status_hdr;
1899
+ grpc_slice http_status_hdr;
1900
+ grpc_slice content_type_hdr;
1763
1901
  grpc_slice message_pfx;
1764
1902
  uint8_t *p;
1765
1903
  uint32_t len = 0;
1766
1904
  grpc_status_code grpc_status;
1767
- const char *msg;
1768
- grpc_error_get_status(error, s->deadline, &grpc_status, &msg, NULL);
1905
+ grpc_slice slice;
1906
+ grpc_error_get_status(error, s->deadline, &grpc_status, &slice, NULL);
1769
1907
 
1770
1908
  GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100);
1771
1909
 
@@ -1775,6 +1913,62 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1775
1913
  It's complicated by the fact that our send machinery would be dead by
1776
1914
  the time we got around to sending this, so instead we ignore HPACK
1777
1915
  compression and just write the uncompressed bytes onto the wire. */
1916
+ if (!s->sent_initial_metadata) {
1917
+ http_status_hdr = grpc_slice_malloc(13);
1918
+ p = GRPC_SLICE_START_PTR(http_status_hdr);
1919
+ *p++ = 0x00;
1920
+ *p++ = 7;
1921
+ *p++ = ':';
1922
+ *p++ = 's';
1923
+ *p++ = 't';
1924
+ *p++ = 'a';
1925
+ *p++ = 't';
1926
+ *p++ = 'u';
1927
+ *p++ = 's';
1928
+ *p++ = 3;
1929
+ *p++ = '2';
1930
+ *p++ = '0';
1931
+ *p++ = '0';
1932
+ GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr));
1933
+ len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr);
1934
+
1935
+ content_type_hdr = grpc_slice_malloc(31);
1936
+ p = GRPC_SLICE_START_PTR(content_type_hdr);
1937
+ *p++ = 0x00;
1938
+ *p++ = 12;
1939
+ *p++ = 'c';
1940
+ *p++ = 'o';
1941
+ *p++ = 'n';
1942
+ *p++ = 't';
1943
+ *p++ = 'e';
1944
+ *p++ = 'n';
1945
+ *p++ = 't';
1946
+ *p++ = '-';
1947
+ *p++ = 't';
1948
+ *p++ = 'y';
1949
+ *p++ = 'p';
1950
+ *p++ = 'e';
1951
+ *p++ = 16;
1952
+ *p++ = 'a';
1953
+ *p++ = 'p';
1954
+ *p++ = 'p';
1955
+ *p++ = 'l';
1956
+ *p++ = 'i';
1957
+ *p++ = 'c';
1958
+ *p++ = 'a';
1959
+ *p++ = 't';
1960
+ *p++ = 'i';
1961
+ *p++ = 'o';
1962
+ *p++ = 'n';
1963
+ *p++ = '/';
1964
+ *p++ = 'g';
1965
+ *p++ = 'r';
1966
+ *p++ = 'p';
1967
+ *p++ = 'c';
1968
+ GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr));
1969
+ len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr);
1970
+ }
1971
+
1778
1972
  status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10));
1779
1973
  p = GRPC_SLICE_START_PTR(status_hdr);
1780
1974
  *p++ = 0x00; /* literal header, not indexed */
@@ -1801,32 +1995,30 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1801
1995
  GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr));
1802
1996
  len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr);
1803
1997
 
1804
- if (msg != NULL) {
1805
- size_t msg_len = strlen(msg);
1806
- GPR_ASSERT(msg_len <= UINT32_MAX);
1807
- uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0);
1808
- message_pfx = grpc_slice_malloc(14 + msg_len_len);
1809
- p = GRPC_SLICE_START_PTR(message_pfx);
1810
- *p++ = 0x00; /* literal header, not indexed */
1811
- *p++ = 12; /* len(grpc-message) */
1812
- *p++ = 'g';
1813
- *p++ = 'r';
1814
- *p++ = 'p';
1815
- *p++ = 'c';
1816
- *p++ = '-';
1817
- *p++ = 'm';
1818
- *p++ = 'e';
1819
- *p++ = 's';
1820
- *p++ = 's';
1821
- *p++ = 'a';
1822
- *p++ = 'g';
1823
- *p++ = 'e';
1824
- GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 0, 0, p, (uint32_t)msg_len_len);
1825
- p += msg_len_len;
1826
- GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx));
1827
- len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx);
1828
- len += (uint32_t)msg_len;
1829
- }
1998
+ size_t msg_len = GRPC_SLICE_LENGTH(slice);
1999
+ GPR_ASSERT(msg_len <= UINT32_MAX);
2000
+ uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 1);
2001
+ message_pfx = grpc_slice_malloc(14 + msg_len_len);
2002
+ p = GRPC_SLICE_START_PTR(message_pfx);
2003
+ *p++ = 0x00; /* literal header, not indexed */
2004
+ *p++ = 12; /* len(grpc-message) */
2005
+ *p++ = 'g';
2006
+ *p++ = 'r';
2007
+ *p++ = 'p';
2008
+ *p++ = 'c';
2009
+ *p++ = '-';
2010
+ *p++ = 'm';
2011
+ *p++ = 'e';
2012
+ *p++ = 's';
2013
+ *p++ = 's';
2014
+ *p++ = 'a';
2015
+ *p++ = 'g';
2016
+ *p++ = 'e';
2017
+ GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 1, 0, p, (uint32_t)msg_len_len);
2018
+ p += msg_len_len;
2019
+ GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx));
2020
+ len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx);
2021
+ len += (uint32_t)msg_len;
1830
2022
 
1831
2023
  hdr = grpc_slice_malloc(9);
1832
2024
  p = GRPC_SLICE_START_PTR(hdr);
@@ -1842,11 +2034,13 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
1842
2034
  GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr));
1843
2035
 
1844
2036
  grpc_slice_buffer_add(&t->qbuf, hdr);
1845
- grpc_slice_buffer_add(&t->qbuf, status_hdr);
1846
- if (msg != NULL) {
1847
- grpc_slice_buffer_add(&t->qbuf, message_pfx);
1848
- grpc_slice_buffer_add(&t->qbuf, grpc_slice_from_copied_string(msg));
2037
+ if (!s->sent_initial_metadata) {
2038
+ grpc_slice_buffer_add(&t->qbuf, http_status_hdr);
2039
+ grpc_slice_buffer_add(&t->qbuf, content_type_hdr);
1849
2040
  }
2041
+ grpc_slice_buffer_add(&t->qbuf, status_hdr);
2042
+ grpc_slice_buffer_add(&t->qbuf, message_pfx);
2043
+ grpc_slice_buffer_add(&t->qbuf, grpc_slice_ref_internal(slice));
1850
2044
  grpc_slice_buffer_add(
1851
2045
  &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR,
1852
2046
  &s->stats.outgoing));
@@ -1921,9 +2115,9 @@ static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx,
1921
2115
  if (parse_error == GRPC_ERROR_NONE &&
1922
2116
  (parse_error = grpc_http_parser_eof(&parser)) == GRPC_ERROR_NONE) {
1923
2117
  error = grpc_error_set_int(
1924
- grpc_error_set_int(
1925
- GRPC_ERROR_CREATE("Trying to connect an http1.x server"),
1926
- GRPC_ERROR_INT_HTTP_STATUS, response.status),
2118
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2119
+ "Trying to connect an http1.x server"),
2120
+ GRPC_ERROR_INT_HTTP_STATUS, response.status),
1927
2121
  GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
1928
2122
  }
1929
2123
  GRPC_ERROR_UNREF(parse_error);
@@ -1944,9 +2138,10 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp,
1944
2138
 
1945
2139
  grpc_error *err = error;
1946
2140
  if (err != GRPC_ERROR_NONE) {
1947
- err = grpc_error_set_int(
1948
- GRPC_ERROR_CREATE_REFERENCING("Endpoint read failed", &err, 1),
1949
- GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state);
2141
+ err = grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
2142
+ "Endpoint read failed", &err, 1),
2143
+ GRPC_ERROR_INT_OCCURRED_DURING_WRITE,
2144
+ t->write_state);
1950
2145
  }
1951
2146
  GPR_SWAP(grpc_error *, err, error);
1952
2147
  GRPC_ERROR_UNREF(err);
@@ -1967,8 +2162,8 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp,
1967
2162
  if (errors[1] != GRPC_ERROR_NONE) {
1968
2163
  errors[2] = try_http_parsing(exec_ctx, t);
1969
2164
  GRPC_ERROR_UNREF(error);
1970
- error = GRPC_ERROR_CREATE_REFERENCING("Failed parsing HTTP/2", errors,
1971
- GPR_ARRAY_SIZE(errors));
2165
+ error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
2166
+ "Failed parsing HTTP/2", errors, GPR_ARRAY_SIZE(errors));
1972
2167
  }
1973
2168
  for (i = 0; i < GPR_ARRAY_SIZE(errors); i++) {
1974
2169
  GRPC_ERROR_UNREF(errors[i]);
@@ -1993,7 +2188,7 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp,
1993
2188
  GPR_TIMER_BEGIN("post_reading_action_locked", 0);
1994
2189
  bool keep_reading = false;
1995
2190
  if (error == GRPC_ERROR_NONE && t->closed) {
1996
- error = GRPC_ERROR_CREATE("Transport closed");
2191
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed");
1997
2192
  }
1998
2193
  if (error != GRPC_ERROR_NONE) {
1999
2194
  close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error));
@@ -2057,6 +2252,10 @@ static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
2057
2252
  if (grpc_http_trace) {
2058
2253
  gpr_log(GPR_DEBUG, "%s: Start BDP ping", t->peer_string);
2059
2254
  }
2255
+ /* Reset the keepalive ping timer */
2256
+ if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
2257
+ grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
2258
+ }
2060
2259
  grpc_bdp_estimator_start_ping(&t->bdp_estimator);
2061
2260
  }
2062
2261
 
@@ -2071,12 +2270,51 @@ static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
2071
2270
  GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping");
2072
2271
  }
2073
2272
 
2273
+ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args,
2274
+ bool is_client) {
2275
+ size_t i;
2276
+ if (args) {
2277
+ for (i = 0; i < args->num_args; i++) {
2278
+ if (0 == strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_TIME_MS)) {
2279
+ const int value = grpc_channel_arg_get_integer(
2280
+ &args->args[i],
2281
+ (grpc_integer_options){g_default_client_keepalive_time_ms, 1,
2282
+ INT_MAX});
2283
+ if (is_client) {
2284
+ g_default_client_keepalive_time_ms = value;
2285
+ } else {
2286
+ g_default_server_keepalive_time_ms = value;
2287
+ }
2288
+ } else if (0 ==
2289
+ strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
2290
+ const int value = grpc_channel_arg_get_integer(
2291
+ &args->args[i],
2292
+ (grpc_integer_options){g_default_client_keepalive_timeout_ms, 0,
2293
+ INT_MAX});
2294
+ if (is_client) {
2295
+ g_default_client_keepalive_timeout_ms = value;
2296
+ } else {
2297
+ g_default_server_keepalive_timeout_ms = value;
2298
+ }
2299
+ } else if (0 == strcmp(args->args[i].key,
2300
+ GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
2301
+ g_default_keepalive_permit_without_calls =
2302
+ (uint32_t)grpc_channel_arg_get_integer(
2303
+ &args->args[i],
2304
+ (grpc_integer_options){g_default_keepalive_permit_without_calls,
2305
+ 0, 1});
2306
+ }
2307
+ }
2308
+ }
2309
+ }
2310
+
2074
2311
  static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
2075
2312
  grpc_error *error) {
2076
2313
  grpc_chttp2_transport *t = arg;
2077
2314
  GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING);
2078
2315
  if (error == GRPC_ERROR_NONE && !(t->destroying || t->closed)) {
2079
- if (t->keepalive_permit_without_calls || t->stream_map.count > 0) {
2316
+ if (t->keepalive_permit_without_calls ||
2317
+ grpc_chttp2_stream_map_size(&t->stream_map) > 0) {
2080
2318
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING;
2081
2319
  GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end");
2082
2320
  send_ping_locked(exec_ctx, t, GRPC_CHTTP2_PING_ON_NEXT_WRITE,
@@ -2089,6 +2327,13 @@ static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
2089
2327
  gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
2090
2328
  &t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
2091
2329
  }
2330
+ } else if (error == GRPC_ERROR_CANCELLED && !(t->destroying || t->closed)) {
2331
+ /* The keepalive ping timer may be cancelled by bdp */
2332
+ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
2333
+ grpc_timer_init(
2334
+ exec_ctx, &t->keepalive_ping_timer,
2335
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
2336
+ &t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
2092
2337
  }
2093
2338
  GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "init keepalive ping");
2094
2339
  }
@@ -2114,9 +2359,7 @@ static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
2114
2359
  grpc_timer_init(
2115
2360
  exec_ctx, &t->keepalive_ping_timer,
2116
2361
  gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
2117
- grpc_closure_create(init_keepalive_ping_locked, t,
2118
- grpc_combiner_scheduler(t->combiner, false)),
2119
- gpr_now(GPR_CLOCK_MONOTONIC));
2362
+ &t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
2120
2363
  }
2121
2364
  }
2122
2365
  GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive ping end");
@@ -2128,12 +2371,12 @@ static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg,
2128
2371
  if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
2129
2372
  if (error == GRPC_ERROR_NONE) {
2130
2373
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
2131
- close_transport_locked(exec_ctx, t,
2132
- GRPC_ERROR_CREATE("keepalive watchdog timeout"));
2374
+ close_transport_locked(exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2375
+ "keepalive watchdog timeout"));
2133
2376
  }
2134
2377
  } else {
2135
- /** The watchdog timer should have been cancelled by
2136
- finish_keepalive_ping_locked. */
2378
+ /* The watchdog timer should have been cancelled by
2379
+ * finish_keepalive_ping_locked. */
2137
2380
  if (error != GRPC_ERROR_CANCELLED) {
2138
2381
  gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)",
2139
2382
  t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING);
@@ -2328,7 +2571,8 @@ void grpc_chttp2_incoming_byte_stream_push(grpc_exec_ctx *exec_ctx,
2328
2571
  gpr_mu_lock(&bs->slice_mu);
2329
2572
  if (bs->remaining_bytes < GRPC_SLICE_LENGTH(slice)) {
2330
2573
  incoming_byte_stream_publish_error(
2331
- exec_ctx, bs, GRPC_ERROR_CREATE("Too many bytes in stream"));
2574
+ exec_ctx, bs,
2575
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many bytes in stream"));
2332
2576
  } else {
2333
2577
  bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice);
2334
2578
  if (bs->on_next != NULL) {
@@ -2348,7 +2592,7 @@ void grpc_chttp2_incoming_byte_stream_finished(
2348
2592
  if (error == GRPC_ERROR_NONE) {
2349
2593
  gpr_mu_lock(&bs->slice_mu);
2350
2594
  if (bs->remaining_bytes != 0) {
2351
- error = GRPC_ERROR_CREATE("Truncated message");
2595
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message");
2352
2596
  }
2353
2597
  gpr_mu_unlock(&bs->slice_mu);
2354
2598
  }
@@ -2428,9 +2672,9 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
2428
2672
  t->peer_string);
2429
2673
  }
2430
2674
  send_goaway(exec_ctx, t,
2431
- grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
2432
- GRPC_ERROR_INT_HTTP2_ERROR,
2433
- GRPC_HTTP2_ENHANCE_YOUR_CALM));
2675
+ grpc_error_set_int(
2676
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
2677
+ GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
2434
2678
  } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace) {
2435
2679
  gpr_log(GPR_DEBUG,
2436
2680
  "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
@@ -2457,9 +2701,10 @@ static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
2457
2701
  s->id);
2458
2702
  }
2459
2703
  grpc_chttp2_cancel_stream(
2460
- exec_ctx, t, s, grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"),
2461
- GRPC_ERROR_INT_HTTP2_ERROR,
2462
- GRPC_HTTP2_ENHANCE_YOUR_CALM));
2704
+ exec_ctx, t, s,
2705
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
2706
+ GRPC_ERROR_INT_HTTP2_ERROR,
2707
+ GRPC_HTTP2_ENHANCE_YOUR_CALM));
2463
2708
  if (n > 1) {
2464
2709
  /* Since we cancel one stream per destructive reclamation, if
2465
2710
  there are more streams left, we can immediately post a new