Craig Tiller | 640d3bd | 2015-06-12 07:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 34 | #ifndef GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H |
| 35 | #define GRPC_INTERNAL_CORE_CHTTP2_INTERNAL_H |
| 36 | |
| 37 | #include "src/core/transport/transport_impl.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 38 | #include "src/core/iomgr/endpoint.h" |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 39 | #include "src/core/transport/chttp2/frame.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 40 | #include "src/core/transport/chttp2/frame_data.h" |
| 41 | #include "src/core/transport/chttp2/frame_goaway.h" |
| 42 | #include "src/core/transport/chttp2/frame_ping.h" |
| 43 | #include "src/core/transport/chttp2/frame_rst_stream.h" |
| 44 | #include "src/core/transport/chttp2/frame_settings.h" |
| 45 | #include "src/core/transport/chttp2/frame_window_update.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 46 | #include "src/core/transport/chttp2/hpack_parser.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 47 | #include "src/core/transport/chttp2/incoming_metadata.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 48 | #include "src/core/transport/chttp2/stream_encoder.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 49 | #include "src/core/transport/chttp2/stream_map.h" |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 50 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 51 | typedef struct grpc_chttp2_transport grpc_chttp2_transport; |
| 52 | typedef struct grpc_chttp2_stream grpc_chttp2_stream; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 53 | |
| 54 | /* streams are kept in various linked lists depending on what things need to |
| 55 | happen to them... this enum labels each list */ |
| 56 | typedef enum { |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 57 | GRPC_CHTTP2_LIST_ALL_STREAMS, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 58 | GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 59 | GRPC_CHTTP2_LIST_WRITABLE, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 60 | GRPC_CHTTP2_LIST_WRITING, |
| 61 | GRPC_CHTTP2_LIST_WRITTEN, |
| 62 | GRPC_CHTTP2_LIST_WRITABLE_WINDOW_UPDATE, |
| 63 | GRPC_CHTTP2_LIST_PARSING_SEEN, |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 64 | GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING, |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 65 | GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 66 | /** streams that are waiting to start because there are too many concurrent |
| 67 | streams on the connection */ |
| 68 | GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 69 | STREAM_LIST_COUNT /* must be last */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 70 | } grpc_chttp2_stream_list_id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 71 | |
| 72 | /* deframer state for the overall http2 stream of bytes */ |
| 73 | typedef enum { |
| 74 | /* prefix: one entry per http2 connection prefix byte */ |
| 75 | DTS_CLIENT_PREFIX_0 = 0, |
| 76 | DTS_CLIENT_PREFIX_1, |
| 77 | DTS_CLIENT_PREFIX_2, |
| 78 | DTS_CLIENT_PREFIX_3, |
| 79 | DTS_CLIENT_PREFIX_4, |
| 80 | DTS_CLIENT_PREFIX_5, |
| 81 | DTS_CLIENT_PREFIX_6, |
| 82 | DTS_CLIENT_PREFIX_7, |
| 83 | DTS_CLIENT_PREFIX_8, |
| 84 | DTS_CLIENT_PREFIX_9, |
| 85 | DTS_CLIENT_PREFIX_10, |
| 86 | DTS_CLIENT_PREFIX_11, |
| 87 | DTS_CLIENT_PREFIX_12, |
| 88 | DTS_CLIENT_PREFIX_13, |
| 89 | DTS_CLIENT_PREFIX_14, |
| 90 | DTS_CLIENT_PREFIX_15, |
| 91 | DTS_CLIENT_PREFIX_16, |
| 92 | DTS_CLIENT_PREFIX_17, |
| 93 | DTS_CLIENT_PREFIX_18, |
| 94 | DTS_CLIENT_PREFIX_19, |
| 95 | DTS_CLIENT_PREFIX_20, |
| 96 | DTS_CLIENT_PREFIX_21, |
| 97 | DTS_CLIENT_PREFIX_22, |
| 98 | DTS_CLIENT_PREFIX_23, |
| 99 | /* frame header byte 0... */ |
| 100 | /* must follow from the prefix states */ |
| 101 | DTS_FH_0, |
| 102 | DTS_FH_1, |
| 103 | DTS_FH_2, |
| 104 | DTS_FH_3, |
| 105 | DTS_FH_4, |
| 106 | DTS_FH_5, |
| 107 | DTS_FH_6, |
| 108 | DTS_FH_7, |
| 109 | /* ... frame header byte 8 */ |
| 110 | DTS_FH_8, |
| 111 | /* inside a http2 frame */ |
| 112 | DTS_FRAME |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 113 | } grpc_chttp2_deframe_transport_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 114 | |
| 115 | typedef enum { |
| 116 | WRITE_STATE_OPEN, |
| 117 | WRITE_STATE_QUEUED_CLOSE, |
| 118 | WRITE_STATE_SENT_CLOSE |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 119 | } grpc_chttp2_write_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 120 | |
| 121 | typedef enum { |
| 122 | DONT_SEND_CLOSED = 0, |
| 123 | SEND_CLOSED, |
| 124 | SEND_CLOSED_WITH_RST_STREAM |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 125 | } grpc_chttp2_send_closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 126 | |
| 127 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 128 | grpc_chttp2_stream *head; |
| 129 | grpc_chttp2_stream *tail; |
| 130 | } grpc_chttp2_stream_list; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 131 | |
| 132 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 133 | grpc_chttp2_stream *next; |
| 134 | grpc_chttp2_stream *prev; |
| 135 | } grpc_chttp2_stream_link; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 136 | |
| 137 | typedef enum { |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 138 | GRPC_CHTTP2_ERROR_STATE_NONE, |
| 139 | GRPC_CHTTP2_ERROR_STATE_SEEN, |
| 140 | GRPC_CHTTP2_ERROR_STATE_NOTIFIED |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 141 | } grpc_chttp2_error_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 142 | |
| 143 | /* We keep several sets of connection wide parameters */ |
| 144 | typedef enum { |
| 145 | /* The settings our peer has asked for (and we have acked) */ |
| 146 | PEER_SETTINGS = 0, |
| 147 | /* The settings we'd like to have */ |
| 148 | LOCAL_SETTINGS, |
| 149 | /* The settings we've published to our peer */ |
| 150 | SENT_SETTINGS, |
| 151 | /* The settings the peer has acked */ |
| 152 | ACKED_SETTINGS, |
| 153 | NUM_SETTING_SETS |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 154 | } grpc_chttp2_setting_set; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 155 | |
| 156 | /* Outstanding ping request data */ |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 157 | typedef struct grpc_chttp2_outstanding_ping { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 158 | gpr_uint8 id[8]; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 159 | grpc_iomgr_closure *on_recv; |
| 160 | struct grpc_chttp2_outstanding_ping *next; |
| 161 | struct grpc_chttp2_outstanding_ping *prev; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 162 | } grpc_chttp2_outstanding_ping; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 163 | |
| 164 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 165 | /** data to write next write */ |
| 166 | gpr_slice_buffer qbuf; |
| 167 | /** queued callbacks */ |
| 168 | grpc_iomgr_closure *pending_closures; |
| 169 | |
| 170 | /** window available for us to send to peer */ |
| 171 | gpr_uint32 outgoing_window; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 172 | /** window available for peer to send to us - updated after parse */ |
| 173 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 174 | /** how much window would we like to have for incoming_window */ |
| 175 | gpr_uint32 connection_window_target; |
| 176 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 177 | /** is this transport a client? */ |
| 178 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 179 | /** are the local settings dirty and need to be sent? */ |
| 180 | gpr_uint8 dirtied_local_settings; |
| 181 | /** have local settings been sent? */ |
| 182 | gpr_uint8 sent_local_settings; |
| 183 | /** bitmask of setting indexes to send out */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 184 | gpr_uint32 force_send_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 185 | /** settings values */ |
| 186 | gpr_uint32 settings[NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS]; |
| 187 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 188 | /** has there been a connection level error, and have we notified |
| 189 | anyone about it? */ |
| 190 | grpc_chttp2_error_state error_state; |
| 191 | |
| 192 | /** what is the next stream id to be allocated by this peer? |
| 193 | copied to next_stream_id in parsing when parsing commences */ |
| 194 | gpr_uint32 next_stream_id; |
| 195 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 196 | /** last received stream id */ |
| 197 | gpr_uint32 last_incoming_stream_id; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 198 | |
| 199 | /** pings awaiting responses */ |
| 200 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 201 | /** next payload for an outgoing ping */ |
| 202 | gpr_uint64 ping_counter; |
| 203 | |
| 204 | /** concurrent stream count: updated when not parsing, |
| 205 | so this is a strict over-estimation on the client */ |
| 206 | gpr_uint32 concurrent_stream_count; |
| 207 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 208 | /** is there a goaway available? (boolean) */ |
| 209 | grpc_chttp2_error_state goaway_state; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 210 | /** what is the debug text of the goaway? */ |
| 211 | gpr_slice goaway_text; |
| 212 | /** what is the status code of the goaway? */ |
| 213 | grpc_status_code goaway_error; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 214 | } grpc_chttp2_transport_global; |
| 215 | |
| 216 | typedef struct { |
| 217 | /** data to write now */ |
| 218 | gpr_slice_buffer outbuf; |
| 219 | /** hpack encoding */ |
| 220 | grpc_chttp2_hpack_compressor hpack_compressor; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 221 | /** is this a client? */ |
| 222 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 223 | } grpc_chttp2_transport_writing; |
| 224 | |
| 225 | struct grpc_chttp2_transport_parsing { |
| 226 | /** is this transport a client? (boolean) */ |
| 227 | gpr_uint8 is_client; |
| 228 | |
| 229 | /** were settings updated? */ |
| 230 | gpr_uint8 settings_updated; |
| 231 | /** was a settings ack received? */ |
| 232 | gpr_uint8 settings_ack_received; |
| 233 | /** was a goaway frame received? */ |
| 234 | gpr_uint8 goaway_received; |
| 235 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 236 | /** initial window change */ |
| 237 | gpr_int64 initial_window_update; |
| 238 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 239 | /** data to write later - after parsing */ |
| 240 | gpr_slice_buffer qbuf; |
| 241 | /* metadata object cache */ |
| 242 | grpc_mdstr *str_grpc_timeout; |
| 243 | /** parser for headers */ |
| 244 | grpc_chttp2_hpack_parser hpack_parser; |
| 245 | /** simple one shot parsers */ |
| 246 | union { |
| 247 | grpc_chttp2_window_update_parser window_update; |
| 248 | grpc_chttp2_settings_parser settings; |
| 249 | grpc_chttp2_ping_parser ping; |
| 250 | grpc_chttp2_rst_stream_parser rst_stream; |
| 251 | } simple; |
| 252 | /** parser for goaway frames */ |
| 253 | grpc_chttp2_goaway_parser goaway_parser; |
| 254 | |
| 255 | /** window available for peer to send to us */ |
| 256 | gpr_uint32 incoming_window; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 257 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 258 | |
| 259 | /** next stream id available at the time of beginning parsing */ |
| 260 | gpr_uint32 next_stream_id; |
| 261 | gpr_uint32 last_incoming_stream_id; |
| 262 | |
| 263 | /* deframing */ |
| 264 | grpc_chttp2_deframe_transport_state deframe_state; |
| 265 | gpr_uint8 incoming_frame_type; |
| 266 | gpr_uint8 incoming_frame_flags; |
| 267 | gpr_uint8 header_eof; |
| 268 | gpr_uint32 expect_continuation_stream_id; |
| 269 | gpr_uint32 incoming_frame_size; |
| 270 | gpr_uint32 incoming_stream_id; |
| 271 | |
| 272 | /* active parser */ |
| 273 | void *parser_data; |
| 274 | grpc_chttp2_stream_parsing *incoming_stream; |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 275 | grpc_chttp2_parse_error (*parser)( |
| 276 | void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing, |
| 277 | grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 278 | |
| 279 | /* received settings */ |
| 280 | gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS]; |
| 281 | |
| 282 | /* goaway data */ |
| 283 | grpc_status_code goaway_error; |
| 284 | gpr_uint32 goaway_last_stream_index; |
| 285 | gpr_slice goaway_text; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 286 | |
| 287 | gpr_uint64 outgoing_window_update; |
| 288 | |
| 289 | /** pings awaiting responses */ |
| 290 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 293 | struct grpc_chttp2_transport { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 294 | grpc_transport base; /* must be first */ |
| 295 | grpc_endpoint *ep; |
| 296 | grpc_mdctx *metadata_context; |
| 297 | gpr_refcount refs; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 298 | |
| 299 | gpr_mu mu; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 300 | |
| 301 | /** is the transport destroying itself? */ |
| 302 | gpr_uint8 destroying; |
| 303 | /** has the upper layer closed the transport? */ |
| 304 | gpr_uint8 closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 305 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 306 | /** is a thread currently writing */ |
| 307 | gpr_uint8 writing_active; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 308 | /** is a thread currently parsing */ |
| 309 | gpr_uint8 parsing_active; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 310 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 311 | /** is there a read request to the endpoint outstanding? */ |
| 312 | gpr_uint8 endpoint_reading; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 313 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 314 | /** various lists of streams */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 315 | grpc_chttp2_stream_list lists[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 316 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 317 | /** global state for reading/writing */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 318 | grpc_chttp2_transport_global global; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 319 | /** state only accessible by the chain of execution that |
| 320 | set writing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 321 | grpc_chttp2_transport_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 322 | /** state only accessible by the chain of execution that |
| 323 | set parsing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 324 | grpc_chttp2_transport_parsing parsing; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 325 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 326 | /** maps stream id to grpc_chttp2_stream objects; |
| 327 | owned by the parsing thread when parsing */ |
| 328 | grpc_chttp2_stream_map parsing_stream_map; |
| 329 | |
| 330 | /** streams created by the client (possibly during parsing); |
| 331 | merged with parsing_stream_map during unlock when no |
| 332 | parsing is occurring */ |
| 333 | grpc_chttp2_stream_map new_stream_map; |
| 334 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 335 | /** closure to execute writing */ |
| 336 | grpc_iomgr_closure writing_action; |
Craig Tiller | 8b2f1d7 | 2015-06-18 13:38:38 -0700 | [diff] [blame^] | 337 | /** closure to start reading from the endpoint */ |
| 338 | grpc_iomgr_closure reading_action; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 339 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 340 | /** address to place a newly accepted stream - set and unset by |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 341 | grpc_chttp2_parsing_accept_stream; used by init_stream to |
| 342 | publish the accepted server stream */ |
| 343 | grpc_chttp2_stream **accepting_stream; |
| 344 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 345 | struct { |
| 346 | /** is a thread currently performing channel callbacks */ |
| 347 | gpr_uint8 executing; |
| 348 | /** transport channel-level callback */ |
| 349 | const grpc_transport_callbacks *cb; |
| 350 | /** user data for cb calls */ |
| 351 | void *cb_user_data; |
| 352 | /** closure for notifying transport closure */ |
| 353 | grpc_iomgr_closure notify_closed; |
| 354 | } channel_callback; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 355 | |
| 356 | #if 0 |
| 357 | /* basic state management - what are we doing at the moment? */ |
| 358 | gpr_uint8 reading; |
| 359 | /** are we calling back any grpc_transport_op completion events */ |
| 360 | gpr_uint8 calling_back_ops; |
| 361 | gpr_uint8 destroying; |
| 362 | gpr_uint8 closed; |
| 363 | |
| 364 | /* stream indexing */ |
| 365 | gpr_uint32 next_stream_id; |
| 366 | |
| 367 | /* window management */ |
| 368 | gpr_uint32 outgoing_window_update; |
| 369 | |
| 370 | /* state for a stream that's not yet been created */ |
| 371 | grpc_stream_op_buffer new_stream_sopb; |
| 372 | |
| 373 | /* stream ops that need to be destroyed, but outside of the lock */ |
| 374 | grpc_stream_op_buffer nuke_later_sopb; |
| 375 | |
| 376 | /* pings */ |
| 377 | gpr_int64 ping_counter; |
| 378 | |
| 379 | |
| 380 | grpc_chttp2_stream **accepting_stream; |
| 381 | |
| 382 | #endif |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 385 | typedef struct { |
| 386 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 387 | gpr_uint32 id; |
| 388 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 389 | grpc_iomgr_closure *send_done_closure; |
| 390 | grpc_iomgr_closure *recv_done_closure; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 391 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 392 | /** window available for us to send to peer */ |
| 393 | gpr_int64 outgoing_window; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 394 | /** window available for peer to send to us - updated after parse */ |
| 395 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 396 | /** stream ops the transport user would like to send */ |
| 397 | grpc_stream_op_buffer *outgoing_sopb; |
| 398 | /** when the application requests writes be closed, the write_closed is |
| 399 | 'queued'; when the close is flow controlled into the send path, we are |
| 400 | 'sending' it; when the write has been performed it is 'sent' */ |
| 401 | grpc_chttp2_write_state write_state; |
| 402 | /** is this stream closed (boolean) */ |
| 403 | gpr_uint8 read_closed; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 404 | /** has this stream been cancelled? (boolean) */ |
| 405 | gpr_uint8 cancelled; |
Craig Tiller | cec9eb9 | 2015-06-17 17:16:48 -0700 | [diff] [blame] | 406 | grpc_status_code cancelled_status; |
| 407 | /** have we told the upper layer that this stream is cancelled? */ |
| 408 | gpr_uint8 published_cancelled; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 409 | /** is this stream in the stream map? (boolean) */ |
| 410 | gpr_uint8 in_stream_map; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 411 | |
| 412 | /** stream state already published to the upper layer */ |
| 413 | grpc_stream_state published_state; |
| 414 | /** address to publish next stream state to */ |
| 415 | grpc_stream_state *publish_state; |
| 416 | /** pointer to sop buffer to fill in with new stream ops */ |
Craig Tiller | 6905b7c | 2015-06-16 15:33:33 -0700 | [diff] [blame] | 417 | grpc_stream_op_buffer *publish_sopb; |
| 418 | grpc_stream_op_buffer incoming_sopb; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 419 | |
| 420 | /** incoming metadata */ |
| 421 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
Craig Tiller | b787c50 | 2015-06-15 16:14:52 -0700 | [diff] [blame] | 422 | grpc_chttp2_incoming_metadata_live_op_buffer outstanding_metadata; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 423 | } grpc_chttp2_stream_global; |
| 424 | |
| 425 | typedef struct { |
| 426 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 427 | gpr_uint32 id; |
| 428 | /** sops that have passed flow control to be written */ |
| 429 | grpc_stream_op_buffer sopb; |
| 430 | /** how strongly should we indicate closure with the next write */ |
| 431 | grpc_chttp2_send_closed send_closed; |
| 432 | } grpc_chttp2_stream_writing; |
| 433 | |
| 434 | struct grpc_chttp2_stream_parsing { |
| 435 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 436 | gpr_uint32 id; |
| 437 | /** has this stream received a close */ |
| 438 | gpr_uint8 received_close; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 439 | /** saw a rst_stream */ |
| 440 | gpr_uint8 saw_rst_stream; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 441 | /** incoming_window has been reduced by this much during parsing */ |
| 442 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 443 | /** window available for peer to send to us */ |
| 444 | gpr_uint32 incoming_window; |
| 445 | /** parsing state for data frames */ |
| 446 | grpc_chttp2_data_parser data_parser; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 447 | /** reason give to rst_stream */ |
| 448 | gpr_uint32 rst_stream_reason; |
| 449 | /* amount of window given */ |
| 450 | gpr_uint64 outgoing_window_update; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 451 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 452 | /** incoming metadata */ |
| 453 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
| 454 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 455 | /* |
| 456 | grpc_linked_mdelem *incoming_metadata; |
| 457 | size_t incoming_metadata_count; |
| 458 | size_t incoming_metadata_capacity; |
| 459 | grpc_linked_mdelem *old_incoming_metadata; |
| 460 | gpr_timespec incoming_deadline; |
| 461 | */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | struct grpc_chttp2_stream { |
| 465 | grpc_chttp2_stream_global global; |
| 466 | grpc_chttp2_stream_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 467 | grpc_chttp2_stream_parsing parsing; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 468 | |
| 469 | grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; |
| 470 | gpr_uint8 included[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 471 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 472 | #if 0 |
| 473 | gpr_uint32 outgoing_window_update; |
| 474 | gpr_uint8 cancelled; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 475 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 476 | grpc_stream_state callback_state; |
| 477 | grpc_stream_op_buffer callback_sopb; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 478 | #endif |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 479 | }; |
| 480 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 481 | /** Transport writing call flow: |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 482 | chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes |
| 483 | are required; |
| 484 | if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the |
| 485 | writes. |
| 486 | Once writes have been completed (meaning another write could potentially be |
| 487 | started), |
| 488 | grpc_chttp2_terminate_writing is called. This will call |
| 489 | grpc_chttp2_cleanup_writing, at which |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 490 | point the write phase is complete. */ |
| 491 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 492 | /** Someone is unlocking the transport mutex: check to see if writes |
| 493 | are required, and schedule them if so */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 494 | int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, |
| 495 | grpc_chttp2_transport_writing *writing); |
| 496 | void grpc_chttp2_perform_writes( |
| 497 | grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint); |
| 498 | void grpc_chttp2_terminate_writing( |
| 499 | grpc_chttp2_transport_writing *transport_writing, int success); |
| 500 | void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, |
| 501 | grpc_chttp2_transport_writing *writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 502 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 503 | void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, |
| 504 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | 1937b06 | 2015-06-16 08:47:38 -0700 | [diff] [blame] | 505 | /** Process one slice of incoming data */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 506 | int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, |
| 507 | gpr_slice slice); |
| 508 | void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, |
| 509 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 510 | |
| 511 | /** Get a writable stream |
| 512 | \return non-zero if there was a stream available */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 513 | void grpc_chttp2_list_add_writable_stream( |
| 514 | grpc_chttp2_transport_global *transport_global, |
| 515 | grpc_chttp2_stream_global *stream_global); |
| 516 | int grpc_chttp2_list_pop_writable_stream( |
| 517 | grpc_chttp2_transport_global *transport_global, |
| 518 | grpc_chttp2_transport_writing *transport_writing, |
| 519 | grpc_chttp2_stream_global **stream_global, |
| 520 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 521 | |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 522 | void grpc_chttp2_list_add_incoming_window_updated( |
| 523 | grpc_chttp2_transport_global *transport_global, |
| 524 | grpc_chttp2_stream_global *stream_global); |
| 525 | int grpc_chttp2_list_pop_incoming_window_updated( |
| 526 | grpc_chttp2_transport_global *transport_global, |
| 527 | grpc_chttp2_transport_parsing *transport_parsing, |
| 528 | grpc_chttp2_stream_global **stream_global, |
| 529 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | 759eb32 | 2015-06-16 22:41:18 -0700 | [diff] [blame] | 530 | void grpc_chttp2_list_remove_incoming_window_updated( |
| 531 | grpc_chttp2_transport_global *transport_global, |
| 532 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 533 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 534 | void grpc_chttp2_list_add_writing_stream( |
| 535 | grpc_chttp2_transport_writing *transport_writing, |
| 536 | grpc_chttp2_stream_writing *stream_writing); |
| 537 | int grpc_chttp2_list_have_writing_streams( |
| 538 | grpc_chttp2_transport_writing *transport_writing); |
| 539 | int grpc_chttp2_list_pop_writing_stream( |
| 540 | grpc_chttp2_transport_writing *transport_writing, |
| 541 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 542 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 543 | void grpc_chttp2_list_add_written_stream( |
| 544 | grpc_chttp2_transport_writing *transport_writing, |
| 545 | grpc_chttp2_stream_writing *stream_writing); |
| 546 | int grpc_chttp2_list_pop_written_stream( |
| 547 | grpc_chttp2_transport_global *transport_global, |
| 548 | grpc_chttp2_transport_writing *transport_writing, |
| 549 | grpc_chttp2_stream_global **stream_global, |
| 550 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 551 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 552 | void grpc_chttp2_list_add_writable_window_update_stream( |
| 553 | grpc_chttp2_transport_global *transport_global, |
| 554 | grpc_chttp2_stream_global *stream_global); |
| 555 | int grpc_chttp2_list_pop_writable_window_update_stream( |
| 556 | grpc_chttp2_transport_global *transport_global, |
| 557 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 558 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 559 | void grpc_chttp2_list_add_parsing_seen_stream( |
| 560 | grpc_chttp2_transport_parsing *transport_parsing, |
| 561 | grpc_chttp2_stream_parsing *stream_parsing); |
| 562 | int grpc_chttp2_list_pop_parsing_seen_stream( |
| 563 | grpc_chttp2_transport_global *transport_global, |
| 564 | grpc_chttp2_transport_parsing *transport_parsing, |
| 565 | grpc_chttp2_stream_global **stream_global, |
| 566 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 567 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 568 | void grpc_chttp2_list_add_waiting_for_concurrency( |
| 569 | grpc_chttp2_transport_global *transport_global, |
| 570 | grpc_chttp2_stream_global *stream_global); |
| 571 | int grpc_chttp2_list_pop_waiting_for_concurrency( |
| 572 | grpc_chttp2_transport_global *transport_global, |
| 573 | grpc_chttp2_stream_global **stream_global); |
| 574 | |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 575 | void grpc_chttp2_list_add_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 576 | grpc_chttp2_transport_global *transport_global, |
| 577 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 578 | int grpc_chttp2_list_pop_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 579 | grpc_chttp2_transport_global *transport_global, |
| 580 | grpc_chttp2_stream_global **stream_global); |
| 581 | |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 582 | void grpc_chttp2_list_add_read_write_state_changed( |
| 583 | grpc_chttp2_transport_global *transport_global, |
| 584 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | f73fcd1 | 2015-06-16 16:25:26 -0700 | [diff] [blame] | 585 | int grpc_chttp2_list_pop_read_write_state_changed( |
| 586 | grpc_chttp2_transport_global *transport_global, |
| 587 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 588 | |
Craig Tiller | 1937b06 | 2015-06-16 08:47:38 -0700 | [diff] [blame] | 589 | /** schedule a closure to run without the transport lock taken */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 590 | void grpc_chttp2_schedule_closure( |
| 591 | grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure, |
| 592 | int success); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 593 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 594 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream( |
| 595 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
| 596 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream( |
| 597 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 598 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 599 | void grpc_chttp2_add_incoming_goaway( |
| 600 | grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error, |
| 601 | gpr_slice goaway_text); |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 602 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 603 | void grpc_chttp2_register_stream(grpc_chttp2_transport *t, |
| 604 | grpc_chttp2_stream *s); |
| 605 | void grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, |
| 606 | grpc_chttp2_stream *s); |
| 607 | void grpc_chttp2_for_all_streams( |
| 608 | grpc_chttp2_transport_global *transport_global, void *user_data, |
| 609 | void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, |
| 610 | grpc_chttp2_stream_global *stream_global)); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 611 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 612 | void grpc_chttp2_parsing_become_skip_parser( |
| 613 | grpc_chttp2_transport_parsing *transport_parsing); |
Craig Tiller | 66abdaa | 2015-06-17 08:00:39 -0700 | [diff] [blame] | 614 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 615 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 616 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ |
| 617 | (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 618 | |
| 619 | extern int grpc_http_trace; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 620 | extern int grpc_flowctl_trace; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 621 | |
| 622 | #define IF_TRACING(stmt) \ |
| 623 | if (!(grpc_http_trace)) \ |
| 624 | ; \ |
| 625 | else \ |
| 626 | stmt |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 627 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 628 | #define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \ |
| 629 | delta) \ |
| 630 | if (!(grpc_flowctl_trace)) { \ |
| 631 | } else { \ |
| 632 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 633 | transport->is_client, context->id, context->var, \ |
| 634 | delta); \ |
| 635 | } |
| 636 | |
| 637 | #define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \ |
| 638 | if (!(grpc_flowctl_trace)) { \ |
| 639 | } else { \ |
| 640 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 641 | context->is_client, 0, context->var, delta); \ |
| 642 | } |
| 643 | |
| 644 | void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason, |
| 645 | const char *context, const char *var, |
| 646 | int is_client, gpr_uint32 stream_id, |
| 647 | gpr_int64 current_value, gpr_int64 delta); |
| 648 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 649 | #endif |