grpc 1.3.4 → 1.4.0

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

Potentially problematic release.


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

Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +581 -450
  3. data/include/grpc/census.h +49 -49
  4. data/include/grpc/grpc.h +16 -70
  5. data/include/grpc/grpc_security.h +59 -59
  6. data/include/grpc/grpc_security_constants.h +9 -9
  7. data/include/grpc/impl/codegen/atm.h +1 -1
  8. data/include/grpc/impl/codegen/atm_windows.h +4 -4
  9. data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
  10. data/include/grpc/impl/codegen/compression_types.h +4 -5
  11. data/include/grpc/impl/codegen/gpr_slice.h +5 -5
  12. data/include/grpc/impl/codegen/gpr_types.h +6 -7
  13. data/include/grpc/impl/codegen/grpc_types.h +128 -59
  14. data/include/grpc/impl/codegen/port_platform.h +6 -0
  15. data/include/grpc/impl/codegen/propagation_bits.h +2 -2
  16. data/include/grpc/impl/codegen/slice.h +13 -12
  17. data/include/grpc/impl/codegen/status.h +23 -18
  18. data/include/grpc/impl/codegen/sync.h +1 -1
  19. data/include/grpc/load_reporting.h +6 -6
  20. data/include/grpc/slice.h +47 -25
  21. data/include/grpc/slice_buffer.h +18 -14
  22. data/include/grpc/support/alloc.h +7 -7
  23. data/include/grpc/support/cmdline.h +10 -10
  24. data/include/grpc/support/cpu.h +3 -3
  25. data/include/grpc/support/histogram.h +1 -1
  26. data/include/grpc/support/host_port.h +2 -2
  27. data/include/grpc/support/log.h +9 -9
  28. data/include/grpc/support/log_windows.h +1 -1
  29. data/include/grpc/support/string_util.h +3 -3
  30. data/include/grpc/support/subprocess.h +3 -3
  31. data/include/grpc/support/sync.h +31 -31
  32. data/include/grpc/support/thd.h +11 -11
  33. data/include/grpc/support/time.h +12 -12
  34. data/include/grpc/support/tls.h +1 -1
  35. data/include/grpc/support/tls_gcc.h +2 -2
  36. data/include/grpc/support/tls_msvc.h +1 -1
  37. data/include/grpc/support/tls_pthread.h +1 -1
  38. data/include/grpc/support/useful.h +2 -2
  39. data/include/grpc/support/workaround_list.h +46 -0
  40. data/src/core/ext/census/context.c +1 -1
  41. data/src/core/ext/census/intrusive_hash_map.c +319 -0
  42. data/src/core/ext/census/intrusive_hash_map.h +167 -0
  43. data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
  44. data/src/core/ext/census/resource.c +3 -1
  45. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  46. data/src/core/ext/filters/client_channel/client_channel.c +173 -103
  47. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  48. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  49. data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
  50. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  51. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  52. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
  53. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  54. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  55. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
  56. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
  57. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  58. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  59. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  60. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
  61. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  62. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  63. data/src/core/ext/filters/client_channel/parse_address.c +90 -59
  64. data/src/core/ext/filters/client_channel/parse_address.h +17 -8
  65. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
  66. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
  67. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
  68. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  69. data/src/core/ext/filters/client_channel/subchannel.c +20 -17
  70. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  71. data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
  72. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  73. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  74. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  75. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  76. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  77. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  78. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  79. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  80. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  81. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  82. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  83. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  84. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  85. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  86. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  87. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  88. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
  89. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
  90. data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
  91. data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
  92. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
  94. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  95. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  96. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
  97. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  98. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  99. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  100. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  101. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  102. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  103. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  104. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  105. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  107. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  108. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  109. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  110. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  111. data/src/core/lib/channel/channel_args.c +30 -9
  112. data/src/core/lib/channel/channel_args.h +5 -1
  113. data/src/core/lib/channel/channel_stack.c +1 -1
  114. data/src/core/lib/channel/channel_stack.h +2 -2
  115. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  116. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  117. data/src/core/lib/channel/connected_channel.c +3 -1
  118. data/src/core/lib/channel/context.h +2 -2
  119. data/src/core/lib/compression/message_compress.c +2 -2
  120. data/src/core/lib/debug/trace.c +13 -6
  121. data/src/core/lib/debug/trace.h +27 -1
  122. data/src/core/lib/http/httpcli.c +1 -1
  123. data/src/core/lib/http/httpcli_security_connector.c +9 -11
  124. data/src/core/lib/http/parser.c +2 -2
  125. data/src/core/lib/http/parser.h +2 -1
  126. data/src/core/lib/iomgr/combiner.c +6 -6
  127. data/src/core/lib/iomgr/combiner.h +2 -1
  128. data/src/core/lib/iomgr/error.c +12 -5
  129. data/src/core/lib/iomgr/error.h +13 -13
  130. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  131. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  132. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  133. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  134. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  135. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  136. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  137. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  138. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
  139. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  140. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  141. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  142. data/src/core/lib/iomgr/ev_posix.c +22 -8
  143. data/src/core/lib/iomgr/ev_posix.h +4 -3
  144. data/src/core/lib/iomgr/ev_windows.c +43 -0
  145. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  146. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  147. data/src/core/lib/iomgr/iomgr.c +4 -0
  148. data/src/core/lib/iomgr/iomgr.h +3 -0
  149. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  150. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  151. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  152. data/src/core/lib/iomgr/pollset.h +2 -5
  153. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  154. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  155. data/src/core/lib/iomgr/resource_quota.c +9 -8
  156. data/src/core/lib/iomgr/resource_quota.h +2 -1
  157. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  158. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  159. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  160. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  161. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  162. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  163. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  164. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  165. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  166. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  167. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  168. data/src/core/lib/iomgr/timer_generic.c +24 -25
  169. data/src/core/lib/iomgr/timer_manager.c +276 -0
  170. data/src/core/lib/iomgr/timer_manager.h +52 -0
  171. data/src/core/lib/iomgr/timer_uv.c +6 -0
  172. data/src/core/lib/iomgr/udp_server.c +42 -9
  173. data/src/core/lib/iomgr/udp_server.h +3 -1
  174. data/src/core/lib/security/credentials/credentials.c +0 -1
  175. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  176. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  177. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  178. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  179. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  180. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  181. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  182. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  183. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  184. data/src/core/lib/security/transport/security_connector.c +45 -57
  185. data/src/core/lib/security/transport/security_connector.h +10 -14
  186. data/src/core/lib/security/transport/security_handshaker.c +123 -97
  187. data/src/core/lib/slice/b64.c +1 -1
  188. data/src/core/lib/slice/percent_encoding.c +3 -3
  189. data/src/core/lib/slice/slice.c +66 -33
  190. data/src/core/lib/slice/slice_buffer.c +25 -6
  191. data/src/core/lib/slice/slice_hash_table.c +33 -35
  192. data/src/core/lib/slice/slice_hash_table.h +7 -12
  193. data/src/core/lib/support/atomic.h +45 -0
  194. data/src/core/lib/support/atomic_with_atm.h +70 -0
  195. data/src/core/lib/support/atomic_with_std.h +48 -0
  196. data/src/core/lib/support/avl.c +14 -14
  197. data/src/core/lib/support/cmdline.c +3 -3
  198. data/src/core/lib/support/histogram.c +2 -2
  199. data/src/core/lib/support/host_port.c +1 -1
  200. data/src/core/lib/support/memory.h +74 -0
  201. data/src/core/lib/support/mpscq.c +36 -2
  202. data/src/core/lib/support/mpscq.h +28 -1
  203. data/src/core/lib/support/stack_lockfree.c +3 -36
  204. data/src/core/lib/support/string.c +12 -12
  205. data/src/core/lib/support/string_posix.c +1 -1
  206. data/src/core/lib/support/subprocess_posix.c +2 -2
  207. data/src/core/lib/support/thd_posix.c +1 -1
  208. data/src/core/lib/support/time_posix.c +8 -0
  209. data/src/core/lib/support/tmpfile_posix.c +10 -10
  210. data/src/core/lib/surface/alarm.c +3 -1
  211. data/src/core/lib/surface/api_trace.c +2 -1
  212. data/src/core/lib/surface/api_trace.h +2 -2
  213. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  214. data/src/core/lib/surface/call.c +65 -22
  215. data/src/core/lib/surface/call.h +4 -2
  216. data/src/core/lib/surface/channel_init.c +2 -19
  217. data/src/core/lib/surface/channel_stack_type.c +18 -0
  218. data/src/core/lib/surface/channel_stack_type.h +2 -0
  219. data/src/core/lib/surface/completion_queue.c +694 -247
  220. data/src/core/lib/surface/completion_queue.h +30 -13
  221. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  222. data/src/core/lib/surface/init.c +1 -52
  223. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  224. data/src/core/lib/surface/server.c +79 -110
  225. data/src/core/lib/surface/server.h +2 -1
  226. data/src/core/lib/surface/version.c +2 -2
  227. data/src/core/lib/transport/bdp_estimator.c +25 -9
  228. data/src/core/lib/transport/bdp_estimator.h +7 -1
  229. data/src/core/lib/transport/byte_stream.c +23 -9
  230. data/src/core/lib/transport/byte_stream.h +15 -6
  231. data/src/core/lib/transport/connectivity_state.c +6 -6
  232. data/src/core/lib/transport/connectivity_state.h +2 -1
  233. data/src/core/lib/transport/service_config.c +6 -13
  234. data/src/core/lib/transport/service_config.h +2 -2
  235. data/src/core/lib/transport/static_metadata.c +403 -389
  236. data/src/core/lib/transport/static_metadata.h +127 -114
  237. data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
  238. data/src/core/tsi/fake_transport_security.c +5 -4
  239. data/src/core/tsi/ssl_transport_security.c +71 -82
  240. data/src/core/tsi/ssl_transport_security.h +39 -61
  241. data/src/core/tsi/transport_security.c +83 -2
  242. data/src/core/tsi/transport_security.h +27 -2
  243. data/src/core/tsi/transport_security_adapter.c +236 -0
  244. data/src/core/tsi/transport_security_adapter.h +62 -0
  245. data/src/core/tsi/transport_security_interface.h +179 -66
  246. data/src/ruby/ext/grpc/extconf.rb +2 -1
  247. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  248. data/src/ruby/ext/grpc/rb_call.c +56 -48
  249. data/src/ruby/ext/grpc/rb_call.h +3 -4
  250. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  251. data/src/ruby/ext/grpc/rb_channel.c +2 -3
  252. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  253. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  254. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  255. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  256. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  257. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  258. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  259. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  260. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
  261. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
  262. data/src/ruby/ext/grpc/rb_server.c +26 -28
  263. data/src/ruby/lib/grpc/grpc.rb +1 -1
  264. data/src/ruby/lib/grpc/version.rb +1 -1
  265. data/third_party/cares/config_linux/ares_config.h +36 -2
  266. data/third_party/zlib/adler32.c +14 -7
  267. data/third_party/zlib/compress.c +24 -18
  268. data/third_party/zlib/crc32.c +29 -12
  269. data/third_party/zlib/deflate.c +499 -303
  270. data/third_party/zlib/deflate.h +19 -16
  271. data/third_party/zlib/gzguts.h +16 -7
  272. data/third_party/zlib/gzlib.c +17 -14
  273. data/third_party/zlib/gzread.c +108 -48
  274. data/third_party/zlib/gzwrite.c +210 -122
  275. data/third_party/zlib/infback.c +2 -2
  276. data/third_party/zlib/inffast.c +34 -51
  277. data/third_party/zlib/inflate.c +86 -37
  278. data/third_party/zlib/inflate.h +7 -4
  279. data/third_party/zlib/inftrees.c +12 -14
  280. data/third_party/zlib/trees.c +38 -61
  281. data/third_party/zlib/uncompr.c +66 -32
  282. data/third_party/zlib/zconf.h +32 -9
  283. data/third_party/zlib/zlib.h +298 -154
  284. data/third_party/zlib/zutil.c +25 -24
  285. data/third_party/zlib/zutil.h +35 -17
  286. metadata +63 -30
@@ -34,11 +34,12 @@
34
34
  #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H
35
35
  #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H
36
36
 
37
+ #include "src/core/lib/debug/trace.h"
37
38
  #include "src/core/lib/iomgr/endpoint.h"
38
39
  #include "src/core/lib/transport/transport.h"
39
40
 
40
- extern int grpc_http_trace;
41
- extern int grpc_flowctl_trace;
41
+ extern grpc_tracer_flag grpc_http_trace;
42
+ extern grpc_tracer_flag grpc_flowctl_trace;
42
43
 
43
44
  grpc_transport *grpc_create_chttp2_transport(
44
45
  grpc_exec_ctx *exec_ctx, const grpc_channel_args *channel_args,
@@ -40,6 +40,7 @@
40
40
  #include <grpc/support/string_util.h>
41
41
  #include <grpc/support/useful.h>
42
42
  #include "src/core/ext/transport/chttp2/transport/internal.h"
43
+ #include "src/core/lib/slice/slice_internal.h"
43
44
  #include "src/core/lib/slice/slice_string_helpers.h"
44
45
  #include "src/core/lib/support/string.h"
45
46
  #include "src/core/lib/transport/transport.h"
@@ -53,16 +54,17 @@ grpc_error *grpc_chttp2_data_parser_init(grpc_chttp2_data_parser *parser) {
53
54
  void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx,
54
55
  grpc_chttp2_data_parser *parser) {
55
56
  if (parser->parsing_frame != NULL) {
56
- grpc_chttp2_incoming_byte_stream_finished(
57
+ GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished(
57
58
  exec_ctx, parser->parsing_frame,
58
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"));
59
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"), false));
59
60
  }
60
61
  GRPC_ERROR_UNREF(parser->error);
61
62
  }
62
63
 
63
64
  grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser,
64
65
  uint8_t flags,
65
- uint32_t stream_id) {
66
+ uint32_t stream_id,
67
+ grpc_chttp2_stream *s) {
66
68
  if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) {
67
69
  char *msg;
68
70
  gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags);
@@ -74,47 +76,14 @@ grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser,
74
76
  }
75
77
 
76
78
  if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) {
77
- parser->is_last_frame = 1;
79
+ s->received_last_frame = true;
78
80
  } else {
79
- parser->is_last_frame = 0;
81
+ s->received_last_frame = false;
80
82
  }
81
83
 
82
84
  return GRPC_ERROR_NONE;
83
85
  }
84
86
 
85
- void grpc_chttp2_incoming_frame_queue_merge(
86
- grpc_chttp2_incoming_frame_queue *head_dst,
87
- grpc_chttp2_incoming_frame_queue *tail_src) {
88
- if (tail_src->head == NULL) {
89
- return;
90
- }
91
-
92
- if (head_dst->head == NULL) {
93
- *head_dst = *tail_src;
94
- memset(tail_src, 0, sizeof(*tail_src));
95
- return;
96
- }
97
-
98
- head_dst->tail->next_message = tail_src->head;
99
- head_dst->tail = tail_src->tail;
100
- memset(tail_src, 0, sizeof(*tail_src));
101
- }
102
-
103
- grpc_byte_stream *grpc_chttp2_incoming_frame_queue_pop(
104
- grpc_chttp2_incoming_frame_queue *q) {
105
- grpc_byte_stream *out;
106
- if (q->head == NULL) {
107
- return NULL;
108
- }
109
- out = &q->head->base;
110
- if (q->head == q->tail) {
111
- memset(q, 0, sizeof(*q));
112
- } else {
113
- q->head = q->head->next_message;
114
- }
115
- return out;
116
- }
117
-
118
87
  void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
119
88
  uint32_t write_bytes, int is_eof,
120
89
  grpc_transport_one_way_stats *stats,
@@ -123,7 +92,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
123
92
  uint8_t *p;
124
93
  static const size_t header_size = 9;
125
94
 
126
- hdr = grpc_slice_malloc(header_size);
95
+ hdr = GRPC_SLICE_MALLOC(header_size);
127
96
  p = GRPC_SLICE_START_PTR(hdr);
128
97
  GPR_ASSERT(write_bytes < (1 << 24));
129
98
  *p++ = (uint8_t)(write_bytes >> 16);
@@ -137,151 +106,221 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
137
106
  *p++ = (uint8_t)(id);
138
107
  grpc_slice_buffer_add(outbuf, hdr);
139
108
 
140
- grpc_slice_buffer_move_first(inbuf, write_bytes, outbuf);
109
+ grpc_slice_buffer_move_first_no_ref(inbuf, write_bytes, outbuf);
141
110
 
142
111
  stats->framing_bytes += header_size;
143
112
  stats->data_bytes += write_bytes;
144
113
  }
145
114
 
146
- static grpc_error *parse_inner(grpc_exec_ctx *exec_ctx,
147
- grpc_chttp2_data_parser *p,
148
- grpc_chttp2_transport *t, grpc_chttp2_stream *s,
149
- grpc_slice slice) {
150
- uint8_t *const beg = GRPC_SLICE_START_PTR(slice);
151
- uint8_t *const end = GRPC_SLICE_END_PTR(slice);
152
- uint8_t *cur = beg;
153
- uint32_t message_flags;
154
- grpc_chttp2_incoming_byte_stream *incoming_byte_stream;
155
- char *msg;
115
+ grpc_error *grpc_deframe_unprocessed_incoming_frames(
116
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_data_parser *p, grpc_chttp2_stream *s,
117
+ grpc_slice_buffer *slices, grpc_slice *slice_out,
118
+ grpc_byte_stream **stream_out) {
119
+ grpc_error *error = GRPC_ERROR_NONE;
120
+ grpc_chttp2_transport *t = s->t;
156
121
 
157
- if (cur == end) {
158
- return GRPC_ERROR_NONE;
159
- }
122
+ while (slices->count > 0) {
123
+ uint8_t *beg = NULL;
124
+ uint8_t *end = NULL;
125
+ uint8_t *cur = NULL;
160
126
 
161
- switch (p->state) {
162
- case GRPC_CHTTP2_DATA_ERROR:
163
- p->state = GRPC_CHTTP2_DATA_ERROR;
164
- return GRPC_ERROR_REF(p->error);
165
- fh_0:
166
- case GRPC_CHTTP2_DATA_FH_0:
167
- s->stats.incoming.framing_bytes++;
168
- p->frame_type = *cur;
169
- switch (p->frame_type) {
170
- case 0:
171
- p->is_frame_compressed = 0; /* GPR_FALSE */
172
- break;
173
- case 1:
174
- p->is_frame_compressed = 1; /* GPR_TRUE */
175
- break;
176
- default:
177
- gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type);
178
- p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
179
- p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
180
- (intptr_t)s->id);
181
- gpr_free(msg);
182
- msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
183
- p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
184
- grpc_slice_from_copied_string(msg));
185
- gpr_free(msg);
186
- p->error =
187
- grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
188
- p->state = GRPC_CHTTP2_DATA_ERROR;
189
- return GRPC_ERROR_REF(p->error);
190
- }
191
- if (++cur == end) {
192
- p->state = GRPC_CHTTP2_DATA_FH_1;
193
- return GRPC_ERROR_NONE;
194
- }
195
- /* fallthrough */
196
- case GRPC_CHTTP2_DATA_FH_1:
197
- s->stats.incoming.framing_bytes++;
198
- p->frame_size = ((uint32_t)*cur) << 24;
199
- if (++cur == end) {
200
- p->state = GRPC_CHTTP2_DATA_FH_2;
201
- return GRPC_ERROR_NONE;
202
- }
203
- /* fallthrough */
204
- case GRPC_CHTTP2_DATA_FH_2:
205
- s->stats.incoming.framing_bytes++;
206
- p->frame_size |= ((uint32_t)*cur) << 16;
207
- if (++cur == end) {
208
- p->state = GRPC_CHTTP2_DATA_FH_3;
209
- return GRPC_ERROR_NONE;
210
- }
211
- /* fallthrough */
212
- case GRPC_CHTTP2_DATA_FH_3:
213
- s->stats.incoming.framing_bytes++;
214
- p->frame_size |= ((uint32_t)*cur) << 8;
215
- if (++cur == end) {
216
- p->state = GRPC_CHTTP2_DATA_FH_4;
217
- return GRPC_ERROR_NONE;
218
- }
219
- /* fallthrough */
220
- case GRPC_CHTTP2_DATA_FH_4:
221
- s->stats.incoming.framing_bytes++;
222
- p->frame_size |= ((uint32_t)*cur);
223
- p->state = GRPC_CHTTP2_DATA_FRAME;
224
- ++cur;
225
- message_flags = 0;
226
- if (p->is_frame_compressed) {
227
- message_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
228
- }
229
- p->parsing_frame = incoming_byte_stream =
230
- grpc_chttp2_incoming_byte_stream_create(exec_ctx, t, s, p->frame_size,
231
- message_flags);
232
- /* fallthrough */
233
- case GRPC_CHTTP2_DATA_FRAME:
234
- if (cur == end) {
235
- return GRPC_ERROR_NONE;
236
- }
237
- uint32_t remaining = (uint32_t)(end - cur);
238
- if (remaining == p->frame_size) {
239
- s->stats.incoming.data_bytes += p->frame_size;
240
- grpc_chttp2_incoming_byte_stream_push(
241
- exec_ctx, p->parsing_frame,
242
- grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
243
- grpc_chttp2_incoming_byte_stream_finished(exec_ctx, p->parsing_frame,
244
- GRPC_ERROR_NONE);
245
- p->parsing_frame = NULL;
246
- p->state = GRPC_CHTTP2_DATA_FH_0;
247
- return GRPC_ERROR_NONE;
248
- } else if (remaining > p->frame_size) {
249
- s->stats.incoming.data_bytes += p->frame_size;
250
- grpc_chttp2_incoming_byte_stream_push(
251
- exec_ctx, p->parsing_frame,
252
- grpc_slice_sub(slice, (size_t)(cur - beg),
253
- (size_t)(cur + p->frame_size - beg)));
254
- grpc_chttp2_incoming_byte_stream_finished(exec_ctx, p->parsing_frame,
255
- GRPC_ERROR_NONE);
256
- p->parsing_frame = NULL;
257
- cur += p->frame_size;
258
- goto fh_0; /* loop */
259
- } else {
260
- GPR_ASSERT(remaining <= p->frame_size);
261
- grpc_chttp2_incoming_byte_stream_push(
262
- exec_ctx, p->parsing_frame,
263
- grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
264
- p->frame_size -= remaining;
265
- s->stats.incoming.data_bytes += remaining;
127
+ grpc_slice slice = grpc_slice_buffer_take_first(slices);
128
+
129
+ beg = GRPC_SLICE_START_PTR(slice);
130
+ end = GRPC_SLICE_END_PTR(slice);
131
+ cur = beg;
132
+ uint32_t message_flags;
133
+ char *msg;
134
+
135
+ if (cur == end) {
136
+ grpc_slice_unref_internal(exec_ctx, slice);
137
+ continue;
138
+ }
139
+
140
+ switch (p->state) {
141
+ case GRPC_CHTTP2_DATA_ERROR:
142
+ p->state = GRPC_CHTTP2_DATA_ERROR;
143
+ grpc_slice_unref_internal(exec_ctx, slice);
144
+ return GRPC_ERROR_REF(p->error);
145
+ case GRPC_CHTTP2_DATA_FH_0:
146
+ p->frame_type = *cur;
147
+ switch (p->frame_type) {
148
+ case 0:
149
+ p->is_frame_compressed = false; /* GPR_FALSE */
150
+ break;
151
+ case 1:
152
+ p->is_frame_compressed = true; /* GPR_TRUE */
153
+ break;
154
+ default:
155
+ gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type);
156
+ p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
157
+ p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
158
+ (intptr_t)s->id);
159
+ gpr_free(msg);
160
+ msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
161
+ p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
162
+ grpc_slice_from_copied_string(msg));
163
+ gpr_free(msg);
164
+ p->error =
165
+ grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
166
+ p->state = GRPC_CHTTP2_DATA_ERROR;
167
+ grpc_slice_unref_internal(exec_ctx, slice);
168
+ return GRPC_ERROR_REF(p->error);
169
+ }
170
+ if (++cur == end) {
171
+ p->state = GRPC_CHTTP2_DATA_FH_1;
172
+ grpc_slice_unref_internal(exec_ctx, slice);
173
+ continue;
174
+ }
175
+ /* fallthrough */
176
+ case GRPC_CHTTP2_DATA_FH_1:
177
+ p->frame_size = ((uint32_t)*cur) << 24;
178
+ if (++cur == end) {
179
+ p->state = GRPC_CHTTP2_DATA_FH_2;
180
+ grpc_slice_unref_internal(exec_ctx, slice);
181
+ continue;
182
+ }
183
+ /* fallthrough */
184
+ case GRPC_CHTTP2_DATA_FH_2:
185
+ p->frame_size |= ((uint32_t)*cur) << 16;
186
+ if (++cur == end) {
187
+ p->state = GRPC_CHTTP2_DATA_FH_3;
188
+ grpc_slice_unref_internal(exec_ctx, slice);
189
+ continue;
190
+ }
191
+ /* fallthrough */
192
+ case GRPC_CHTTP2_DATA_FH_3:
193
+ p->frame_size |= ((uint32_t)*cur) << 8;
194
+ if (++cur == end) {
195
+ p->state = GRPC_CHTTP2_DATA_FH_4;
196
+ grpc_slice_unref_internal(exec_ctx, slice);
197
+ continue;
198
+ }
199
+ /* fallthrough */
200
+ case GRPC_CHTTP2_DATA_FH_4:
201
+ GPR_ASSERT(stream_out != NULL);
202
+ GPR_ASSERT(p->parsing_frame == NULL);
203
+ p->frame_size |= ((uint32_t)*cur);
204
+ p->state = GRPC_CHTTP2_DATA_FRAME;
205
+ ++cur;
206
+ message_flags = 0;
207
+ if (p->is_frame_compressed) {
208
+ message_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
209
+ }
210
+ p->parsing_frame = grpc_chttp2_incoming_byte_stream_create(
211
+ exec_ctx, t, s, p->frame_size, message_flags);
212
+ *stream_out = &p->parsing_frame->base;
213
+ if (p->parsing_frame->remaining_bytes == 0) {
214
+ GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished(
215
+ exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true));
216
+ p->parsing_frame = NULL;
217
+ p->state = GRPC_CHTTP2_DATA_FH_0;
218
+ }
219
+ s->pending_byte_stream = true;
220
+
221
+ if (cur != end) {
222
+ grpc_slice_buffer_undo_take_first(
223
+ &s->unprocessed_incoming_frames_buffer,
224
+ grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
225
+ }
226
+ grpc_slice_unref_internal(exec_ctx, slice);
266
227
  return GRPC_ERROR_NONE;
228
+ case GRPC_CHTTP2_DATA_FRAME: {
229
+ GPR_ASSERT(p->parsing_frame != NULL);
230
+ GPR_ASSERT(slice_out != NULL);
231
+ if (cur == end) {
232
+ grpc_slice_unref_internal(exec_ctx, slice);
233
+ continue;
234
+ }
235
+ uint32_t remaining = (uint32_t)(end - cur);
236
+ if (remaining == p->frame_size) {
237
+ if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push(
238
+ exec_ctx, p->parsing_frame,
239
+ grpc_slice_sub(slice, (size_t)(cur - beg),
240
+ (size_t)(end - beg)),
241
+ slice_out))) {
242
+ grpc_slice_unref_internal(exec_ctx, slice);
243
+ return error;
244
+ }
245
+ if (GRPC_ERROR_NONE !=
246
+ (error = grpc_chttp2_incoming_byte_stream_finished(
247
+ exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) {
248
+ grpc_slice_unref_internal(exec_ctx, slice);
249
+ return error;
250
+ }
251
+ p->parsing_frame = NULL;
252
+ p->state = GRPC_CHTTP2_DATA_FH_0;
253
+ grpc_slice_unref_internal(exec_ctx, slice);
254
+ return GRPC_ERROR_NONE;
255
+ } else if (remaining < p->frame_size) {
256
+ if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push(
257
+ exec_ctx, p->parsing_frame,
258
+ grpc_slice_sub(slice, (size_t)(cur - beg),
259
+ (size_t)(end - beg)),
260
+ slice_out))) {
261
+ return error;
262
+ }
263
+ p->frame_size -= remaining;
264
+ grpc_slice_unref_internal(exec_ctx, slice);
265
+ return GRPC_ERROR_NONE;
266
+ } else {
267
+ GPR_ASSERT(remaining > p->frame_size);
268
+ if (GRPC_ERROR_NONE !=
269
+ (grpc_chttp2_incoming_byte_stream_push(
270
+ exec_ctx, p->parsing_frame,
271
+ grpc_slice_sub(slice, (size_t)(cur - beg),
272
+ (size_t)(cur + p->frame_size - beg)),
273
+ slice_out))) {
274
+ grpc_slice_unref_internal(exec_ctx, slice);
275
+ return error;
276
+ }
277
+ if (GRPC_ERROR_NONE !=
278
+ (error = grpc_chttp2_incoming_byte_stream_finished(
279
+ exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true))) {
280
+ grpc_slice_unref_internal(exec_ctx, slice);
281
+ return error;
282
+ }
283
+ p->parsing_frame = NULL;
284
+ p->state = GRPC_CHTTP2_DATA_FH_0;
285
+ cur += p->frame_size;
286
+ grpc_slice_buffer_undo_take_first(
287
+ &s->unprocessed_incoming_frames_buffer,
288
+ grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
289
+ grpc_slice_unref_internal(exec_ctx, slice);
290
+ return GRPC_ERROR_NONE;
291
+ }
267
292
  }
293
+ }
268
294
  }
269
295
 
270
- GPR_UNREACHABLE_CODE(
271
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
296
+ return GRPC_ERROR_NONE;
272
297
  }
273
298
 
274
299
  grpc_error *grpc_chttp2_data_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
275
300
  grpc_chttp2_transport *t,
276
301
  grpc_chttp2_stream *s,
277
302
  grpc_slice slice, int is_last) {
278
- grpc_chttp2_data_parser *p = parser;
279
- grpc_error *error = parse_inner(exec_ctx, p, t, s, slice);
303
+ /* grpc_error *error = parse_inner_buffer(exec_ctx, p, t, s, slice); */
304
+ s->stats.incoming.framing_bytes += GRPC_SLICE_LENGTH(slice);
305
+ if (!s->pending_byte_stream) {
306
+ grpc_slice_ref_internal(slice);
307
+ grpc_slice_buffer_add(&s->frame_storage, slice);
308
+ grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
309
+ } else if (s->on_next) {
310
+ GPR_ASSERT(s->frame_storage.length == 0);
311
+ grpc_slice_ref_internal(slice);
312
+ grpc_slice_buffer_add(&s->unprocessed_incoming_frames_buffer, slice);
313
+ grpc_closure_sched(exec_ctx, s->on_next, GRPC_ERROR_NONE);
314
+ s->on_next = NULL;
315
+ } else {
316
+ grpc_slice_ref_internal(slice);
317
+ grpc_slice_buffer_add(&s->frame_storage, slice);
318
+ }
280
319
 
281
- if (is_last && p->is_last_frame) {
320
+ if (is_last && s->received_last_frame) {
282
321
  grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false,
283
322
  GRPC_ERROR_NONE);
284
323
  }
285
324
 
286
- return error;
325
+ return GRPC_ERROR_NONE;
287
326
  }
@@ -56,28 +56,16 @@ typedef enum {
56
56
  typedef struct grpc_chttp2_incoming_byte_stream
57
57
  grpc_chttp2_incoming_byte_stream;
58
58
 
59
- typedef struct grpc_chttp2_incoming_frame_queue {
60
- grpc_chttp2_incoming_byte_stream *head;
61
- grpc_chttp2_incoming_byte_stream *tail;
62
- } grpc_chttp2_incoming_frame_queue;
63
-
64
59
  typedef struct {
65
60
  grpc_chttp2_stream_state state;
66
- uint8_t is_last_frame;
67
61
  uint8_t frame_type;
68
62
  uint32_t frame_size;
69
63
  grpc_error *error;
70
64
 
71
- int is_frame_compressed;
65
+ bool is_frame_compressed;
72
66
  grpc_chttp2_incoming_byte_stream *parsing_frame;
73
67
  } grpc_chttp2_data_parser;
74
68
 
75
- void grpc_chttp2_incoming_frame_queue_merge(
76
- grpc_chttp2_incoming_frame_queue *head_dst,
77
- grpc_chttp2_incoming_frame_queue *tail_src);
78
- grpc_byte_stream *grpc_chttp2_incoming_frame_queue_pop(
79
- grpc_chttp2_incoming_frame_queue *q);
80
-
81
69
  /* initialize per-stream state for data frame parsing */
82
70
  grpc_error *grpc_chttp2_data_parser_init(grpc_chttp2_data_parser *parser);
83
71
 
@@ -87,7 +75,8 @@ void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx,
87
75
  /* start processing a new data frame */
88
76
  grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser,
89
77
  uint8_t flags,
90
- uint32_t stream_id);
78
+ uint32_t stream_id,
79
+ grpc_chttp2_stream *s);
91
80
 
92
81
  /* handle a slice of a data frame - is_last indicates the last slice of a
93
82
  frame */
@@ -101,4 +90,9 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
101
90
  grpc_transport_one_way_stats *stats,
102
91
  grpc_slice_buffer *outbuf);
103
92
 
93
+ grpc_error *grpc_deframe_unprocessed_incoming_frames(
94
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_data_parser *p, grpc_chttp2_stream *s,
95
+ grpc_slice_buffer *slices, grpc_slice *slice_out,
96
+ grpc_byte_stream **stream_out);
97
+
104
98
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_DATA_H */