grpc 1.8.7 → 1.9.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (488) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +549 -325
  3. data/include/grpc/impl/codegen/grpc_types.h +1 -2
  4. data/include/grpc/impl/codegen/port_platform.h +46 -5
  5. data/include/grpc/impl/codegen/slice.h +1 -2
  6. data/include/grpc/module.modulemap +0 -2
  7. data/include/grpc/slice_buffer.h +1 -2
  8. data/include/grpc/support/log.h +4 -2
  9. data/include/grpc/support/thd.h +4 -1
  10. data/include/grpc/support/tls.h +6 -0
  11. data/include/grpc/support/tls_gcc.h +5 -40
  12. data/include/grpc/support/tls_msvc.h +9 -0
  13. data/include/grpc/support/tls_pthread.h +9 -0
  14. data/src/core/ext/filters/client_channel/backup_poller.cc +32 -29
  15. data/src/core/ext/filters/client_channel/backup_poller.h +2 -2
  16. data/src/core/ext/filters/client_channel/channel_connectivity.cc +26 -32
  17. data/src/core/ext/filters/client_channel/client_channel.cc +325 -356
  18. data/src/core/ext/filters/client_channel/client_channel.h +4 -12
  19. data/src/core/ext/filters/client_channel/client_channel_factory.cc +9 -14
  20. data/src/core/ext/filters/client_channel/client_channel_factory.h +7 -20
  21. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +7 -10
  22. data/src/core/ext/filters/client_channel/connector.cc +6 -7
  23. data/src/core/ext/filters/client_channel/connector.h +6 -16
  24. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +38 -50
  25. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +0 -8
  26. data/src/core/ext/filters/client_channel/http_proxy.cc +9 -13
  27. data/src/core/ext/filters/client_channel/http_proxy.h +0 -8
  28. data/src/core/ext/filters/client_channel/lb_policy.cc +72 -94
  29. data/src/core/ext/filters/client_channel/lb_policy.h +83 -92
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +14 -19
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +0 -8
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +474 -591
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -8
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +2 -10
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +6 -6
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +0 -8
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +0 -9
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +0 -9
  39. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +3 -4
  40. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +9 -12
  41. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +160 -182
  42. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +182 -221
  43. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +24 -35
  44. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -20
  45. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +6 -9
  46. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -15
  47. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +3 -3
  48. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -9
  49. data/src/core/ext/filters/client_channel/parse_address.cc +1 -1
  50. data/src/core/ext/filters/client_channel/parse_address.h +0 -8
  51. data/src/core/ext/filters/client_channel/proxy_mapper.cc +6 -8
  52. data/src/core/ext/filters/client_channel/proxy_mapper.h +6 -16
  53. data/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +13 -17
  54. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +2 -12
  55. data/src/core/ext/filters/client_channel/resolver.cc +11 -13
  56. data/src/core/ext/filters/client_channel/resolver.h +14 -25
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +57 -70
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +2 -12
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +23 -31
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +27 -45
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -15
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +9 -11
  63. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +53 -66
  64. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +25 -33
  65. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -9
  66. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +26 -35
  67. data/src/core/ext/filters/client_channel/resolver_factory.cc +2 -3
  68. data/src/core/ext/filters/client_channel/resolver_factory.h +2 -12
  69. data/src/core/ext/filters/client_channel/resolver_registry.cc +12 -15
  70. data/src/core/ext/filters/client_channel/resolver_registry.h +3 -12
  71. data/src/core/ext/filters/client_channel/retry_throttle.h +0 -8
  72. data/src/core/ext/filters/client_channel/subchannel.cc +289 -301
  73. data/src/core/ext/filters/client_channel/subchannel.h +57 -84
  74. data/src/core/ext/filters/client_channel/subchannel_index.cc +30 -33
  75. data/src/core/ext/filters/client_channel/subchannel_index.h +4 -16
  76. data/src/core/ext/filters/client_channel/uri_parser.cc +13 -17
  77. data/src/core/ext/filters/client_channel/uri_parser.h +1 -10
  78. data/src/core/ext/filters/deadline/deadline_filter.cc +49 -67
  79. data/src/core/ext/filters/deadline/deadline_filter.h +4 -14
  80. data/src/core/ext/filters/http/client/http_client_filter.cc +60 -77
  81. data/src/core/ext/filters/http/client/http_client_filter.h +0 -8
  82. data/src/core/ext/filters/http/http_filters_plugin.cc +4 -6
  83. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +63 -79
  84. data/src/core/ext/filters/http/message_compress/message_compress_filter.h +0 -8
  85. data/src/core/ext/filters/http/server/http_server_filter.cc +57 -71
  86. data/src/core/ext/filters/http/server/http_server_filter.h +0 -8
  87. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +19 -24
  88. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.h +0 -8
  89. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +3 -3
  90. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +0 -8
  91. data/src/core/ext/filters/max_age/max_age_filter.cc +49 -62
  92. data/src/core/ext/filters/max_age/max_age_filter.h +0 -8
  93. data/src/core/ext/filters/message_size/message_size_filter.cc +23 -29
  94. data/src/core/ext/filters/message_size/message_size_filter.h +0 -8
  95. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +15 -18
  96. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +0 -8
  97. data/src/core/ext/filters/workarounds/workaround_utils.h +0 -8
  98. data/src/core/ext/transport/chttp2/alpn/alpn.h +0 -8
  99. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +33 -40
  100. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +0 -8
  101. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +15 -17
  102. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +8 -8
  103. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +23 -28
  104. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -57
  105. data/src/core/ext/transport/chttp2/server/chttp2_server.h +1 -10
  106. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +3 -3
  107. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +7 -10
  108. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +5 -6
  109. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -9
  110. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +2 -11
  111. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -9
  112. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +10 -2
  113. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +516 -636
  114. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +4 -11
  115. data/src/core/ext/transport/chttp2/transport/flow_control.cc +29 -13
  116. data/src/core/ext/transport/chttp2/transport/flow_control.h +196 -53
  117. data/src/core/ext/transport/chttp2/transport/frame.h +0 -8
  118. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -33
  119. data/src/core/ext/transport/chttp2/transport/frame_data.h +3 -12
  120. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -3
  121. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +1 -10
  122. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -9
  124. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +2 -3
  125. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +1 -10
  126. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +8 -3
  127. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -10
  128. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +8 -8
  129. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +5 -11
  130. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +63 -81
  131. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -12
  132. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +230 -318
  133. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +6 -19
  134. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +14 -20
  135. data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -16
  136. data/src/core/ext/transport/chttp2/transport/http2_settings.h +0 -7
  137. data/src/core/ext/transport/chttp2/transport/huffsyms.h +0 -8
  138. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +8 -11
  139. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +4 -13
  140. data/src/core/ext/transport/chttp2/transport/internal.h +51 -75
  141. data/src/core/ext/transport/chttp2/transport/parsing.cc +83 -109
  142. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +2 -0
  143. data/src/core/ext/transport/chttp2/transport/stream_map.h +0 -8
  144. data/src/core/ext/transport/chttp2/transport/varint.h +0 -8
  145. data/src/core/ext/transport/chttp2/transport/writing.cc +61 -65
  146. data/src/core/ext/transport/inproc/inproc_plugin.cc +2 -4
  147. data/src/core/ext/transport/inproc/inproc_transport.cc +177 -188
  148. data/src/core/ext/transport/inproc/inproc_transport.h +0 -8
  149. data/src/core/lib/backoff/backoff.cc +39 -44
  150. data/src/core/lib/backoff/backoff.h +61 -57
  151. data/src/core/lib/channel/channel_args.cc +8 -10
  152. data/src/core/lib/channel/channel_args.h +4 -13
  153. data/src/core/lib/channel/channel_stack.cc +19 -27
  154. data/src/core/lib/channel/channel_stack.h +27 -47
  155. data/src/core/lib/channel/channel_stack_builder.cc +11 -14
  156. data/src/core/lib/channel/channel_stack_builder.h +4 -15
  157. data/src/core/lib/channel/connected_channel.cc +23 -36
  158. data/src/core/lib/channel/connected_channel.h +1 -10
  159. data/src/core/lib/channel/handshaker.cc +31 -40
  160. data/src/core/lib/channel/handshaker.h +14 -25
  161. data/src/core/lib/channel/handshaker_factory.cc +6 -6
  162. data/src/core/lib/channel/handshaker_factory.h +5 -15
  163. data/src/core/lib/channel/handshaker_registry.cc +9 -13
  164. data/src/core/lib/channel/handshaker_registry.h +2 -11
  165. data/src/core/lib/compression/algorithm_metadata.h +0 -8
  166. data/src/core/lib/compression/message_compress.cc +19 -23
  167. data/src/core/lib/compression/message_compress.h +2 -12
  168. data/src/core/lib/compression/stream_compression.cc +1 -1
  169. data/src/core/lib/compression/stream_compression.h +0 -8
  170. data/src/core/lib/compression/stream_compression_gzip.cc +12 -11
  171. data/src/core/lib/compression/stream_compression_gzip.h +0 -8
  172. data/src/core/lib/compression/stream_compression_identity.h +0 -8
  173. data/src/core/lib/debug/stats.cc +4 -4
  174. data/src/core/lib/debug/stats.h +9 -19
  175. data/src/core/lib/debug/stats_data.cc +85 -116
  176. data/src/core/lib/debug/stats_data.h +236 -312
  177. data/src/core/lib/debug/trace.cc +1 -1
  178. data/src/core/lib/debug/trace.h +0 -12
  179. data/src/core/lib/{support → gpr++}/abstract.h +8 -3
  180. data/src/core/lib/{support → gpr++}/atomic.h +5 -5
  181. data/src/core/lib/{support → gpr++}/atomic_with_atm.h +3 -3
  182. data/src/core/lib/{support → gpr++}/atomic_with_std.h +3 -3
  183. data/src/core/lib/gpr++/debug_location.h +52 -0
  184. data/src/core/lib/gpr++/inlined_vector.h +112 -0
  185. data/src/core/lib/{support → gpr++}/manual_constructor.h +2 -2
  186. data/src/core/lib/{support → gpr++}/memory.h +3 -3
  187. data/src/core/lib/gpr++/orphanable.h +171 -0
  188. data/src/core/lib/gpr++/ref_counted.h +133 -0
  189. data/src/core/lib/gpr++/ref_counted_ptr.h +99 -0
  190. data/src/core/lib/{support → gpr}/alloc.cc +0 -0
  191. data/src/core/lib/{support → gpr}/arena.cc +1 -1
  192. data/src/core/lib/{support → gpr}/arena.h +3 -11
  193. data/src/core/lib/{support → gpr}/atm.cc +0 -0
  194. data/src/core/lib/{support → gpr}/avl.cc +0 -0
  195. data/src/core/lib/{support → gpr}/cmdline.cc +1 -1
  196. data/src/core/lib/{support → gpr}/cpu_iphone.cc +0 -0
  197. data/src/core/lib/{support → gpr}/cpu_linux.cc +0 -0
  198. data/src/core/lib/{support → gpr}/cpu_posix.cc +0 -0
  199. data/src/core/lib/{support → gpr}/cpu_windows.cc +0 -0
  200. data/src/core/lib/{support → gpr}/env.h +3 -11
  201. data/src/core/lib/{support → gpr}/env_linux.cc +2 -2
  202. data/src/core/lib/{support → gpr}/env_posix.cc +4 -4
  203. data/src/core/lib/{support → gpr}/env_windows.cc +3 -3
  204. data/src/core/lib/{support → gpr}/fork.cc +3 -3
  205. data/src/core/lib/{support → gpr}/fork.h +3 -3
  206. data/src/core/lib/{support → gpr}/host_port.cc +1 -1
  207. data/src/core/lib/{support → gpr}/log.cc +3 -3
  208. data/src/core/lib/{support → gpr}/log_android.cc +3 -3
  209. data/src/core/lib/{support → gpr}/log_linux.cc +1 -1
  210. data/src/core/lib/{support → gpr}/log_posix.cc +5 -5
  211. data/src/core/lib/{support → gpr}/log_windows.cc +3 -3
  212. data/src/core/lib/{support → gpr}/mpscq.cc +1 -1
  213. data/src/core/lib/{support → gpr}/mpscq.h +3 -10
  214. data/src/core/lib/{support → gpr}/murmur_hash.cc +1 -1
  215. data/src/core/lib/{support → gpr}/murmur_hash.h +3 -11
  216. data/src/core/lib/{support → gpr}/spinlock.h +3 -3
  217. data/src/core/lib/{support → gpr}/string.cc +1 -1
  218. data/src/core/lib/{support → gpr}/string.h +3 -10
  219. data/src/core/lib/{support → gpr}/string_posix.cc +0 -0
  220. data/src/core/lib/{support → gpr}/string_util_windows.cc +2 -2
  221. data/src/core/lib/{support → gpr}/string_windows.cc +1 -1
  222. data/src/core/lib/{support → gpr}/string_windows.h +3 -11
  223. data/src/core/lib/{support → gpr}/subprocess_posix.cc +0 -0
  224. data/src/core/lib/{support → gpr}/subprocess_windows.cc +2 -2
  225. data/src/core/lib/{support → gpr}/sync.cc +0 -0
  226. data/src/core/lib/{support → gpr}/sync_posix.cc +10 -1
  227. data/src/core/lib/{support → gpr}/sync_windows.cc +0 -0
  228. data/src/core/lib/{support → gpr}/thd.cc +0 -0
  229. data/src/core/lib/{support → gpr}/thd_internal.h +3 -3
  230. data/src/core/lib/{support → gpr}/thd_posix.cc +18 -2
  231. data/src/core/lib/{support → gpr}/thd_windows.cc +2 -1
  232. data/src/core/lib/{support → gpr}/time.cc +0 -0
  233. data/src/core/lib/{support → gpr}/time_posix.cc +2 -4
  234. data/src/core/lib/{support → gpr}/time_precise.cc +1 -1
  235. data/src/core/lib/{support → gpr}/time_precise.h +3 -11
  236. data/src/core/lib/{support → gpr}/time_windows.cc +1 -3
  237. data/src/core/lib/{support → gpr}/tls_pthread.cc +0 -0
  238. data/src/core/lib/{support → gpr}/tmpfile.h +3 -11
  239. data/src/core/lib/{support → gpr}/tmpfile_msys.cc +2 -2
  240. data/src/core/lib/{support → gpr}/tmpfile_posix.cc +2 -2
  241. data/src/core/lib/{support → gpr}/tmpfile_windows.cc +2 -2
  242. data/src/core/lib/{support → gpr}/wrap_memcpy.cc +0 -0
  243. data/src/core/lib/http/format_request.cc +1 -1
  244. data/src/core/lib/http/format_request.h +0 -8
  245. data/src/core/lib/http/httpcli.cc +55 -74
  246. data/src/core/lib/http/httpcli.h +13 -22
  247. data/src/core/lib/http/httpcli_security_connector.cc +27 -33
  248. data/src/core/lib/http/parser.h +0 -8
  249. data/src/core/lib/iomgr/block_annotate.h +10 -17
  250. data/src/core/lib/iomgr/call_combiner.cc +14 -17
  251. data/src/core/lib/iomgr/call_combiner.h +16 -34
  252. data/src/core/lib/iomgr/closure.h +24 -37
  253. data/src/core/lib/iomgr/combiner.cc +62 -66
  254. data/src/core/lib/iomgr/combiner.h +6 -16
  255. data/src/core/lib/iomgr/endpoint.cc +15 -21
  256. data/src/core/lib/iomgr/endpoint.h +16 -33
  257. data/src/core/lib/iomgr/endpoint_pair.h +0 -8
  258. data/src/core/lib/iomgr/endpoint_pair_posix.cc +4 -5
  259. data/src/core/lib/iomgr/endpoint_pair_windows.cc +4 -6
  260. data/src/core/lib/iomgr/error.cc +2 -6
  261. data/src/core/lib/iomgr/error.h +4 -9
  262. data/src/core/lib/iomgr/error_internal.h +0 -8
  263. data/src/core/lib/iomgr/ev_epoll1_linux.cc +110 -117
  264. data/src/core/lib/iomgr/ev_epoll1_linux.h +0 -8
  265. data/src/core/lib/iomgr/ev_epollex_linux.cc +111 -141
  266. data/src/core/lib/iomgr/ev_epollex_linux.h +0 -8
  267. data/src/core/lib/iomgr/ev_epollsig_linux.cc +83 -109
  268. data/src/core/lib/iomgr/ev_epollsig_linux.h +2 -10
  269. data/src/core/lib/iomgr/ev_poll_posix.cc +103 -125
  270. data/src/core/lib/iomgr/ev_poll_posix.h +0 -8
  271. data/src/core/lib/iomgr/ev_posix.cc +35 -50
  272. data/src/core/lib/iomgr/ev_posix.h +27 -53
  273. data/src/core/lib/iomgr/exec_ctx.cc +46 -78
  274. data/src/core/lib/iomgr/exec_ctx.h +127 -60
  275. data/src/core/lib/iomgr/executor.cc +34 -38
  276. data/src/core/lib/iomgr/executor.h +3 -11
  277. data/src/core/lib/iomgr/fork_posix.cc +13 -12
  278. data/src/core/lib/iomgr/gethostname.h +0 -8
  279. data/src/core/lib/iomgr/gethostname_sysconf.cc +1 -1
  280. data/src/core/lib/iomgr/iocp_windows.cc +14 -16
  281. data/src/core/lib/iomgr/iocp_windows.h +1 -10
  282. data/src/core/lib/iomgr/iomgr.cc +60 -59
  283. data/src/core/lib/iomgr/iomgr.h +3 -12
  284. data/src/core/lib/iomgr/iomgr_internal.h +0 -8
  285. data/src/core/lib/iomgr/iomgr_uv.cc +2 -3
  286. data/src/core/lib/iomgr/iomgr_uv.h +0 -8
  287. data/src/core/lib/iomgr/is_epollexclusive_available.cc +1 -1
  288. data/src/core/lib/iomgr/load_file.cc +1 -1
  289. data/src/core/lib/iomgr/load_file.h +0 -8
  290. data/src/core/lib/iomgr/lockfree_event.cc +7 -8
  291. data/src/core/lib/iomgr/lockfree_event.h +3 -3
  292. data/src/core/lib/iomgr/polling_entity.cc +6 -10
  293. data/src/core/lib/iomgr/polling_entity.h +2 -11
  294. data/src/core/lib/iomgr/pollset.h +4 -13
  295. data/src/core/lib/iomgr/pollset_set.h +5 -18
  296. data/src/core/lib/iomgr/pollset_set_uv.cc +5 -10
  297. data/src/core/lib/iomgr/pollset_set_windows.cc +5 -10
  298. data/src/core/lib/iomgr/pollset_uv.cc +8 -9
  299. data/src/core/lib/iomgr/pollset_uv.h +0 -8
  300. data/src/core/lib/iomgr/pollset_windows.cc +14 -15
  301. data/src/core/lib/iomgr/pollset_windows.h +0 -8
  302. data/src/core/lib/iomgr/port.h +6 -1
  303. data/src/core/lib/iomgr/resolve_address.h +1 -10
  304. data/src/core/lib/iomgr/resolve_address_posix.cc +10 -12
  305. data/src/core/lib/iomgr/resolve_address_uv.cc +7 -8
  306. data/src/core/lib/iomgr/resolve_address_windows.cc +8 -9
  307. data/src/core/lib/iomgr/resource_quota.cc +77 -107
  308. data/src/core/lib/iomgr/resource_quota.h +8 -25
  309. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -1
  310. data/src/core/lib/iomgr/sockaddr_utils.h +0 -8
  311. data/src/core/lib/iomgr/socket_factory_posix.cc +1 -1
  312. data/src/core/lib/iomgr/socket_factory_posix.h +0 -8
  313. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  314. data/src/core/lib/iomgr/socket_mutator.h +1 -9
  315. data/src/core/lib/iomgr/socket_utils.h +0 -8
  316. data/src/core/lib/iomgr/socket_utils_common_posix.cc +1 -1
  317. data/src/core/lib/iomgr/socket_utils_posix.h +0 -8
  318. data/src/core/lib/iomgr/socket_windows.cc +8 -11
  319. data/src/core/lib/iomgr/socket_windows.h +3 -14
  320. data/src/core/lib/iomgr/tcp_client.h +1 -10
  321. data/src/core/lib/iomgr/tcp_client_posix.cc +94 -78
  322. data/src/core/lib/iomgr/tcp_client_posix.h +36 -8
  323. data/src/core/lib/iomgr/tcp_client_uv.cc +16 -23
  324. data/src/core/lib/iomgr/tcp_client_windows.cc +22 -25
  325. data/src/core/lib/iomgr/tcp_posix.cc +131 -153
  326. data/src/core/lib/iomgr/tcp_posix.h +3 -12
  327. data/src/core/lib/iomgr/tcp_server.h +6 -17
  328. data/src/core/lib/iomgr/tcp_server_posix.cc +31 -35
  329. data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -8
  330. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -1
  331. data/src/core/lib/iomgr/tcp_server_uv.cc +23 -34
  332. data/src/core/lib/iomgr/tcp_server_windows.cc +24 -34
  333. data/src/core/lib/iomgr/tcp_uv.cc +42 -56
  334. data/src/core/lib/iomgr/tcp_uv.h +0 -8
  335. data/src/core/lib/iomgr/tcp_windows.cc +43 -50
  336. data/src/core/lib/iomgr/tcp_windows.h +1 -9
  337. data/src/core/lib/iomgr/time_averaged_stats.h +0 -8
  338. data/src/core/lib/iomgr/timer.h +6 -15
  339. data/src/core/lib/iomgr/timer_generic.cc +22 -27
  340. data/src/core/lib/iomgr/timer_heap.h +0 -8
  341. data/src/core/lib/iomgr/timer_manager.cc +17 -19
  342. data/src/core/lib/iomgr/timer_manager.h +0 -8
  343. data/src/core/lib/iomgr/timer_uv.cc +12 -14
  344. data/src/core/lib/iomgr/udp_server.cc +148 -54
  345. data/src/core/lib/iomgr/udp_server.h +16 -21
  346. data/src/core/lib/iomgr/unix_sockets_posix.h +0 -8
  347. data/src/core/lib/iomgr/wakeup_fd_cv.cc +4 -4
  348. data/src/core/lib/iomgr/wakeup_fd_cv.h +12 -20
  349. data/src/core/lib/iomgr/wakeup_fd_nospecial.cc +1 -1
  350. data/src/core/lib/iomgr/wakeup_fd_pipe.h +0 -8
  351. data/src/core/lib/iomgr/wakeup_fd_posix.h +0 -8
  352. data/src/core/lib/json/json.h +0 -8
  353. data/src/core/lib/json/json_reader.h +0 -8
  354. data/src/core/lib/json/json_writer.h +0 -8
  355. data/src/core/lib/profiling/basic_timers.cc +3 -2
  356. data/src/core/lib/profiling/timers.h +0 -8
  357. data/src/core/lib/security/context/security_context.cc +9 -10
  358. data/src/core/lib/security/context/security_context.h +0 -8
  359. data/src/core/lib/security/credentials/composite/composite_credentials.cc +23 -28
  360. data/src/core/lib/security/credentials/composite/composite_credentials.h +0 -8
  361. data/src/core/lib/security/credentials/credentials.cc +33 -42
  362. data/src/core/lib/security/credentials/credentials.h +24 -43
  363. data/src/core/lib/security/credentials/credentials_metadata.cc +2 -2
  364. data/src/core/lib/security/credentials/fake/fake_credentials.cc +16 -22
  365. data/src/core/lib/security/credentials/fake/fake_credentials.h +0 -8
  366. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +3 -3
  367. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +28 -34
  368. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +0 -8
  369. data/src/core/lib/security/credentials/iam/iam_credentials.cc +9 -13
  370. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  371. data/src/core/lib/security/credentials/jwt/json_token.h +0 -8
  372. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +14 -20
  373. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +1 -10
  374. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +56 -72
  375. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +5 -17
  376. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +47 -55
  377. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +3 -12
  378. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +23 -28
  379. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +8 -13
  380. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +0 -8
  381. data/src/core/lib/security/transport/auth_filters.h +0 -8
  382. data/src/core/lib/security/transport/client_auth_filter.cc +45 -54
  383. data/src/core/lib/security/transport/lb_targets_info.cc +2 -2
  384. data/src/core/lib/security/transport/lb_targets_info.h +0 -8
  385. data/src/core/lib/security/transport/secure_endpoint.cc +54 -68
  386. data/src/core/lib/security/transport/secure_endpoint.h +0 -8
  387. data/src/core/lib/security/transport/security_connector.cc +62 -86
  388. data/src/core/lib/security/transport/security_connector.h +22 -39
  389. data/src/core/lib/security/transport/security_handshaker.cc +83 -106
  390. data/src/core/lib/security/transport/security_handshaker.h +1 -10
  391. data/src/core/lib/security/transport/server_auth_filter.cc +31 -38
  392. data/src/core/lib/security/transport/tsi_error.h +0 -8
  393. data/src/core/lib/security/util/json_util.h +0 -8
  394. data/src/core/lib/slice/b64.cc +5 -6
  395. data/src/core/lib/slice/b64.h +3 -12
  396. data/src/core/lib/slice/percent_encoding.h +0 -8
  397. data/src/core/lib/slice/slice.cc +8 -9
  398. data/src/core/lib/slice/slice_buffer.cc +11 -16
  399. data/src/core/lib/slice/slice_hash_table.cc +5 -7
  400. data/src/core/lib/slice/slice_hash_table.h +2 -12
  401. data/src/core/lib/slice/slice_intern.cc +4 -5
  402. data/src/core/lib/slice/slice_internal.h +4 -15
  403. data/src/core/lib/slice/slice_string_helpers.cc +1 -1
  404. data/src/core/lib/slice/slice_string_helpers.h +1 -9
  405. data/src/core/lib/surface/alarm.cc +11 -14
  406. data/src/core/lib/surface/alarm_internal.h +0 -8
  407. data/src/core/lib/surface/byte_buffer.cc +2 -3
  408. data/src/core/lib/surface/byte_buffer_reader.cc +7 -9
  409. data/src/core/lib/surface/call.cc +198 -241
  410. data/src/core/lib/surface/call.h +9 -23
  411. data/src/core/lib/surface/call_details.cc +3 -4
  412. data/src/core/lib/surface/call_log_batch.cc +1 -1
  413. data/src/core/lib/surface/call_test_only.h +0 -8
  414. data/src/core/lib/surface/channel.cc +53 -64
  415. data/src/core/lib/surface/channel.h +12 -23
  416. data/src/core/lib/surface/channel_init.cc +2 -3
  417. data/src/core/lib/surface/channel_init.h +2 -12
  418. data/src/core/lib/surface/channel_ping.cc +7 -9
  419. data/src/core/lib/surface/channel_stack_type.h +0 -8
  420. data/src/core/lib/surface/completion_queue.cc +158 -176
  421. data/src/core/lib/surface/completion_queue.h +9 -20
  422. data/src/core/lib/surface/completion_queue_factory.h +0 -8
  423. data/src/core/lib/surface/event_string.cc +1 -1
  424. data/src/core/lib/surface/event_string.h +0 -8
  425. data/src/core/lib/surface/init.cc +27 -25
  426. data/src/core/lib/surface/init.h +0 -8
  427. data/src/core/lib/surface/init_secure.cc +2 -2
  428. data/src/core/lib/surface/lame_client.cc +30 -33
  429. data/src/core/lib/surface/lame_client.h +0 -8
  430. data/src/core/lib/surface/server.cc +151 -203
  431. data/src/core/lib/surface/server.h +7 -16
  432. data/src/core/lib/surface/validate_metadata.h +0 -8
  433. data/src/core/lib/surface/version.cc +2 -2
  434. data/src/core/lib/transport/bdp_estimator.cc +2 -2
  435. data/src/core/lib/transport/bdp_estimator.h +1 -1
  436. data/src/core/lib/transport/byte_stream.cc +24 -38
  437. data/src/core/lib/transport/byte_stream.h +10 -25
  438. data/src/core/lib/transport/connectivity_state.cc +9 -13
  439. data/src/core/lib/transport/connectivity_state.h +4 -14
  440. data/src/core/lib/transport/error_utils.cc +6 -6
  441. data/src/core/lib/transport/error_utils.h +2 -11
  442. data/src/core/lib/transport/metadata.cc +21 -23
  443. data/src/core/lib/transport/metadata.h +8 -20
  444. data/src/core/lib/transport/metadata_batch.cc +34 -45
  445. data/src/core/lib/transport/metadata_batch.h +18 -32
  446. data/src/core/lib/transport/service_config.cc +11 -15
  447. data/src/core/lib/transport/service_config.h +3 -13
  448. data/src/core/lib/transport/static_metadata.cc +1 -1
  449. data/src/core/lib/transport/static_metadata.h +1 -7
  450. data/src/core/lib/transport/status_conversion.cc +2 -3
  451. data/src/core/lib/transport/status_conversion.h +1 -10
  452. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  453. data/src/core/lib/transport/timeout_encoding.h +1 -9
  454. data/src/core/lib/transport/transport.cc +36 -50
  455. data/src/core/lib/transport/transport.h +28 -30
  456. data/src/core/lib/transport/transport_impl.h +12 -23
  457. data/src/core/lib/transport/transport_op_string.cc +2 -2
  458. data/src/core/plugin_registry/grpc_plugin_registry.cc +34 -34
  459. data/src/core/tsi/fake_transport_security.cc +7 -10
  460. data/src/core/tsi/fake_transport_security.h +0 -8
  461. data/src/core/tsi/gts_transport_security.cc +2 -2
  462. data/src/core/tsi/gts_transport_security.h +0 -8
  463. data/src/core/tsi/ssl_transport_security.cc +3 -0
  464. data/src/core/tsi/ssl_transport_security.h +0 -8
  465. data/src/core/tsi/ssl_types.h +0 -8
  466. data/src/core/tsi/transport_security.h +1 -9
  467. data/src/core/tsi/transport_security_adapter.h +0 -8
  468. data/src/core/tsi/transport_security_grpc.cc +11 -18
  469. data/src/core/tsi/transport_security_grpc.h +9 -21
  470. data/src/core/tsi/transport_security_interface.h +0 -8
  471. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +0 -30
  472. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +2 -48
  473. data/src/ruby/lib/grpc/version.rb +1 -1
  474. data/src/ruby/spec/channel_connection_spec.rb +2 -1
  475. data/src/ruby/spec/client_auth_spec.rb +1 -1
  476. data/src/ruby/spec/client_server_spec.rb +2 -2
  477. data/src/ruby/spec/generic/active_call_spec.rb +1 -1
  478. data/src/ruby/spec/generic/client_stub_spec.rb +4 -4
  479. data/src/ruby/spec/generic/interceptor_registry_spec.rb +1 -1
  480. data/src/ruby/spec/generic/rpc_server_spec.rb +12 -12
  481. data/src/ruby/spec/google_rpc_status_utils_spec.rb +3 -2
  482. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  483. data/src/ruby/spec/server_spec.rb +9 -9
  484. data/src/ruby/spec/support/helpers.rb +35 -1
  485. metadata +68 -66
  486. data/include/grpc/impl/codegen/exec_ctx_fwd.h +0 -26
  487. data/include/grpc/support/histogram.h +0 -64
  488. data/src/core/lib/support/histogram.cc +0 -227
@@ -28,10 +28,9 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* factory) {
28
28
 
29
29
  /** Create a resolver instance for a name */
30
30
  grpc_resolver* grpc_resolver_factory_create_resolver(
31
- grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory,
32
- grpc_resolver_args* args) {
31
+ grpc_resolver_factory* factory, grpc_resolver_args* args) {
33
32
  if (factory == nullptr) return nullptr;
34
- return factory->vtable->create_resolver(exec_ctx, factory, args);
33
+ return factory->vtable->create_resolver(factory, args);
35
34
  }
36
35
 
37
36
  char* grpc_resolver_factory_get_default_authority(
@@ -24,10 +24,6 @@
24
24
  #include "src/core/ext/filters/client_channel/uri_parser.h"
25
25
  #include "src/core/lib/iomgr/pollset_set.h"
26
26
 
27
- #ifdef __cplusplus
28
- extern "C" {
29
- #endif
30
-
31
27
  typedef struct grpc_resolver_factory grpc_resolver_factory;
32
28
  typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable;
33
29
 
@@ -47,8 +43,7 @@ struct grpc_resolver_factory_vtable {
47
43
  void (*unref)(grpc_resolver_factory* factory);
48
44
 
49
45
  /** Implementation of grpc_resolver_factory_create_resolver */
50
- grpc_resolver* (*create_resolver)(grpc_exec_ctx* exec_ctx,
51
- grpc_resolver_factory* factory,
46
+ grpc_resolver* (*create_resolver)(grpc_resolver_factory* factory,
52
47
  grpc_resolver_args* args);
53
48
 
54
49
  /** Implementation of grpc_resolver_factory_get_default_authority */
@@ -63,16 +58,11 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* resolver);
63
58
 
64
59
  /** Create a resolver instance for a name */
65
60
  grpc_resolver* grpc_resolver_factory_create_resolver(
66
- grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory,
67
- grpc_resolver_args* args);
61
+ grpc_resolver_factory* factory, grpc_resolver_args* args);
68
62
 
69
63
  /** Return a (freshly allocated with gpr_malloc) string representing
70
64
  the default authority to use for this scheme. */
71
65
  char* grpc_resolver_factory_get_default_authority(
72
66
  grpc_resolver_factory* factory, grpc_uri* uri);
73
67
 
74
- #ifdef __cplusplus
75
- }
76
- #endif
77
-
78
68
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FACTORY_H */
@@ -92,23 +92,22 @@ static grpc_resolver_factory* lookup_factory_by_uri(grpc_uri* uri) {
92
92
  return lookup_factory(uri->scheme);
93
93
  }
94
94
 
95
- static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx,
96
- const char* target,
95
+ static grpc_resolver_factory* resolve_factory(const char* target,
97
96
  grpc_uri** uri,
98
97
  char** canonical_target) {
99
98
  grpc_resolver_factory* factory = nullptr;
100
99
 
101
100
  GPR_ASSERT(uri != nullptr);
102
- *uri = grpc_uri_parse(exec_ctx, target, 1);
101
+ *uri = grpc_uri_parse(target, 1);
103
102
  factory = lookup_factory_by_uri(*uri);
104
103
  if (factory == nullptr) {
105
104
  grpc_uri_destroy(*uri);
106
105
  gpr_asprintf(canonical_target, "%s%s", g_default_resolver_prefix, target);
107
- *uri = grpc_uri_parse(exec_ctx, *canonical_target, 1);
106
+ *uri = grpc_uri_parse(*canonical_target, 1);
108
107
  factory = lookup_factory_by_uri(*uri);
109
108
  if (factory == nullptr) {
110
- grpc_uri_destroy(grpc_uri_parse(exec_ctx, target, 0));
111
- grpc_uri_destroy(grpc_uri_parse(exec_ctx, *canonical_target, 0));
109
+ grpc_uri_destroy(grpc_uri_parse(target, 0));
110
+ grpc_uri_destroy(grpc_uri_parse(*canonical_target, 0));
112
111
  gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target,
113
112
  *canonical_target);
114
113
  }
@@ -116,14 +115,14 @@ static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx,
116
115
  return factory;
117
116
  }
118
117
 
119
- grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target,
118
+ grpc_resolver* grpc_resolver_create(const char* target,
120
119
  const grpc_channel_args* args,
121
120
  grpc_pollset_set* pollset_set,
122
121
  grpc_combiner* combiner) {
123
122
  grpc_uri* uri = nullptr;
124
123
  char* canonical_target = nullptr;
125
124
  grpc_resolver_factory* factory =
126
- resolve_factory(exec_ctx, target, &uri, &canonical_target);
125
+ resolve_factory(target, &uri, &canonical_target);
127
126
  grpc_resolver* resolver;
128
127
  grpc_resolver_args resolver_args;
129
128
  memset(&resolver_args, 0, sizeof(resolver_args));
@@ -131,29 +130,27 @@ grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target,
131
130
  resolver_args.args = args;
132
131
  resolver_args.pollset_set = pollset_set;
133
132
  resolver_args.combiner = combiner;
134
- resolver =
135
- grpc_resolver_factory_create_resolver(exec_ctx, factory, &resolver_args);
133
+ resolver = grpc_resolver_factory_create_resolver(factory, &resolver_args);
136
134
  grpc_uri_destroy(uri);
137
135
  gpr_free(canonical_target);
138
136
  return resolver;
139
137
  }
140
138
 
141
- char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) {
139
+ char* grpc_get_default_authority(const char* target) {
142
140
  grpc_uri* uri = nullptr;
143
141
  char* canonical_target = nullptr;
144
142
  grpc_resolver_factory* factory =
145
- resolve_factory(exec_ctx, target, &uri, &canonical_target);
143
+ resolve_factory(target, &uri, &canonical_target);
146
144
  char* authority = grpc_resolver_factory_get_default_authority(factory, uri);
147
145
  grpc_uri_destroy(uri);
148
146
  gpr_free(canonical_target);
149
147
  return authority;
150
148
  }
151
149
 
152
- char* grpc_resolver_factory_add_default_prefix_if_needed(
153
- grpc_exec_ctx* exec_ctx, const char* target) {
150
+ char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target) {
154
151
  grpc_uri* uri = nullptr;
155
152
  char* canonical_target = nullptr;
156
- resolve_factory(exec_ctx, target, &uri, &canonical_target);
153
+ resolve_factory(target, &uri, &canonical_target);
157
154
  grpc_uri_destroy(uri);
158
155
  return canonical_target == nullptr ? gpr_strdup(target) : canonical_target;
159
156
  }
@@ -22,10 +22,6 @@
22
22
  #include "src/core/ext/filters/client_channel/resolver_factory.h"
23
23
  #include "src/core/lib/iomgr/pollset_set.h"
24
24
 
25
- #ifdef __cplusplus
26
- extern "C" {
27
- #endif
28
-
29
25
  void grpc_resolver_registry_init();
30
26
  void grpc_resolver_registry_shutdown(void);
31
27
 
@@ -52,7 +48,7 @@ void grpc_register_resolver_type(grpc_resolver_factory* factory);
52
48
  (typically the set of arguments passed in from the client API).
53
49
  \a pollset_set is used to drive IO in the name resolution process, it
54
50
  should not be NULL. */
55
- grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target,
51
+ grpc_resolver* grpc_resolver_create(const char* target,
56
52
  const grpc_channel_args* args,
57
53
  grpc_pollset_set* pollset_set,
58
54
  grpc_combiner* combiner);
@@ -63,15 +59,10 @@ grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name);
63
59
 
64
60
  /** Given a target, return a (freshly allocated with gpr_malloc) string
65
61
  representing the default authority to pass from a client. */
66
- char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target);
62
+ char* grpc_get_default_authority(const char* target);
67
63
 
68
64
  /** Returns a newly allocated string containing \a target, adding the
69
65
  default prefix if needed. */
70
- char* grpc_resolver_factory_add_default_prefix_if_needed(
71
- grpc_exec_ctx* exec_ctx, const char* target);
72
-
73
- #ifdef __cplusplus
74
- }
75
- #endif
66
+ char* grpc_resolver_factory_add_default_prefix_if_needed(const char* target);
76
67
 
77
68
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H */
@@ -21,10 +21,6 @@
21
21
 
22
22
  #include <stdbool.h>
23
23
 
24
- #ifdef __cplusplus
25
- extern "C" {
26
- #endif
27
-
28
24
  /// Tracks retry throttling data for an individual server name.
29
25
  typedef struct grpc_server_retry_throttle_data grpc_server_retry_throttle_data;
30
26
 
@@ -51,8 +47,4 @@ void grpc_retry_throttle_map_shutdown();
51
47
  grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server(
52
48
  const char* server_name, int max_milli_tokens, int milli_token_ratio);
53
49
 
54
- #ifdef __cplusplus
55
- }
56
- #endif
57
-
58
50
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RETRY_THROTTLE_H */
@@ -20,7 +20,9 @@
20
20
 
21
21
  #include <inttypes.h>
22
22
  #include <limits.h>
23
- #include <string.h>
23
+
24
+ #include <algorithm>
25
+ #include <cstring>
24
26
 
25
27
  #include <grpc/support/alloc.h>
26
28
  #include <grpc/support/avl.h>
@@ -35,6 +37,8 @@
35
37
  #include "src/core/lib/channel/channel_args.h"
36
38
  #include "src/core/lib/channel/connected_channel.h"
37
39
  #include "src/core/lib/debug/stats.h"
40
+ #include "src/core/lib/gpr++/debug_location.h"
41
+ #include "src/core/lib/gpr++/manual_constructor.h"
38
42
  #include "src/core/lib/iomgr/sockaddr_utils.h"
39
43
  #include "src/core/lib/iomgr/timer.h"
40
44
  #include "src/core/lib/profiling/timers.h"
@@ -48,19 +52,17 @@
48
52
 
49
53
  #define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1
50
54
  #define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6
51
- #define GRPC_SUBCHANNEL_RECONNECT_MIN_BACKOFF_SECONDS 20
55
+ #define GRPC_SUBCHANNEL_RECONNECT_MIN_TIMEOUT_SECONDS 20
52
56
  #define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120
53
57
  #define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2
54
58
 
55
- #define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \
56
- ((grpc_connected_subchannel*)(gpr_atm_##barrier##_load( \
57
- &(subchannel)->connected_subchannel)))
58
-
59
- typedef struct {
59
+ namespace {
60
+ struct state_watcher {
60
61
  grpc_closure closure;
61
62
  grpc_subchannel* subchannel;
62
63
  grpc_connectivity_state connectivity_state;
63
- } state_watcher;
64
+ };
65
+ } // namespace
64
66
 
65
67
  typedef struct external_state_watcher {
66
68
  grpc_subchannel* subchannel;
@@ -93,7 +95,7 @@ struct grpc_subchannel {
93
95
  grpc_connect_out_args connecting_result;
94
96
 
95
97
  /** callback for connection finishing */
96
- grpc_closure connected;
98
+ grpc_closure on_connected;
97
99
 
98
100
  /** callback for our alarm */
99
101
  grpc_closure on_alarm;
@@ -102,12 +104,13 @@ struct grpc_subchannel {
102
104
  being setup */
103
105
  grpc_pollset_set* pollset_set;
104
106
 
105
- /** active connection, or null; of type grpc_connected_subchannel */
106
- gpr_atm connected_subchannel;
107
-
108
107
  /** mutex protecting remaining elements */
109
108
  gpr_mu mu;
110
109
 
110
+ /** active connection, or null; of type grpc_core::ConnectedSubchannel
111
+ */
112
+ grpc_core::RefCountedPtr<grpc_core::ConnectedSubchannel> connected_subchannel;
113
+
111
114
  /** have we seen a disconnection? */
112
115
  bool disconnected;
113
116
  /** are we connecting */
@@ -118,8 +121,9 @@ struct grpc_subchannel {
118
121
  external_state_watcher root_external_state_watcher;
119
122
 
120
123
  /** backoff state */
121
- grpc_backoff backoff_state;
122
- grpc_backoff_result backoff_result;
124
+ grpc_core::ManualConstructor<grpc_core::BackOff> backoff;
125
+ grpc_millis next_attempt_deadline;
126
+ grpc_millis min_connect_timeout_ms;
123
127
 
124
128
  /** do we have an active alarm? */
125
129
  bool have_alarm;
@@ -130,17 +134,15 @@ struct grpc_subchannel {
130
134
  };
131
135
 
132
136
  struct grpc_subchannel_call {
133
- grpc_connected_subchannel* connection;
137
+ grpc_core::ConnectedSubchannel* connection;
134
138
  grpc_closure* schedule_closure_after_destroy;
135
139
  };
136
140
 
137
141
  #define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack*)((call) + 1))
138
- #define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack*)(con))
139
142
  #define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \
140
143
  (((grpc_subchannel_call*)(callstack)) - 1)
141
144
 
142
- static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel,
143
- grpc_error* error);
145
+ static void on_subchannel_connected(void* subchannel, grpc_error* error);
144
146
 
145
147
  #ifndef NDEBUG
146
148
  #define REF_REASON reason
@@ -157,39 +159,24 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel,
157
159
  * connection implementation
158
160
  */
159
161
 
160
- static void connection_destroy(grpc_exec_ctx* exec_ctx, void* arg,
161
- grpc_error* error) {
162
- grpc_connected_subchannel* c = (grpc_connected_subchannel*)arg;
163
- grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c));
164
- gpr_free(c);
165
- }
166
-
167
- grpc_connected_subchannel* grpc_connected_subchannel_ref(
168
- grpc_connected_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
169
- GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON);
170
- return c;
171
- }
172
-
173
- void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx,
174
- grpc_connected_subchannel* c
175
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
176
- GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c),
177
- REF_REASON);
162
+ static void connection_destroy(void* arg, grpc_error* error) {
163
+ grpc_channel_stack* stk = (grpc_channel_stack*)arg;
164
+ grpc_channel_stack_destroy(stk);
165
+ gpr_free(stk);
178
166
  }
179
167
 
180
168
  /*
181
169
  * grpc_subchannel implementation
182
170
  */
183
171
 
184
- static void subchannel_destroy(grpc_exec_ctx* exec_ctx, void* arg,
185
- grpc_error* error) {
172
+ static void subchannel_destroy(void* arg, grpc_error* error) {
186
173
  grpc_subchannel* c = (grpc_subchannel*)arg;
187
174
  gpr_free((void*)c->filters);
188
- grpc_channel_args_destroy(exec_ctx, c->args);
189
- grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker);
190
- grpc_connector_unref(exec_ctx, c->connector);
191
- grpc_pollset_set_destroy(exec_ctx, c->pollset_set);
192
- grpc_subchannel_key_destroy(exec_ctx, c->key);
175
+ grpc_channel_args_destroy(c->args);
176
+ grpc_connectivity_state_destroy(&c->state_tracker);
177
+ grpc_connector_unref(c->connector);
178
+ grpc_pollset_set_destroy(c->pollset_set);
179
+ grpc_subchannel_key_destroy(c->key);
193
180
  gpr_mu_destroy(&c->mu);
194
181
  gpr_free(c);
195
182
  }
@@ -241,59 +228,97 @@ grpc_subchannel* grpc_subchannel_ref_from_weak_ref(
241
228
  }
242
229
  }
243
230
 
244
- static void disconnect(grpc_exec_ctx* exec_ctx, grpc_subchannel* c) {
245
- grpc_connected_subchannel* con;
246
- grpc_subchannel_index_unregister(exec_ctx, c->key, c);
231
+ static void disconnect(grpc_subchannel* c) {
232
+ grpc_subchannel_index_unregister(c->key, c);
247
233
  gpr_mu_lock(&c->mu);
248
234
  GPR_ASSERT(!c->disconnected);
249
235
  c->disconnected = true;
250
- grpc_connector_shutdown(
251
- exec_ctx, c->connector,
252
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected"));
253
- con = GET_CONNECTED_SUBCHANNEL(c, no_barrier);
254
- if (con != nullptr) {
255
- GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection");
256
- gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef);
257
- }
236
+ grpc_connector_shutdown(c->connector, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
237
+ "Subchannel disconnected"));
238
+ c->connected_subchannel.reset();
258
239
  gpr_mu_unlock(&c->mu);
259
240
  }
260
241
 
261
- void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx,
262
- grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
242
+ void grpc_subchannel_unref(grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
263
243
  gpr_atm old_refs;
264
244
  // add a weak ref and subtract a strong ref (atomically)
265
245
  old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS),
266
246
  1 REF_MUTATE_PURPOSE("STRONG_UNREF"));
267
247
  if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) {
268
- disconnect(exec_ctx, c);
248
+ disconnect(c);
269
249
  }
270
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref");
250
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "strong-unref");
271
251
  }
272
252
 
273
- void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx,
274
- grpc_subchannel* c
275
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
253
+ void grpc_subchannel_weak_unref(
254
+ grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
276
255
  gpr_atm old_refs;
277
256
  old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF"));
278
257
  if (old_refs == 1) {
279
258
  GRPC_CLOSURE_SCHED(
280
- exec_ctx,
281
259
  GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx),
282
260
  GRPC_ERROR_NONE);
283
261
  }
284
262
  }
285
263
 
286
- grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx,
287
- grpc_connector* connector,
264
+ static void parse_args_for_backoff_values(
265
+ const grpc_channel_args* args, grpc_core::BackOff::Options* backoff_options,
266
+ grpc_millis* min_connect_timeout_ms) {
267
+ grpc_millis initial_backoff_ms =
268
+ GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000;
269
+ *min_connect_timeout_ms =
270
+ GRPC_SUBCHANNEL_RECONNECT_MIN_TIMEOUT_SECONDS * 1000;
271
+ grpc_millis max_backoff_ms =
272
+ GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000;
273
+ bool fixed_reconnect_backoff = false;
274
+ if (args != nullptr) {
275
+ for (size_t i = 0; i < args->num_args; i++) {
276
+ if (0 == strcmp(args->args[i].key,
277
+ "grpc.testing.fixed_reconnect_backoff_ms")) {
278
+ fixed_reconnect_backoff = true;
279
+ initial_backoff_ms = *min_connect_timeout_ms = max_backoff_ms =
280
+ grpc_channel_arg_get_integer(
281
+ &args->args[i],
282
+ {static_cast<int>(initial_backoff_ms), 100, INT_MAX});
283
+ } else if (0 ==
284
+ strcmp(args->args[i].key, GRPC_ARG_MIN_RECONNECT_BACKOFF_MS)) {
285
+ fixed_reconnect_backoff = false;
286
+ *min_connect_timeout_ms = grpc_channel_arg_get_integer(
287
+ &args->args[i],
288
+ {static_cast<int>(*min_connect_timeout_ms), 100, INT_MAX});
289
+ } else if (0 ==
290
+ strcmp(args->args[i].key, GRPC_ARG_MAX_RECONNECT_BACKOFF_MS)) {
291
+ fixed_reconnect_backoff = false;
292
+ max_backoff_ms = grpc_channel_arg_get_integer(
293
+ &args->args[i], {static_cast<int>(max_backoff_ms), 100, INT_MAX});
294
+ } else if (0 == strcmp(args->args[i].key,
295
+ GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS)) {
296
+ fixed_reconnect_backoff = false;
297
+ initial_backoff_ms = grpc_channel_arg_get_integer(
298
+ &args->args[i],
299
+ {static_cast<int>(initial_backoff_ms), 100, INT_MAX});
300
+ }
301
+ }
302
+ }
303
+ backoff_options->set_initial_backoff(initial_backoff_ms)
304
+ .set_multiplier(fixed_reconnect_backoff
305
+ ? 1.0
306
+ : GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER)
307
+ .set_jitter(fixed_reconnect_backoff ? 0.0
308
+ : GRPC_SUBCHANNEL_RECONNECT_JITTER)
309
+ .set_max_backoff(max_backoff_ms);
310
+ }
311
+
312
+ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
288
313
  const grpc_subchannel_args* args) {
289
314
  grpc_subchannel_key* key = grpc_subchannel_key_create(args);
290
- grpc_subchannel* c = grpc_subchannel_index_find(exec_ctx, key);
315
+ grpc_subchannel* c = grpc_subchannel_index_find(key);
291
316
  if (c) {
292
- grpc_subchannel_key_destroy(exec_ctx, key);
317
+ grpc_subchannel_key_destroy(key);
293
318
  return c;
294
319
  }
295
320
 
296
- GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx);
321
+ GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED();
297
322
  c = (grpc_subchannel*)gpr_zalloc(sizeof(*c));
298
323
  c->key = key;
299
324
  gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS);
@@ -311,10 +336,10 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx,
311
336
  c->pollset_set = grpc_pollset_set_create();
312
337
  grpc_resolved_address* addr =
313
338
  (grpc_resolved_address*)gpr_malloc(sizeof(*addr));
314
- grpc_get_subchannel_address_arg(exec_ctx, args->args, addr);
339
+ grpc_get_subchannel_address_arg(args->args, addr);
315
340
  grpc_resolved_address* new_address = nullptr;
316
341
  grpc_channel_args* new_args = nullptr;
317
- if (grpc_proxy_mappers_map_address(exec_ctx, addr, args->args, &new_address,
342
+ if (grpc_proxy_mappers_map_address(addr, args->args, &new_address,
318
343
  &new_args)) {
319
344
  GPR_ASSERT(new_address != nullptr);
320
345
  gpr_free(addr);
@@ -327,68 +352,34 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx,
327
352
  new_args != nullptr ? new_args : args->args, keys_to_remove,
328
353
  GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1);
329
354
  gpr_free(new_arg.value.string);
330
- if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args);
355
+ if (new_args != nullptr) grpc_channel_args_destroy(new_args);
331
356
  c->root_external_state_watcher.next = c->root_external_state_watcher.prev =
332
357
  &c->root_external_state_watcher;
333
- GRPC_CLOSURE_INIT(&c->connected, subchannel_connected, c,
358
+ GRPC_CLOSURE_INIT(&c->on_connected, on_subchannel_connected, c,
334
359
  grpc_schedule_on_exec_ctx);
335
360
  grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE,
336
361
  "subchannel");
337
- int initial_backoff_ms =
338
- GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000;
339
- int min_backoff_ms = GRPC_SUBCHANNEL_RECONNECT_MIN_BACKOFF_SECONDS * 1000;
340
- int max_backoff_ms = GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000;
341
- bool fixed_reconnect_backoff = false;
342
- if (c->args) {
343
- for (size_t i = 0; i < c->args->num_args; i++) {
344
- if (0 == strcmp(c->args->args[i].key,
345
- "grpc.testing.fixed_reconnect_backoff_ms")) {
346
- fixed_reconnect_backoff = true;
347
- initial_backoff_ms = min_backoff_ms = max_backoff_ms =
348
- grpc_channel_arg_get_integer(&c->args->args[i],
349
- {initial_backoff_ms, 100, INT_MAX});
350
- } else if (0 == strcmp(c->args->args[i].key,
351
- GRPC_ARG_MIN_RECONNECT_BACKOFF_MS)) {
352
- fixed_reconnect_backoff = false;
353
- min_backoff_ms = grpc_channel_arg_get_integer(
354
- &c->args->args[i], {min_backoff_ms, 100, INT_MAX});
355
- } else if (0 == strcmp(c->args->args[i].key,
356
- GRPC_ARG_MAX_RECONNECT_BACKOFF_MS)) {
357
- fixed_reconnect_backoff = false;
358
- max_backoff_ms = grpc_channel_arg_get_integer(
359
- &c->args->args[i], {max_backoff_ms, 100, INT_MAX});
360
- } else if (0 == strcmp(c->args->args[i].key,
361
- GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS)) {
362
- fixed_reconnect_backoff = false;
363
- initial_backoff_ms = grpc_channel_arg_get_integer(
364
- &c->args->args[i], {initial_backoff_ms, 100, INT_MAX});
365
- }
366
- }
367
- }
368
- grpc_backoff_init(
369
- &c->backoff_state, initial_backoff_ms,
370
- fixed_reconnect_backoff ? 1.0
371
- : GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER,
372
- fixed_reconnect_backoff ? 0.0 : GRPC_SUBCHANNEL_RECONNECT_JITTER,
373
- min_backoff_ms, max_backoff_ms);
362
+ grpc_core::BackOff::Options backoff_options;
363
+ parse_args_for_backoff_values(args->args, &backoff_options,
364
+ &c->min_connect_timeout_ms);
365
+ c->backoff.Init(backoff_options);
374
366
  gpr_mu_init(&c->mu);
375
367
 
376
- return grpc_subchannel_index_register(exec_ctx, key, c);
368
+ return grpc_subchannel_index_register(key, c);
377
369
  }
378
370
 
379
- static void continue_connect_locked(grpc_exec_ctx* exec_ctx,
380
- grpc_subchannel* c) {
371
+ static void continue_connect_locked(grpc_subchannel* c) {
381
372
  grpc_connect_in_args args;
382
-
383
373
  args.interested_parties = c->pollset_set;
384
- args.deadline = c->backoff_result.current_deadline;
374
+ const grpc_millis min_deadline =
375
+ c->min_connect_timeout_ms + grpc_core::ExecCtx::Get()->Now();
376
+ c->next_attempt_deadline = c->backoff->NextAttemptTime();
377
+ args.deadline = std::max(c->next_attempt_deadline, min_deadline);
385
378
  args.channel_args = c->args;
386
-
387
- grpc_connectivity_state_set(exec_ctx, &c->state_tracker,
388
- GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE,
389
- "state_change");
390
- grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result,
391
- &c->connected);
379
+ grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_CONNECTING,
380
+ GRPC_ERROR_NONE, "state_change");
381
+ grpc_connector_connect(c->connector, &args, &c->connecting_result,
382
+ &c->on_connected);
392
383
  }
393
384
 
394
385
  grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c,
@@ -400,24 +391,23 @@ grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c,
400
391
  return state;
401
392
  }
402
393
 
403
- static void on_external_state_watcher_done(grpc_exec_ctx* exec_ctx, void* arg,
404
- grpc_error* error) {
394
+ static void on_external_state_watcher_done(void* arg, grpc_error* error) {
405
395
  external_state_watcher* w = (external_state_watcher*)arg;
406
396
  grpc_closure* follow_up = w->notify;
407
397
  if (w->pollset_set != nullptr) {
408
- grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set,
398
+ grpc_pollset_set_del_pollset_set(w->subchannel->pollset_set,
409
399
  w->pollset_set);
410
400
  }
411
401
  gpr_mu_lock(&w->subchannel->mu);
412
402
  w->next->prev = w->prev;
413
403
  w->prev->next = w->next;
414
404
  gpr_mu_unlock(&w->subchannel->mu);
415
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher");
405
+ GRPC_SUBCHANNEL_WEAK_UNREF(w->subchannel, "external_state_watcher");
416
406
  gpr_free(w);
417
- GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error));
407
+ GRPC_CLOSURE_RUN(follow_up, GRPC_ERROR_REF(error));
418
408
  }
419
409
 
420
- static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
410
+ static void on_alarm(void* arg, grpc_error* error) {
421
411
  grpc_subchannel* c = (grpc_subchannel*)arg;
422
412
  gpr_mu_lock(&c->mu);
423
413
  c->have_alarm = false;
@@ -429,18 +419,16 @@ static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
429
419
  }
430
420
  if (error == GRPC_ERROR_NONE) {
431
421
  gpr_log(GPR_INFO, "Failed to connect to channel, retrying");
432
- c->backoff_result = grpc_backoff_step(exec_ctx, &c->backoff_state);
433
- continue_connect_locked(exec_ctx, c);
422
+ continue_connect_locked(c);
434
423
  gpr_mu_unlock(&c->mu);
435
424
  } else {
436
425
  gpr_mu_unlock(&c->mu);
437
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting");
426
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting");
438
427
  }
439
428
  GRPC_ERROR_UNREF(error);
440
429
  }
441
430
 
442
- static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx,
443
- grpc_subchannel* c) {
431
+ static void maybe_start_connecting_locked(grpc_subchannel* c) {
444
432
  if (c->disconnected) {
445
433
  /* Don't try to connect if we're already disconnected */
446
434
  return;
@@ -451,7 +439,7 @@ static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx,
451
439
  return;
452
440
  }
453
441
 
454
- if (GET_CONNECTED_SUBCHANNEL(c, no_barrier) != nullptr) {
442
+ if (c->connected_subchannel != nullptr) {
455
443
  /* Already connected: don't restart */
456
444
  return;
457
445
  }
@@ -466,28 +454,26 @@ static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx,
466
454
 
467
455
  if (!c->backoff_begun) {
468
456
  c->backoff_begun = true;
469
- c->backoff_result = grpc_backoff_begin(exec_ctx, &c->backoff_state);
470
- continue_connect_locked(exec_ctx, c);
457
+ continue_connect_locked(c);
471
458
  } else {
472
459
  GPR_ASSERT(!c->have_alarm);
473
460
  c->have_alarm = true;
474
461
  const grpc_millis time_til_next =
475
- c->backoff_result.next_attempt_start_time - grpc_exec_ctx_now(exec_ctx);
462
+ c->next_attempt_deadline - grpc_core::ExecCtx::Get()->Now();
476
463
  if (time_til_next <= 0) {
477
- gpr_log(GPR_INFO, "Retry immediately");
464
+ gpr_log(GPR_INFO, "Subchannel %p: Retry immediately", c);
478
465
  } else {
479
- gpr_log(GPR_INFO, "Retry in %" PRIdPTR " milliseconds", time_til_next);
466
+ gpr_log(GPR_INFO, "Subchannel %p: Retry in %" PRIdPTR " milliseconds", c,
467
+ time_til_next);
480
468
  }
481
469
  GRPC_CLOSURE_INIT(&c->on_alarm, on_alarm, c, grpc_schedule_on_exec_ctx);
482
- grpc_timer_init(exec_ctx, &c->alarm,
483
- c->backoff_result.next_attempt_start_time, &c->on_alarm);
470
+ grpc_timer_init(&c->alarm, c->next_attempt_deadline, &c->on_alarm);
484
471
  }
485
472
  }
486
473
 
487
474
  void grpc_subchannel_notify_on_state_change(
488
- grpc_exec_ctx* exec_ctx, grpc_subchannel* c,
489
- grpc_pollset_set* interested_parties, grpc_connectivity_state* state,
490
- grpc_closure* notify) {
475
+ grpc_subchannel* c, grpc_pollset_set* interested_parties,
476
+ grpc_connectivity_state* state, grpc_closure* notify) {
491
477
  external_state_watcher* w;
492
478
 
493
479
  if (state == nullptr) {
@@ -495,8 +481,8 @@ void grpc_subchannel_notify_on_state_change(
495
481
  for (w = c->root_external_state_watcher.next;
496
482
  w != &c->root_external_state_watcher; w = w->next) {
497
483
  if (w->notify == notify) {
498
- grpc_connectivity_state_notify_on_state_change(
499
- exec_ctx, &c->state_tracker, nullptr, &w->closure);
484
+ grpc_connectivity_state_notify_on_state_change(&c->state_tracker,
485
+ nullptr, &w->closure);
500
486
  }
501
487
  }
502
488
  gpr_mu_unlock(&c->mu);
@@ -508,172 +494,144 @@ void grpc_subchannel_notify_on_state_change(
508
494
  GRPC_CLOSURE_INIT(&w->closure, on_external_state_watcher_done, w,
509
495
  grpc_schedule_on_exec_ctx);
510
496
  if (interested_parties != nullptr) {
511
- grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set,
512
- interested_parties);
497
+ grpc_pollset_set_add_pollset_set(c->pollset_set, interested_parties);
513
498
  }
514
499
  GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher");
515
500
  gpr_mu_lock(&c->mu);
516
501
  w->next = &c->root_external_state_watcher;
517
502
  w->prev = w->next->prev;
518
503
  w->next->prev = w->prev->next = w;
519
- grpc_connectivity_state_notify_on_state_change(exec_ctx, &c->state_tracker,
520
- state, &w->closure);
521
- maybe_start_connecting_locked(exec_ctx, c);
504
+ grpc_connectivity_state_notify_on_state_change(&c->state_tracker, state,
505
+ &w->closure);
506
+ maybe_start_connecting_locked(c);
522
507
  gpr_mu_unlock(&c->mu);
523
508
  }
524
509
  }
525
510
 
526
- void grpc_connected_subchannel_process_transport_op(
527
- grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con,
528
- grpc_transport_op* op) {
529
- grpc_channel_stack* channel_stack = CHANNEL_STACK_FROM_CONNECTION(con);
530
- grpc_channel_element* top_elem = grpc_channel_stack_element(channel_stack, 0);
531
- top_elem->filter->start_transport_op(exec_ctx, top_elem, op);
532
- }
533
-
534
- static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p,
535
- grpc_error* error) {
536
- state_watcher* sw = (state_watcher*)p;
537
- grpc_subchannel* c = sw->subchannel;
511
+ static void on_connected_subchannel_connectivity_changed(void* p,
512
+ grpc_error* error) {
513
+ state_watcher* connected_subchannel_watcher = (state_watcher*)p;
514
+ grpc_subchannel* c = connected_subchannel_watcher->subchannel;
538
515
  gpr_mu* mu = &c->mu;
539
516
 
540
517
  gpr_mu_lock(mu);
541
518
 
542
- /* if we failed just leave this closure */
543
- if (sw->connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) {
544
- /* any errors on a subchannel ==> we're done, create a new one */
545
- sw->connectivity_state = GRPC_CHANNEL_SHUTDOWN;
546
- }
547
- grpc_connectivity_state_set(exec_ctx, &c->state_tracker,
548
- sw->connectivity_state, GRPC_ERROR_REF(error),
549
- "reflect_child");
550
- if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) {
551
- grpc_connected_subchannel_notify_on_state_change(
552
- exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr,
553
- &sw->connectivity_state, &sw->closure);
554
- GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher");
555
- sw = nullptr;
519
+ switch (connected_subchannel_watcher->connectivity_state) {
520
+ case GRPC_CHANNEL_TRANSIENT_FAILURE:
521
+ case GRPC_CHANNEL_SHUTDOWN: {
522
+ if (!c->disconnected && c->connected_subchannel != nullptr) {
523
+ if (grpc_trace_stream_refcount.enabled()) {
524
+ gpr_log(GPR_INFO,
525
+ "Connected subchannel %p of subchannel %p has gone into %s. "
526
+ "Attempting to reconnect.",
527
+ c->connected_subchannel.get(), c,
528
+ grpc_connectivity_state_name(
529
+ connected_subchannel_watcher->connectivity_state));
530
+ }
531
+ c->connected_subchannel.reset();
532
+ grpc_connectivity_state_set(&c->state_tracker,
533
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
534
+ GRPC_ERROR_REF(error), "reflect_child");
535
+ c->backoff_begun = false;
536
+ c->backoff->Reset();
537
+ maybe_start_connecting_locked(c);
538
+ } else {
539
+ connected_subchannel_watcher->connectivity_state =
540
+ GRPC_CHANNEL_SHUTDOWN;
541
+ }
542
+ break;
543
+ }
544
+ default: {
545
+ grpc_connectivity_state_set(
546
+ &c->state_tracker, connected_subchannel_watcher->connectivity_state,
547
+ GRPC_ERROR_REF(error), "reflect_child");
548
+ GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher");
549
+ c->connected_subchannel->NotifyOnStateChange(
550
+ nullptr, &connected_subchannel_watcher->connectivity_state,
551
+ &connected_subchannel_watcher->closure);
552
+ connected_subchannel_watcher = nullptr;
553
+ }
556
554
  }
557
-
558
555
  gpr_mu_unlock(mu);
559
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher");
560
- gpr_free(sw);
561
- }
562
-
563
- static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx,
564
- grpc_connected_subchannel* con,
565
- grpc_pollset_set* interested_parties,
566
- grpc_connectivity_state* state,
567
- grpc_closure* closure) {
568
- grpc_transport_op* op = grpc_make_transport_op(nullptr);
569
- grpc_channel_element* elem;
570
- op->connectivity_state = state;
571
- op->on_connectivity_state_change = closure;
572
- op->bind_pollset_set = interested_parties;
573
- elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0);
574
- elem->filter->start_transport_op(exec_ctx, elem, op);
575
- }
576
-
577
- void grpc_connected_subchannel_notify_on_state_change(
578
- grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con,
579
- grpc_pollset_set* interested_parties, grpc_connectivity_state* state,
580
- grpc_closure* closure) {
581
- connected_subchannel_state_op(exec_ctx, con, interested_parties, state,
582
- closure);
556
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "state_watcher");
557
+ gpr_free(connected_subchannel_watcher);
583
558
  }
584
559
 
585
- void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx,
586
- grpc_connected_subchannel* con,
587
- grpc_closure* closure) {
588
- grpc_transport_op* op = grpc_make_transport_op(nullptr);
589
- grpc_channel_element* elem;
590
- op->send_ping = closure;
591
- elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0);
592
- elem->filter->start_transport_op(exec_ctx, elem, op);
593
- }
594
-
595
- static bool publish_transport_locked(grpc_exec_ctx* exec_ctx,
596
- grpc_subchannel* c) {
597
- grpc_connected_subchannel* con;
598
- grpc_channel_stack* stk;
599
- state_watcher* sw_subchannel;
600
-
560
+ static bool publish_transport_locked(grpc_subchannel* c) {
601
561
  /* construct channel stack */
602
562
  grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create();
603
563
  grpc_channel_stack_builder_set_channel_arguments(
604
- exec_ctx, builder, c->connecting_result.channel_args);
564
+ builder, c->connecting_result.channel_args);
605
565
  grpc_channel_stack_builder_set_transport(builder,
606
566
  c->connecting_result.transport);
607
567
 
608
- if (!grpc_channel_init_create_stack(exec_ctx, builder,
609
- GRPC_CLIENT_SUBCHANNEL)) {
610
- grpc_channel_stack_builder_destroy(exec_ctx, builder);
568
+ if (!grpc_channel_init_create_stack(builder, GRPC_CLIENT_SUBCHANNEL)) {
569
+ grpc_channel_stack_builder_destroy(builder);
611
570
  return false;
612
571
  }
572
+ grpc_channel_stack* stk;
613
573
  grpc_error* error = grpc_channel_stack_builder_finish(
614
- exec_ctx, builder, 0, 1, connection_destroy, nullptr, (void**)&con);
574
+ builder, 0, 1, connection_destroy, nullptr, (void**)&stk);
615
575
  if (error != GRPC_ERROR_NONE) {
616
- grpc_transport_destroy(exec_ctx, c->connecting_result.transport);
576
+ grpc_transport_destroy(c->connecting_result.transport);
617
577
  gpr_log(GPR_ERROR, "error initializing subchannel stack: %s",
618
578
  grpc_error_string(error));
619
579
  GRPC_ERROR_UNREF(error);
620
580
  return false;
621
581
  }
622
- stk = CHANNEL_STACK_FROM_CONNECTION(con);
623
582
  memset(&c->connecting_result, 0, sizeof(c->connecting_result));
624
583
 
625
584
  /* initialize state watcher */
626
- sw_subchannel = (state_watcher*)gpr_malloc(sizeof(*sw_subchannel));
627
- sw_subchannel->subchannel = c;
628
- sw_subchannel->connectivity_state = GRPC_CHANNEL_READY;
629
- GRPC_CLOSURE_INIT(&sw_subchannel->closure, subchannel_on_child_state_changed,
630
- sw_subchannel, grpc_schedule_on_exec_ctx);
585
+ state_watcher* connected_subchannel_watcher =
586
+ (state_watcher*)gpr_zalloc(sizeof(*connected_subchannel_watcher));
587
+ connected_subchannel_watcher->subchannel = c;
588
+ connected_subchannel_watcher->connectivity_state = GRPC_CHANNEL_READY;
589
+ GRPC_CLOSURE_INIT(&connected_subchannel_watcher->closure,
590
+ on_connected_subchannel_connectivity_changed,
591
+ connected_subchannel_watcher, grpc_schedule_on_exec_ctx);
631
592
 
632
593
  if (c->disconnected) {
633
- gpr_free(sw_subchannel);
634
- grpc_channel_stack_destroy(exec_ctx, stk);
635
- gpr_free(con);
594
+ gpr_free(connected_subchannel_watcher);
595
+ grpc_channel_stack_destroy(stk);
596
+ gpr_free(stk);
636
597
  return false;
637
598
  }
638
599
 
639
600
  /* publish */
640
- /* TODO(ctiller): this full barrier seems to clear up a TSAN failure.
641
- I'd have expected the rel_cas below to be enough, but
642
- seemingly it's not.
643
- Re-evaluate if we really need this. */
644
- gpr_atm_full_barrier();
645
- GPR_ASSERT(gpr_atm_rel_cas(&c->connected_subchannel, 0, (gpr_atm)con));
601
+ c->connected_subchannel.reset(
602
+ grpc_core::New<grpc_core::ConnectedSubchannel>(stk));
603
+ gpr_log(GPR_INFO, "New connected subchannel at %p for subchannel %p",
604
+ c->connected_subchannel.get(), c);
646
605
 
647
606
  /* setup subchannel watching connected subchannel for changes; subchannel
648
607
  ref for connecting is donated to the state watcher */
649
608
  GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher");
650
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting");
651
- grpc_connected_subchannel_notify_on_state_change(
652
- exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state,
653
- &sw_subchannel->closure);
609
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting");
610
+ c->connected_subchannel->NotifyOnStateChange(
611
+ c->pollset_set, &connected_subchannel_watcher->connectivity_state,
612
+ &connected_subchannel_watcher->closure);
654
613
 
655
614
  /* signal completion */
656
- grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY,
615
+ grpc_connectivity_state_set(&c->state_tracker, GRPC_CHANNEL_READY,
657
616
  GRPC_ERROR_NONE, "connected");
658
617
  return true;
659
618
  }
660
619
 
661
- static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg,
662
- grpc_error* error) {
620
+ static void on_subchannel_connected(void* arg, grpc_error* error) {
663
621
  grpc_subchannel* c = (grpc_subchannel*)arg;
664
622
  grpc_channel_args* delete_channel_args = c->connecting_result.channel_args;
665
623
 
666
- GRPC_SUBCHANNEL_WEAK_REF(c, "connected");
624
+ GRPC_SUBCHANNEL_WEAK_REF(c, "on_subchannel_connected");
667
625
  gpr_mu_lock(&c->mu);
668
626
  c->connecting = false;
669
627
  if (c->connecting_result.transport != nullptr &&
670
- publish_transport_locked(exec_ctx, c)) {
628
+ publish_transport_locked(c)) {
671
629
  /* do nothing, transport was published */
672
630
  } else if (c->disconnected) {
673
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting");
631
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting");
674
632
  } else {
675
633
  grpc_connectivity_state_set(
676
- exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
634
+ &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
677
635
  grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
678
636
  "Connect Failed", &error, 1),
679
637
  GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE),
@@ -682,27 +640,26 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg,
682
640
  const char* errmsg = grpc_error_string(error);
683
641
  gpr_log(GPR_INFO, "Connect failed: %s", errmsg);
684
642
 
685
- maybe_start_connecting_locked(exec_ctx, c);
686
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting");
643
+ maybe_start_connecting_locked(c);
644
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "connecting");
687
645
  }
688
646
  gpr_mu_unlock(&c->mu);
689
- GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connected");
690
- grpc_channel_args_destroy(exec_ctx, delete_channel_args);
647
+ GRPC_SUBCHANNEL_WEAK_UNREF(c, "connected");
648
+ grpc_channel_args_destroy(delete_channel_args);
691
649
  }
692
650
 
693
651
  /*
694
652
  * grpc_subchannel_call implementation
695
653
  */
696
654
 
697
- static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call,
698
- grpc_error* error) {
655
+ static void subchannel_call_destroy(void* call, grpc_error* error) {
699
656
  grpc_subchannel_call* c = (grpc_subchannel_call*)call;
700
657
  GPR_ASSERT(c->schedule_closure_after_destroy != nullptr);
701
658
  GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0);
702
- grpc_connected_subchannel* connection = c->connection;
703
- grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr,
659
+ grpc_core::ConnectedSubchannel* connection = c->connection;
660
+ grpc_call_stack_destroy(SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr,
704
661
  c->schedule_closure_after_destroy);
705
- GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call");
662
+ connection->Unref(DEBUG_LOCATION, "subchannel_call");
706
663
  GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0);
707
664
  }
708
665
 
@@ -718,26 +675,27 @@ void grpc_subchannel_call_ref(
718
675
  GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON);
719
676
  }
720
677
 
721
- void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx,
722
- grpc_subchannel_call* c
723
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
724
- GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON);
678
+ void grpc_subchannel_call_unref(
679
+ grpc_subchannel_call* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
680
+ GRPC_CALL_STACK_UNREF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON);
725
681
  }
726
682
 
727
- void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx,
728
- grpc_subchannel_call* call,
683
+ void grpc_subchannel_call_process_op(grpc_subchannel_call* call,
729
684
  grpc_transport_stream_op_batch* batch) {
730
685
  GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0);
731
686
  grpc_call_stack* call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call);
732
687
  grpc_call_element* top_elem = grpc_call_stack_element(call_stack, 0);
733
688
  GRPC_CALL_LOG_OP(GPR_INFO, top_elem, batch);
734
- top_elem->filter->start_transport_stream_op_batch(exec_ctx, top_elem, batch);
689
+ top_elem->filter->start_transport_stream_op_batch(top_elem, batch);
735
690
  GPR_TIMER_END("grpc_subchannel_call_process_op", 0);
736
691
  }
737
692
 
738
- grpc_connected_subchannel* grpc_subchannel_get_connected_subchannel(
739
- grpc_subchannel* c) {
740
- return GET_CONNECTED_SUBCHANNEL(c, acq);
693
+ grpc_core::RefCountedPtr<grpc_core::ConnectedSubchannel>
694
+ grpc_subchannel_get_connected_subchannel(grpc_subchannel* c) {
695
+ gpr_mu_lock(&c->mu);
696
+ auto copy = c->connected_subchannel;
697
+ gpr_mu_unlock(&c->mu);
698
+ return copy;
741
699
  }
742
700
 
743
701
  const grpc_subchannel_key* grpc_subchannel_get_key(
@@ -745,56 +703,25 @@ const grpc_subchannel_key* grpc_subchannel_get_key(
745
703
  return subchannel->key;
746
704
  }
747
705
 
748
- grpc_error* grpc_connected_subchannel_create_call(
749
- grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con,
750
- const grpc_connected_subchannel_call_args* args,
751
- grpc_subchannel_call** call) {
752
- grpc_channel_stack* chanstk = CHANNEL_STACK_FROM_CONNECTION(con);
753
- *call = (grpc_subchannel_call*)gpr_arena_alloc(
754
- args->arena, sizeof(grpc_subchannel_call) + chanstk->call_stack_size);
755
- grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call);
756
- (*call)->connection = GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call");
757
- const grpc_call_element_args call_args = {
758
- callstk, /* call_stack */
759
- nullptr, /* server_transport_data */
760
- args->context, /* context */
761
- args->path, /* path */
762
- args->start_time, /* start_time */
763
- args->deadline, /* deadline */
764
- args->arena, /* arena */
765
- args->call_combiner /* call_combiner */
766
- };
767
- grpc_error* error = grpc_call_stack_init(
768
- exec_ctx, chanstk, 1, subchannel_call_destroy, *call, &call_args);
769
- if (error != GRPC_ERROR_NONE) {
770
- const char* error_string = grpc_error_string(error);
771
- gpr_log(GPR_ERROR, "error: %s", error_string);
772
- return error;
773
- }
774
- grpc_call_stack_set_pollset_or_pollset_set(exec_ctx, callstk, args->pollent);
775
- return GRPC_ERROR_NONE;
776
- }
777
-
778
706
  grpc_call_stack* grpc_subchannel_call_get_call_stack(
779
707
  grpc_subchannel_call* subchannel_call) {
780
708
  return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call);
781
709
  }
782
710
 
783
- static void grpc_uri_to_sockaddr(grpc_exec_ctx* exec_ctx, const char* uri_str,
711
+ static void grpc_uri_to_sockaddr(const char* uri_str,
784
712
  grpc_resolved_address* addr) {
785
- grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */);
713
+ grpc_uri* uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */);
786
714
  GPR_ASSERT(uri != nullptr);
787
715
  if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr));
788
716
  grpc_uri_destroy(uri);
789
717
  }
790
718
 
791
- void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx,
792
- const grpc_channel_args* args,
719
+ void grpc_get_subchannel_address_arg(const grpc_channel_args* args,
793
720
  grpc_resolved_address* addr) {
794
721
  const char* addr_uri_str = grpc_get_subchannel_address_uri_arg(args);
795
722
  memset(addr, 0, sizeof(*addr));
796
723
  if (*addr_uri_str != '\0') {
797
- grpc_uri_to_sockaddr(exec_ctx, addr_uri_str, addr);
724
+ grpc_uri_to_sockaddr(addr_uri_str, addr);
798
725
  }
799
726
  }
800
727
 
@@ -811,3 +738,64 @@ grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr) {
811
738
  (char*)GRPC_ARG_SUBCHANNEL_ADDRESS,
812
739
  addr->len > 0 ? grpc_sockaddr_to_uri(addr) : gpr_strdup(""));
813
740
  }
741
+
742
+ namespace grpc_core {
743
+ ConnectedSubchannel::ConnectedSubchannel(grpc_channel_stack* channel_stack)
744
+ : grpc_core::RefCountedWithTracing(&grpc_trace_stream_refcount),
745
+ channel_stack_(channel_stack) {}
746
+
747
+ ConnectedSubchannel::~ConnectedSubchannel() {
748
+ GRPC_CHANNEL_STACK_UNREF(channel_stack_, "connected_subchannel_dtor");
749
+ }
750
+
751
+ void ConnectedSubchannel::NotifyOnStateChange(
752
+ grpc_pollset_set* interested_parties, grpc_connectivity_state* state,
753
+ grpc_closure* closure) {
754
+ grpc_transport_op* op = grpc_make_transport_op(nullptr);
755
+ grpc_channel_element* elem;
756
+ op->connectivity_state = state;
757
+ op->on_connectivity_state_change = closure;
758
+ op->bind_pollset_set = interested_parties;
759
+ elem = grpc_channel_stack_element(channel_stack_, 0);
760
+ elem->filter->start_transport_op(elem, op);
761
+ }
762
+
763
+ void ConnectedSubchannel::Ping(grpc_closure* on_initiate,
764
+ grpc_closure* on_ack) {
765
+ grpc_transport_op* op = grpc_make_transport_op(nullptr);
766
+ grpc_channel_element* elem;
767
+ op->send_ping.on_initiate = on_initiate;
768
+ op->send_ping.on_ack = on_ack;
769
+ elem = grpc_channel_stack_element(channel_stack_, 0);
770
+ elem->filter->start_transport_op(elem, op);
771
+ }
772
+
773
+ grpc_error* ConnectedSubchannel::CreateCall(const CallArgs& args,
774
+ grpc_subchannel_call** call) {
775
+ *call = (grpc_subchannel_call*)gpr_arena_alloc(
776
+ args.arena,
777
+ sizeof(grpc_subchannel_call) + channel_stack_->call_stack_size);
778
+ grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call);
779
+ Ref(DEBUG_LOCATION, "subchannel_call");
780
+ (*call)->connection = this;
781
+ const grpc_call_element_args call_args = {
782
+ callstk, /* call_stack */
783
+ nullptr, /* server_transport_data */
784
+ args.context, /* context */
785
+ args.path, /* path */
786
+ args.start_time, /* start_time */
787
+ args.deadline, /* deadline */
788
+ args.arena, /* arena */
789
+ args.call_combiner /* call_combiner */
790
+ };
791
+ grpc_error* error = grpc_call_stack_init(
792
+ channel_stack_, 1, subchannel_call_destroy, *call, &call_args);
793
+ if (error != GRPC_ERROR_NONE) {
794
+ const char* error_string = grpc_error_string(error);
795
+ gpr_log(GPR_ERROR, "error: %s", error_string);
796
+ return error;
797
+ }
798
+ grpc_call_stack_set_pollset_or_pollset_set(callstk, args.pollent);
799
+ return GRPC_ERROR_NONE;
800
+ }
801
+ } // namespace grpc_core