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" |
| 46 | #include "src/core/transport/chttp2/stream_map.h" |
| 47 | #include "src/core/transport/chttp2/hpack_parser.h" |
| 48 | #include "src/core/transport/chttp2/stream_encoder.h" |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 49 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 50 | typedef struct grpc_chttp2_transport grpc_chttp2_transport; |
| 51 | typedef struct grpc_chttp2_stream grpc_chttp2_stream; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 52 | |
| 53 | /* streams are kept in various linked lists depending on what things need to |
| 54 | happen to them... this enum labels each list */ |
| 55 | typedef enum { |
| 56 | /* streams that have pending writes */ |
| 57 | WRITABLE = 0, |
| 58 | /* streams that have been selected to be written */ |
| 59 | WRITING, |
| 60 | /* streams that have just been written, and included a close */ |
| 61 | WRITTEN_CLOSED, |
| 62 | /* streams that have been cancelled and have some pending state updates |
| 63 | to perform */ |
| 64 | CANCELLED, |
| 65 | /* streams that want to send window updates */ |
| 66 | WINDOW_UPDATE, |
| 67 | /* streams that are waiting to start because there are too many concurrent |
| 68 | streams on the connection */ |
| 69 | WAITING_FOR_CONCURRENCY, |
| 70 | /* streams that have finished reading: we wait until unlock to coalesce |
| 71 | all changes into one callback */ |
| 72 | FINISHED_READ_OP, |
| 73 | MAYBE_FINISH_READ_AFTER_PARSE, |
| 74 | PARSER_CHECK_WINDOW_UPDATES_AFTER_PARSE, |
| 75 | OTHER_CHECK_WINDOW_UPDATES_AFTER_PARSE, |
| 76 | NEW_OUTGOING_WINDOW, |
| 77 | STREAM_LIST_COUNT /* must be last */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 78 | } grpc_chttp2_stream_list_id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 79 | |
| 80 | /* deframer state for the overall http2 stream of bytes */ |
| 81 | typedef enum { |
| 82 | /* prefix: one entry per http2 connection prefix byte */ |
| 83 | DTS_CLIENT_PREFIX_0 = 0, |
| 84 | DTS_CLIENT_PREFIX_1, |
| 85 | DTS_CLIENT_PREFIX_2, |
| 86 | DTS_CLIENT_PREFIX_3, |
| 87 | DTS_CLIENT_PREFIX_4, |
| 88 | DTS_CLIENT_PREFIX_5, |
| 89 | DTS_CLIENT_PREFIX_6, |
| 90 | DTS_CLIENT_PREFIX_7, |
| 91 | DTS_CLIENT_PREFIX_8, |
| 92 | DTS_CLIENT_PREFIX_9, |
| 93 | DTS_CLIENT_PREFIX_10, |
| 94 | DTS_CLIENT_PREFIX_11, |
| 95 | DTS_CLIENT_PREFIX_12, |
| 96 | DTS_CLIENT_PREFIX_13, |
| 97 | DTS_CLIENT_PREFIX_14, |
| 98 | DTS_CLIENT_PREFIX_15, |
| 99 | DTS_CLIENT_PREFIX_16, |
| 100 | DTS_CLIENT_PREFIX_17, |
| 101 | DTS_CLIENT_PREFIX_18, |
| 102 | DTS_CLIENT_PREFIX_19, |
| 103 | DTS_CLIENT_PREFIX_20, |
| 104 | DTS_CLIENT_PREFIX_21, |
| 105 | DTS_CLIENT_PREFIX_22, |
| 106 | DTS_CLIENT_PREFIX_23, |
| 107 | /* frame header byte 0... */ |
| 108 | /* must follow from the prefix states */ |
| 109 | DTS_FH_0, |
| 110 | DTS_FH_1, |
| 111 | DTS_FH_2, |
| 112 | DTS_FH_3, |
| 113 | DTS_FH_4, |
| 114 | DTS_FH_5, |
| 115 | DTS_FH_6, |
| 116 | DTS_FH_7, |
| 117 | /* ... frame header byte 8 */ |
| 118 | DTS_FH_8, |
| 119 | /* inside a http2 frame */ |
| 120 | DTS_FRAME |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 121 | } grpc_chttp2_deframe_transport_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 122 | |
| 123 | typedef enum { |
| 124 | WRITE_STATE_OPEN, |
| 125 | WRITE_STATE_QUEUED_CLOSE, |
| 126 | WRITE_STATE_SENT_CLOSE |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 127 | } grpc_chttp2_write_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 128 | |
| 129 | typedef enum { |
| 130 | DONT_SEND_CLOSED = 0, |
| 131 | SEND_CLOSED, |
| 132 | SEND_CLOSED_WITH_RST_STREAM |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 133 | } grpc_chttp2_send_closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 134 | |
| 135 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 136 | grpc_chttp2_stream *head; |
| 137 | grpc_chttp2_stream *tail; |
| 138 | } grpc_chttp2_stream_list; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 139 | |
| 140 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 141 | grpc_chttp2_stream *next; |
| 142 | grpc_chttp2_stream *prev; |
| 143 | } grpc_chttp2_stream_link; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 144 | |
| 145 | typedef enum { |
| 146 | ERROR_STATE_NONE, |
| 147 | ERROR_STATE_SEEN, |
| 148 | ERROR_STATE_NOTIFIED |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 149 | } grpc_chttp2_error_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 150 | |
| 151 | /* We keep several sets of connection wide parameters */ |
| 152 | typedef enum { |
| 153 | /* The settings our peer has asked for (and we have acked) */ |
| 154 | PEER_SETTINGS = 0, |
| 155 | /* The settings we'd like to have */ |
| 156 | LOCAL_SETTINGS, |
| 157 | /* The settings we've published to our peer */ |
| 158 | SENT_SETTINGS, |
| 159 | /* The settings the peer has acked */ |
| 160 | ACKED_SETTINGS, |
| 161 | NUM_SETTING_SETS |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 162 | } grpc_chttp2_setting_set; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 163 | |
| 164 | /* Outstanding ping request data */ |
| 165 | typedef struct { |
| 166 | gpr_uint8 id[8]; |
| 167 | void (*cb)(void *user_data); |
| 168 | void *user_data; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 169 | } grpc_chttp2_outstanding_ping; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 170 | |
| 171 | typedef struct { |
| 172 | grpc_status_code status; |
| 173 | gpr_slice debug; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 174 | } grpc_chttp2_pending_goaway; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 175 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 176 | typedef struct { |
| 177 | /** data to write next write */ |
| 178 | gpr_slice_buffer qbuf; |
| 179 | /** queued callbacks */ |
| 180 | grpc_iomgr_closure *pending_closures; |
| 181 | |
| 182 | /** window available for us to send to peer */ |
| 183 | gpr_uint32 outgoing_window; |
| 184 | /** how much window would we like to have for incoming_window */ |
| 185 | gpr_uint32 connection_window_target; |
| 186 | |
| 187 | |
| 188 | /** are the local settings dirty and need to be sent? */ |
| 189 | gpr_uint8 dirtied_local_settings; |
| 190 | /** have local settings been sent? */ |
| 191 | gpr_uint8 sent_local_settings; |
| 192 | /** bitmask of setting indexes to send out */ |
| 193 | gpr_uint32 force_send_settings; |
| 194 | /** settings values */ |
| 195 | gpr_uint32 settings[NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS]; |
| 196 | |
| 197 | /** last received stream id */ |
| 198 | gpr_uint32 last_incoming_stream_id; |
| 199 | } grpc_chttp2_transport_global; |
| 200 | |
| 201 | typedef struct { |
| 202 | /** data to write now */ |
| 203 | gpr_slice_buffer outbuf; |
| 204 | /** hpack encoding */ |
| 205 | grpc_chttp2_hpack_compressor hpack_compressor; |
| 206 | } grpc_chttp2_transport_writing; |
| 207 | |
| 208 | struct grpc_chttp2_transport_parsing { |
| 209 | /** is this transport a client? (boolean) */ |
| 210 | gpr_uint8 is_client; |
| 211 | |
| 212 | /** were settings updated? */ |
| 213 | gpr_uint8 settings_updated; |
| 214 | /** was a settings ack received? */ |
| 215 | gpr_uint8 settings_ack_received; |
| 216 | /** was a goaway frame received? */ |
| 217 | gpr_uint8 goaway_received; |
| 218 | |
| 219 | /** data to write later - after parsing */ |
| 220 | gpr_slice_buffer qbuf; |
| 221 | /* metadata object cache */ |
| 222 | grpc_mdstr *str_grpc_timeout; |
| 223 | /** parser for headers */ |
| 224 | grpc_chttp2_hpack_parser hpack_parser; |
| 225 | /** simple one shot parsers */ |
| 226 | union { |
| 227 | grpc_chttp2_window_update_parser window_update; |
| 228 | grpc_chttp2_settings_parser settings; |
| 229 | grpc_chttp2_ping_parser ping; |
| 230 | grpc_chttp2_rst_stream_parser rst_stream; |
| 231 | } simple; |
| 232 | /** parser for goaway frames */ |
| 233 | grpc_chttp2_goaway_parser goaway_parser; |
| 234 | |
| 235 | /** window available for peer to send to us */ |
| 236 | gpr_uint32 incoming_window; |
| 237 | |
| 238 | /** next stream id available at the time of beginning parsing */ |
| 239 | gpr_uint32 next_stream_id; |
| 240 | gpr_uint32 last_incoming_stream_id; |
| 241 | |
| 242 | /* deframing */ |
| 243 | grpc_chttp2_deframe_transport_state deframe_state; |
| 244 | gpr_uint8 incoming_frame_type; |
| 245 | gpr_uint8 incoming_frame_flags; |
| 246 | gpr_uint8 header_eof; |
| 247 | gpr_uint32 expect_continuation_stream_id; |
| 248 | gpr_uint32 incoming_frame_size; |
| 249 | gpr_uint32 incoming_stream_id; |
| 250 | |
| 251 | /* active parser */ |
| 252 | void *parser_data; |
| 253 | grpc_chttp2_stream_parsing *incoming_stream; |
| 254 | grpc_chttp2_parse_error (*parser)(void *parser_user_data, |
| 255 | grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing, |
| 256 | gpr_slice slice, int is_last); |
| 257 | |
| 258 | /* received settings */ |
| 259 | gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS]; |
| 260 | |
| 261 | /* goaway data */ |
| 262 | grpc_status_code goaway_error; |
| 263 | gpr_uint32 goaway_last_stream_index; |
| 264 | gpr_slice goaway_text; |
| 265 | }; |
| 266 | |
| 267 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 268 | struct grpc_chttp2_transport { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 269 | grpc_transport base; /* must be first */ |
| 270 | grpc_endpoint *ep; |
| 271 | grpc_mdctx *metadata_context; |
| 272 | gpr_refcount refs; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 273 | |
| 274 | gpr_mu mu; |
| 275 | gpr_cv cv; |
| 276 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 277 | /** is a thread currently writing */ |
| 278 | gpr_uint8 writing_active; |
| 279 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 280 | /* basic state management - what are we doing at the moment? */ |
| 281 | gpr_uint8 reading; |
| 282 | /** are we calling back any grpc_transport_op completion events */ |
| 283 | gpr_uint8 calling_back_ops; |
| 284 | gpr_uint8 destroying; |
| 285 | gpr_uint8 closed; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 286 | grpc_chttp2_error_state error_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 287 | |
| 288 | /* stream indexing */ |
| 289 | gpr_uint32 next_stream_id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 290 | |
| 291 | /* window management */ |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 292 | gpr_uint32 outgoing_window_update; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 293 | |
| 294 | /* goaway */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 295 | grpc_chttp2_pending_goaway *pending_goaways; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 296 | size_t num_pending_goaways; |
| 297 | size_t cap_pending_goaways; |
| 298 | |
| 299 | /* state for a stream that's not yet been created */ |
| 300 | grpc_stream_op_buffer new_stream_sopb; |
| 301 | |
| 302 | /* stream ops that need to be destroyed, but outside of the lock */ |
| 303 | grpc_stream_op_buffer nuke_later_sopb; |
| 304 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 305 | grpc_chttp2_stream_list lists[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 306 | grpc_chttp2_stream_map stream_map; |
| 307 | |
| 308 | /* pings */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 309 | grpc_chttp2_outstanding_ping *pings; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 310 | size_t ping_count; |
| 311 | size_t ping_capacity; |
| 312 | gpr_int64 ping_counter; |
| 313 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 314 | grpc_chttp2_transport_global global; |
| 315 | grpc_chttp2_transport_writing writing; |
| 316 | grpc_chttp2_transport_parsing parsing; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 317 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 318 | /** closure to execute writing */ |
| 319 | grpc_iomgr_closure writing_action; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 320 | |
| 321 | struct { |
| 322 | /** is a thread currently performing channel callbacks */ |
| 323 | gpr_uint8 executing; |
| 324 | /** transport channel-level callback */ |
| 325 | const grpc_transport_callbacks *cb; |
| 326 | /** user data for cb calls */ |
| 327 | void *cb_user_data; |
| 328 | /** closure for notifying transport closure */ |
| 329 | grpc_iomgr_closure notify_closed; |
| 330 | } channel_callback; |
| 331 | }; |
| 332 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 333 | typedef struct { |
| 334 | /** 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] | 335 | gpr_uint32 id; |
| 336 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 337 | grpc_iomgr_closure *send_done_closure; |
| 338 | grpc_iomgr_closure *recv_done_closure; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 339 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 340 | /** window available for us to send to peer */ |
| 341 | gpr_int64 outgoing_window; |
| 342 | /** stream ops the transport user would like to send */ |
| 343 | grpc_stream_op_buffer *outgoing_sopb; |
| 344 | /** when the application requests writes be closed, the write_closed is |
| 345 | 'queued'; when the close is flow controlled into the send path, we are |
| 346 | 'sending' it; when the write has been performed it is 'sent' */ |
| 347 | grpc_chttp2_write_state write_state; |
| 348 | /** is this stream closed (boolean) */ |
| 349 | gpr_uint8 read_closed; |
| 350 | } grpc_chttp2_stream_global; |
| 351 | |
| 352 | typedef struct { |
| 353 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 354 | gpr_uint32 id; |
| 355 | /** sops that have passed flow control to be written */ |
| 356 | grpc_stream_op_buffer sopb; |
| 357 | /** how strongly should we indicate closure with the next write */ |
| 358 | grpc_chttp2_send_closed send_closed; |
| 359 | } grpc_chttp2_stream_writing; |
| 360 | |
| 361 | struct grpc_chttp2_stream_parsing { |
| 362 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 363 | gpr_uint32 id; |
| 364 | /** has this stream received a close */ |
| 365 | gpr_uint8 received_close; |
| 366 | /** incoming_window has been reduced during parsing */ |
| 367 | gpr_uint8 incoming_window_changed; |
| 368 | /** saw an error on this stream during parsing (it should be cancelled) */ |
| 369 | gpr_uint8 saw_error; |
| 370 | /** window available for peer to send to us */ |
| 371 | gpr_uint32 incoming_window; |
| 372 | /** parsing state for data frames */ |
| 373 | grpc_chttp2_data_parser data_parser; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 374 | |
| 375 | /* incoming metadata */ |
| 376 | grpc_linked_mdelem *incoming_metadata; |
| 377 | size_t incoming_metadata_count; |
| 378 | size_t incoming_metadata_capacity; |
| 379 | grpc_linked_mdelem *old_incoming_metadata; |
| 380 | gpr_timespec incoming_deadline; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 381 | }; |
| 382 | |
| 383 | struct grpc_chttp2_stream { |
| 384 | grpc_chttp2_stream_global global; |
| 385 | grpc_chttp2_stream_writing writing; |
| 386 | |
| 387 | gpr_uint32 outgoing_window_update; |
| 388 | gpr_uint8 cancelled; |
| 389 | |
| 390 | grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; |
| 391 | gpr_uint8 included[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 392 | |
| 393 | /* sops from application */ |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 394 | grpc_stream_op_buffer *incoming_sopb; |
| 395 | grpc_stream_state *publish_state; |
| 396 | grpc_stream_state published_state; |
| 397 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 398 | grpc_stream_state callback_state; |
| 399 | grpc_stream_op_buffer callback_sopb; |
| 400 | }; |
| 401 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 402 | /** Transport writing call flow: |
| 403 | chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes are required; |
| 404 | if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the writes. |
| 405 | Once writes have been completed (meaning another write could potentially be started), |
| 406 | grpc_chttp2_terminate_writing is called. This will call grpc_chttp2_cleanup_writing, at which |
| 407 | point the write phase is complete. */ |
| 408 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 409 | /** Someone is unlocking the transport mutex: check to see if writes |
| 410 | are required, and schedule them if so */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame^] | 411 | int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, grpc_chttp2_transport_writing *writing); |
| 412 | void grpc_chttp2_perform_writes(grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint); |
| 413 | void grpc_chttp2_terminate_writing(grpc_chttp2_transport_writing *transport_writing, int success); |
| 414 | void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, grpc_chttp2_transport_writing *writing); |
| 415 | |
| 416 | /** Process one slice of incoming data */ |
| 417 | int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, gpr_slice slice); |
| 418 | void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, grpc_chttp2_transport_parsing *parsing); |
| 419 | |
| 420 | /** Get a writable stream |
| 421 | \return non-zero if there was a stream available */ |
| 422 | void grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global); |
| 423 | int grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_writing *transport_writing, |
| 424 | grpc_chttp2_stream_global **stream_global, grpc_chttp2_stream_writing **stream_writing); |
| 425 | |
| 426 | void grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing *stream_writing); |
| 427 | int grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport_writing *transport_writing); |
| 428 | int grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing **stream_writing); |
| 429 | |
| 430 | void grpc_chttp2_list_add_written_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing *stream_writing); |
| 431 | int grpc_chttp2_list_pop_written_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_global **stream_global, grpc_chttp2_stream_writing **stream_writing); |
| 432 | |
| 433 | int grpc_chttp2_list_pop_writable_window_update_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global **stream_global); |
| 434 | |
| 435 | void grpc_chttp2_list_add_parsing_seen_stream(grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing); |
| 436 | |
| 437 | void grpc_chttp2_schedule_closure(grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure, int success); |
| 438 | void grpc_chttp2_read_write_state_changed(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global); |
| 439 | |
| 440 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
| 441 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
| 442 | |
| 443 | #define GRPC_CHTTP2_FLOW_CTL_TRACE(a,b,c,d,e) do {} while (0) |
| 444 | |
| 445 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" |
| 446 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING)-1) |
| 447 | |
| 448 | extern int grpc_http_trace; |
| 449 | |
| 450 | #define IF_TRACING(stmt) \ |
| 451 | if (!(grpc_http_trace)) \ |
| 452 | ; \ |
| 453 | else \ |
| 454 | stmt |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 455 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 456 | #endif |