grpc 1.1.2 → 1.2.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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -31,51 +31,51 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/ext/transport/chttp2/transport/status_conversion.h"
34
+ #include "src/core/lib/transport/status_conversion.h"
35
35
 
36
- int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) {
36
+ int grpc_status_to_http2_error(grpc_status_code status) {
37
37
  switch (status) {
38
38
  case GRPC_STATUS_OK:
39
- return GRPC_CHTTP2_NO_ERROR;
39
+ return GRPC_HTTP2_NO_ERROR;
40
40
  case GRPC_STATUS_CANCELLED:
41
- return GRPC_CHTTP2_CANCEL;
41
+ return GRPC_HTTP2_CANCEL;
42
42
  case GRPC_STATUS_DEADLINE_EXCEEDED:
43
- return GRPC_CHTTP2_CANCEL;
43
+ return GRPC_HTTP2_CANCEL;
44
44
  case GRPC_STATUS_RESOURCE_EXHAUSTED:
45
- return GRPC_CHTTP2_ENHANCE_YOUR_CALM;
45
+ return GRPC_HTTP2_ENHANCE_YOUR_CALM;
46
46
  case GRPC_STATUS_PERMISSION_DENIED:
47
- return GRPC_CHTTP2_INADEQUATE_SECURITY;
47
+ return GRPC_HTTP2_INADEQUATE_SECURITY;
48
48
  case GRPC_STATUS_UNAVAILABLE:
49
- return GRPC_CHTTP2_REFUSED_STREAM;
49
+ return GRPC_HTTP2_REFUSED_STREAM;
50
50
  default:
51
- return GRPC_CHTTP2_INTERNAL_ERROR;
51
+ return GRPC_HTTP2_INTERNAL_ERROR;
52
52
  }
53
53
  }
54
54
 
55
- grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
56
- grpc_chttp2_error_code error, gpr_timespec deadline) {
55
+ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error,
56
+ gpr_timespec deadline) {
57
57
  switch (error) {
58
- case GRPC_CHTTP2_NO_ERROR:
58
+ case GRPC_HTTP2_NO_ERROR:
59
59
  /* should never be received */
60
60
  return GRPC_STATUS_INTERNAL;
61
- case GRPC_CHTTP2_CANCEL:
61
+ case GRPC_HTTP2_CANCEL:
62
62
  /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been
63
63
  * exceeded */
64
64
  return gpr_time_cmp(gpr_now(deadline.clock_type), deadline) >= 0
65
65
  ? GRPC_STATUS_DEADLINE_EXCEEDED
66
66
  : GRPC_STATUS_CANCELLED;
67
- case GRPC_CHTTP2_ENHANCE_YOUR_CALM:
67
+ case GRPC_HTTP2_ENHANCE_YOUR_CALM:
68
68
  return GRPC_STATUS_RESOURCE_EXHAUSTED;
69
- case GRPC_CHTTP2_INADEQUATE_SECURITY:
69
+ case GRPC_HTTP2_INADEQUATE_SECURITY:
70
70
  return GRPC_STATUS_PERMISSION_DENIED;
71
- case GRPC_CHTTP2_REFUSED_STREAM:
71
+ case GRPC_HTTP2_REFUSED_STREAM:
72
72
  return GRPC_STATUS_UNAVAILABLE;
73
73
  default:
74
74
  return GRPC_STATUS_INTERNAL;
75
75
  }
76
76
  }
77
77
 
78
- grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
78
+ grpc_status_code grpc_http2_status_to_grpc_status(int status) {
79
79
  switch (status) {
80
80
  /* these HTTP2 status codes are called out explicitly in status.proto */
81
81
  case 200:
@@ -110,6 +110,4 @@ grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
110
110
  }
111
111
  }
112
112
 
113
- int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) {
114
- return 200;
115
- }
113
+ int grpc_status_to_http2_status(grpc_status_code status) { return 200; }
@@ -31,20 +31,19 @@
31
31
  *
32
32
  */
33
33
 
34
- #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H
35
- #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H
34
+ #ifndef GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H
35
+ #define GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H
36
36
 
37
37
  #include <grpc/grpc.h>
38
- #include "src/core/ext/transport/chttp2/transport/http2_errors.h"
38
+ #include "src/core/lib/transport/http2_errors.h"
39
39
 
40
40
  /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */
41
- grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error(
42
- grpc_status_code status);
43
- grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
44
- grpc_chttp2_error_code error, gpr_timespec deadline);
41
+ grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status);
42
+ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error,
43
+ gpr_timespec deadline);
45
44
 
46
45
  /* Conversion of HTTP status codes (:status) to grpc status codes */
47
- grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status);
48
- int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status);
46
+ grpc_status_code grpc_http2_status_to_grpc_status(int status);
47
+ int grpc_status_to_http2_status(grpc_status_code status);
49
48
 
50
- #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H */
49
+ #endif /* GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H */
@@ -131,20 +131,21 @@ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer) {
131
131
  }
132
132
  }
133
133
 
134
- static int is_all_whitespace(const char *p) {
135
- while (*p == ' ') p++;
136
- return *p == 0;
134
+ static int is_all_whitespace(const char *p, const char *end) {
135
+ while (p != end && *p == ' ') p++;
136
+ return p == end;
137
137
  }
138
138
 
139
- int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
139
+ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) {
140
140
  int32_t x = 0;
141
- const uint8_t *p = (const uint8_t *)buffer;
141
+ const uint8_t *p = GRPC_SLICE_START_PTR(text);
142
+ const uint8_t *end = GRPC_SLICE_END_PTR(text);
142
143
  int have_digit = 0;
143
144
  /* skip whitespace */
144
- for (; *p == ' '; p++)
145
+ for (; p != end && *p == ' '; p++)
145
146
  ;
146
147
  /* decode numeric part */
147
- for (; *p >= '0' && *p <= '9'; p++) {
148
+ for (; p != end && *p >= '0' && *p <= '9'; p++) {
148
149
  int32_t digit = (int32_t)(*p - (uint8_t)'0');
149
150
  have_digit = 1;
150
151
  /* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */
@@ -158,8 +159,9 @@ int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
158
159
  }
159
160
  if (!have_digit) return 0;
160
161
  /* skip whitespace */
161
- for (; *p == ' '; p++)
162
+ for (; p != end && *p == ' '; p++)
162
163
  ;
164
+ if (p == end) return 0;
163
165
  /* decode unit specifier */
164
166
  switch (*p) {
165
167
  case 'n':
@@ -184,5 +186,5 @@ int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
184
186
  return 0;
185
187
  }
186
188
  p++;
187
- return is_all_whitespace((const char *)p);
189
+ return is_all_whitespace((const char *)p, (const char *)end);
188
190
  }
@@ -34,7 +34,9 @@
34
34
  #ifndef GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H
35
35
  #define GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H
36
36
 
37
+ #include <grpc/slice.h>
37
38
  #include <grpc/support/time.h>
39
+
38
40
  #include "src/core/lib/support/string.h"
39
41
 
40
42
  #define GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1)
@@ -42,6 +44,6 @@
42
44
  /* Encode/decode timeouts to the GRPC over HTTP/2 format;
43
45
  encoding may round up arbitrarily */
44
46
  void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer);
45
- int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout);
47
+ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout);
46
48
 
47
49
  #endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */
@@ -40,6 +40,7 @@
40
40
  #include <grpc/support/log.h>
41
41
  #include <grpc/support/sync.h>
42
42
 
43
+ #include "src/core/lib/iomgr/executor.h"
43
44
  #include "src/core/lib/slice/slice_internal.h"
44
45
  #include "src/core/lib/slice/slice_string_helpers.h"
45
46
  #include "src/core/lib/support/string.h"
@@ -69,10 +70,53 @@ void grpc_stream_unref(grpc_exec_ctx *exec_ctx,
69
70
  grpc_stream_refcount *refcount) {
70
71
  #endif
71
72
  if (gpr_unref(&refcount->refs)) {
73
+ if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) {
74
+ /* Ick.
75
+ The thread we're running on MAY be owned (indirectly) by a call-stack.
76
+ If that's the case, destroying the call-stack MAY try to destroy the
77
+ thread, which is a tangled mess that we just don't want to ever have to
78
+ cope with.
79
+ Throw this over to the executor (on a core-owned thread) and process it
80
+ there. */
81
+ refcount->destroy.scheduler = grpc_executor_scheduler;
82
+ }
72
83
  grpc_closure_sched(exec_ctx, &refcount->destroy, GRPC_ERROR_NONE);
73
84
  }
74
85
  }
75
86
 
87
+ #define STREAM_REF_FROM_SLICE_REF(p) \
88
+ ((grpc_stream_refcount *)(((uint8_t *)p) - \
89
+ offsetof(grpc_stream_refcount, slice_refcount)))
90
+
91
+ static void slice_stream_ref(void *p) {
92
+ #ifdef GRPC_STREAM_REFCOUNT_DEBUG
93
+ grpc_stream_ref(STREAM_REF_FROM_SLICE_REF(p), "slice");
94
+ #else
95
+ grpc_stream_ref(STREAM_REF_FROM_SLICE_REF(p));
96
+ #endif
97
+ }
98
+
99
+ static void slice_stream_unref(grpc_exec_ctx *exec_ctx, void *p) {
100
+ #ifdef GRPC_STREAM_REFCOUNT_DEBUG
101
+ grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p), "slice");
102
+ #else
103
+ grpc_stream_unref(exec_ctx, STREAM_REF_FROM_SLICE_REF(p));
104
+ #endif
105
+ }
106
+
107
+ grpc_slice grpc_slice_from_stream_owned_buffer(grpc_stream_refcount *refcount,
108
+ void *buffer, size_t length) {
109
+ slice_stream_ref(&refcount->slice_refcount);
110
+ return (grpc_slice){.refcount = &refcount->slice_refcount,
111
+ .data.refcounted = {.bytes = buffer, .length = length}};
112
+ }
113
+
114
+ static const grpc_slice_refcount_vtable stream_ref_slice_vtable = {
115
+ .ref = slice_stream_ref,
116
+ .unref = slice_stream_unref,
117
+ .eq = grpc_slice_default_eq_impl,
118
+ .hash = grpc_slice_default_hash_impl};
119
+
76
120
  #ifdef GRPC_STREAM_REFCOUNT_DEBUG
77
121
  void grpc_stream_ref_init(grpc_stream_refcount *refcount, int initial_refs,
78
122
  grpc_iomgr_cb_func cb, void *cb_arg,
@@ -84,6 +128,8 @@ void grpc_stream_ref_init(grpc_stream_refcount *refcount, int initial_refs,
84
128
  #endif
85
129
  gpr_ref_init(&refcount->refs, initial_refs);
86
130
  grpc_closure_init(&refcount->destroy, cb, cb_arg, grpc_schedule_on_exec_ctx);
131
+ refcount->slice_refcount.vtable = &stream_ref_slice_vtable;
132
+ refcount->slice_refcount.sub_refcount = &refcount->slice_refcount;
87
133
  }
88
134
 
89
135
  static void move64(uint64_t *from, uint64_t *to) {
@@ -173,93 +219,7 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx,
173
219
  grpc_closure_sched(exec_ctx, op->recv_initial_metadata_ready,
174
220
  GRPC_ERROR_REF(error));
175
221
  grpc_closure_sched(exec_ctx, op->on_complete, error);
176
- }
177
-
178
- typedef struct {
179
- grpc_error *error;
180
- grpc_closure *then_call;
181
- grpc_closure closure;
182
- } close_message_data;
183
-
184
- static void free_message(grpc_exec_ctx *exec_ctx, void *p, grpc_error *error) {
185
- close_message_data *cmd = p;
186
- GRPC_ERROR_UNREF(cmd->error);
187
- if (cmd->then_call != NULL) {
188
- cmd->then_call->cb(exec_ctx, cmd->then_call->cb_arg, error);
189
- }
190
- gpr_free(cmd);
191
- }
192
-
193
- static void add_error(grpc_transport_stream_op *op, grpc_error **which,
194
- grpc_error *error) {
195
- close_message_data *cmd;
196
- cmd = gpr_malloc(sizeof(*cmd));
197
- cmd->error = error;
198
- cmd->then_call = op->on_complete;
199
- grpc_closure_init(&cmd->closure, free_message, cmd,
200
- grpc_schedule_on_exec_ctx);
201
- op->on_complete = &cmd->closure;
202
- *which = error;
203
- }
204
-
205
- void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
206
- grpc_status_code status) {
207
- GPR_ASSERT(status != GRPC_STATUS_OK);
208
- if (op->cancel_error == GRPC_ERROR_NONE) {
209
- op->cancel_error = grpc_error_set_int(GRPC_ERROR_CANCELLED,
210
- GRPC_ERROR_INT_GRPC_STATUS, status);
211
- op->close_error = GRPC_ERROR_NONE;
212
- }
213
- }
214
-
215
- void grpc_transport_stream_op_add_cancellation_with_message(
216
- grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op,
217
- grpc_status_code status, grpc_slice *optional_message) {
218
- GPR_ASSERT(status != GRPC_STATUS_OK);
219
- if (op->cancel_error != GRPC_ERROR_NONE) {
220
- if (optional_message) {
221
- grpc_slice_unref_internal(exec_ctx, *optional_message);
222
- }
223
- return;
224
- }
225
- grpc_error *error;
226
- if (optional_message != NULL) {
227
- char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII);
228
- error = grpc_error_set_str(GRPC_ERROR_CREATE(msg),
229
- GRPC_ERROR_STR_GRPC_MESSAGE, msg);
230
- gpr_free(msg);
231
- grpc_slice_unref_internal(exec_ctx, *optional_message);
232
- } else {
233
- error = GRPC_ERROR_CREATE("Call cancelled");
234
- }
235
- error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status);
236
- add_error(op, &op->cancel_error, error);
237
- }
238
-
239
- void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx,
240
- grpc_transport_stream_op *op,
241
- grpc_status_code status,
242
- grpc_slice *optional_message) {
243
- GPR_ASSERT(status != GRPC_STATUS_OK);
244
- if (op->cancel_error != GRPC_ERROR_NONE ||
245
- op->close_error != GRPC_ERROR_NONE) {
246
- if (optional_message) {
247
- grpc_slice_unref_internal(exec_ctx, *optional_message);
248
- }
249
- return;
250
- }
251
- grpc_error *error;
252
- if (optional_message != NULL) {
253
- char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII);
254
- error = grpc_error_set_str(GRPC_ERROR_CREATE(msg),
255
- GRPC_ERROR_STR_GRPC_MESSAGE, msg);
256
- gpr_free(msg);
257
- grpc_slice_unref_internal(exec_ctx, *optional_message);
258
- } else {
259
- error = GRPC_ERROR_CREATE("Call force closed");
260
- }
261
- error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status);
262
- add_error(op, &op->close_error, error);
222
+ GRPC_ERROR_UNREF(op->cancel_error);
263
223
  }
264
224
 
265
225
  typedef struct {
@@ -64,6 +64,7 @@ typedef struct grpc_stream_refcount {
64
64
  #ifdef GRPC_STREAM_REFCOUNT_DEBUG
65
65
  const char *object_type;
66
66
  #endif
67
+ grpc_slice_refcount slice_refcount;
67
68
  } grpc_stream_refcount;
68
69
 
69
70
  #ifdef GRPC_STREAM_REFCOUNT_DEBUG
@@ -84,6 +85,11 @@ void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount);
84
85
  grpc_stream_ref_init(rc, ir, cb, cb_arg)
85
86
  #endif
86
87
 
88
+ /* Wrap a buffer that is owned by some stream object into a slice that shares
89
+ the same refcount */
90
+ grpc_slice grpc_slice_from_stream_owned_buffer(grpc_stream_refcount *refcount,
91
+ void *buffer, size_t length);
92
+
87
93
  typedef struct {
88
94
  uint64_t framing_bytes;
89
95
  uint64_t data_bytes;
@@ -150,21 +156,26 @@ typedef struct grpc_transport_stream_op {
150
156
  /** Collect any stats into provided buffer, zero internal stat counters */
151
157
  grpc_transport_stream_stats *collect_stats;
152
158
 
153
- /** If != GRPC_ERROR_NONE, cancel this stream */
159
+ /** If != GRPC_ERROR_NONE, forcefully close this stream.
160
+ The HTTP2 semantics should be:
161
+ - server side: if cancel_error has GRPC_ERROR_INT_GRPC_STATUS, and
162
+ trailing metadata has not been sent, send trailing metadata with status
163
+ and message from cancel_error (use grpc_error_get_status) followed by
164
+ a RST_STREAM with error=GRPC_CHTTP2_NO_ERROR to force a full close
165
+ - at all other times: use grpc_error_get_status to get a status code, and
166
+ convert to a HTTP2 error code using
167
+ grpc_chttp2_grpc_status_to_http2_error. Send a RST_STREAM with this
168
+ error. */
154
169
  grpc_error *cancel_error;
155
170
 
156
- /** If != GRPC_ERROR_NONE, send grpc-status, grpc-message, and close this
157
- stream for both reading and writing */
158
- grpc_error *close_error;
159
-
160
171
  /* Indexes correspond to grpc_context_index enum values */
161
172
  grpc_call_context_element *context;
162
173
 
163
174
  /***************************************************************************
164
175
  * remaining fields are initialized and used at the discretion of the
165
- * transport implementation */
176
+ * current handler of the op */
166
177
 
167
- grpc_transport_private_op_data transport_private;
178
+ grpc_transport_private_op_data handler_private;
168
179
  } grpc_transport_stream_op;
169
180
 
170
181
  /** Transport op: a set of operations to perform on a transport as a whole */
@@ -176,13 +187,8 @@ typedef struct grpc_transport_op {
176
187
  grpc_connectivity_state *connectivity_state;
177
188
  /** should the transport be disconnected */
178
189
  grpc_error *disconnect_with_error;
179
- /** should we send a goaway?
180
- after a goaway is sent, once there are no more active calls on
181
- the transport, the transport should disconnect */
182
- bool send_goaway;
183
190
  /** what should the goaway contain? */
184
- grpc_status_code goaway_status;
185
- grpc_slice *goaway_message;
191
+ grpc_error *goaway_error;
186
192
  /** set the callback for accepting new streams;
187
193
  this is a permanent callback, unlike the other one-shot closures.
188
194
  If true, the callback is set to set_accept_stream_fn, with its
@@ -213,6 +219,7 @@ size_t grpc_transport_stream_size(grpc_transport *transport);
213
219
  /* Initialize transport data for a stream.
214
220
 
215
221
  Returns 0 on success, any other (transport-defined) value for failure.
222
+ May assume that stream contains all-zeros.
216
223
 
217
224
  Arguments:
218
225
  transport - the transport on which to create this stream
@@ -245,18 +252,6 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx,
245
252
  grpc_transport_stream_op *op,
246
253
  grpc_error *error);
247
254
 
248
- void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
249
- grpc_status_code status);
250
-
251
- void grpc_transport_stream_op_add_cancellation_with_message(
252
- grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op,
253
- grpc_status_code status, grpc_slice *optional_message);
254
-
255
- void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx,
256
- grpc_transport_stream_op *op,
257
- grpc_status_code status,
258
- grpc_slice *optional_message);
259
-
260
255
  char *grpc_transport_stream_op_string(grpc_transport_stream_op *op);
261
256
  char *grpc_transport_op_string(grpc_transport_op *op);
262
257
 
@@ -47,14 +47,14 @@
47
47
  /* These routines are here to facilitate debugging - they produce string
48
48
  representations of various transport data structures */
49
49
 
50
- static void put_metadata(gpr_strvec *b, grpc_mdelem *md) {
50
+ static void put_metadata(gpr_strvec *b, grpc_mdelem md) {
51
51
  gpr_strvec_add(b, gpr_strdup("key="));
52
52
  gpr_strvec_add(
53
- b, grpc_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
53
+ b, grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_HEX | GPR_DUMP_ASCII));
54
54
 
55
55
  gpr_strvec_add(b, gpr_strdup(" value="));
56
56
  gpr_strvec_add(
57
- b, grpc_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
57
+ b, grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII));
58
58
  }
59
59
 
60
60
  static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) {
@@ -121,15 +121,7 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) {
121
121
  gpr_strvec_add(&b, gpr_strdup(" "));
122
122
  const char *msg = grpc_error_string(op->cancel_error);
123
123
  gpr_asprintf(&tmp, "CANCEL:%s", msg);
124
- grpc_error_free_string(msg);
125
- gpr_strvec_add(&b, tmp);
126
- }
127
124
 
128
- if (op->close_error != GRPC_ERROR_NONE) {
129
- gpr_strvec_add(&b, gpr_strdup(" "));
130
- const char *msg = grpc_error_string(op->close_error);
131
- gpr_asprintf(&tmp, "CLOSE:%s", msg);
132
- grpc_error_free_string(msg);
133
125
  gpr_strvec_add(&b, tmp);
134
126
  }
135
127
 
@@ -168,18 +160,14 @@ char *grpc_transport_op_string(grpc_transport_op *op) {
168
160
  const char *err = grpc_error_string(op->disconnect_with_error);
169
161
  gpr_asprintf(&tmp, "DISCONNECT:%s", err);
170
162
  gpr_strvec_add(&b, tmp);
171
- grpc_error_free_string(err);
172
163
  }
173
164
 
174
- if (op->send_goaway) {
165
+ if (op->goaway_error) {
175
166
  if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
176
167
  first = false;
177
- char *msg = op->goaway_message == NULL
178
- ? "null"
179
- : grpc_dump_slice(*op->goaway_message,
180
- GPR_DUMP_ASCII | GPR_DUMP_HEX);
181
- gpr_asprintf(&tmp, "SEND_GOAWAY:status=%d:msg=%s", op->goaway_status, msg);
182
- if (op->goaway_message != NULL) gpr_free(msg);
168
+ const char *msg = grpc_error_string(op->goaway_error);
169
+ gpr_asprintf(&tmp, "SEND_GOAWAY:%s", msg);
170
+
183
171
  gpr_strvec_add(&b, tmp);
184
172
  }
185
173