blob: ffadd0476219d3aaa9fa4d82688acbf3b76094b9 [file] [log] [blame]
Craig Tiller640d3bd2015-06-12 07:51:51 -07001/*
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 Tiller9b8671c2015-06-12 07:41:54 -070034#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 Tiller3208e392015-06-12 08:17:02 -070038#include "src/core/iomgr/endpoint.h"
Craig Tillerd20efd22015-06-12 16:17:09 -070039#include "src/core/transport/chttp2/frame.h"
Craig Tiller3208e392015-06-12 08:17:02 -070040#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 Tiller9b8671c2015-06-12 07:41:54 -070049
Craig Tillerb084d902015-06-12 07:50:02 -070050typedef struct grpc_chttp2_transport grpc_chttp2_transport;
51typedef struct grpc_chttp2_stream grpc_chttp2_stream;
Craig Tiller9b8671c2015-06-12 07:41:54 -070052
53/* streams are kept in various linked lists depending on what things need to
54 happen to them... this enum labels each list */
55typedef 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 Tillerb084d902015-06-12 07:50:02 -070078} grpc_chttp2_stream_list_id;
Craig Tiller9b8671c2015-06-12 07:41:54 -070079
80/* deframer state for the overall http2 stream of bytes */
81typedef 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 Tillerb084d902015-06-12 07:50:02 -0700121} grpc_chttp2_deframe_transport_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700122
123typedef enum {
124 WRITE_STATE_OPEN,
125 WRITE_STATE_QUEUED_CLOSE,
126 WRITE_STATE_SENT_CLOSE
Craig Tillerb084d902015-06-12 07:50:02 -0700127} grpc_chttp2_write_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700128
129typedef enum {
130 DONT_SEND_CLOSED = 0,
131 SEND_CLOSED,
132 SEND_CLOSED_WITH_RST_STREAM
Craig Tillerb084d902015-06-12 07:50:02 -0700133} grpc_chttp2_send_closed;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700134
135typedef struct {
Craig Tillerb084d902015-06-12 07:50:02 -0700136 grpc_chttp2_stream *head;
137 grpc_chttp2_stream *tail;
138} grpc_chttp2_stream_list;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700139
140typedef struct {
Craig Tillerb084d902015-06-12 07:50:02 -0700141 grpc_chttp2_stream *next;
142 grpc_chttp2_stream *prev;
143} grpc_chttp2_stream_link;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700144
145typedef enum {
Craig Tiller606d8742015-06-15 06:58:50 -0700146 GRPC_CHTTP2_ERROR_STATE_NONE,
147 GRPC_CHTTP2_ERROR_STATE_SEEN,
148 GRPC_CHTTP2_ERROR_STATE_NOTIFIED
Craig Tillerb084d902015-06-12 07:50:02 -0700149} grpc_chttp2_error_state;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700150
151/* We keep several sets of connection wide parameters */
152typedef 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 Tillerb084d902015-06-12 07:50:02 -0700162} grpc_chttp2_setting_set;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700163
164/* Outstanding ping request data */
Craig Tiller3719f072015-06-12 17:19:51 -0700165typedef struct grpc_chttp2_outstanding_ping {
Craig Tiller9b8671c2015-06-12 07:41:54 -0700166 gpr_uint8 id[8];
Craig Tiller3719f072015-06-12 17:19:51 -0700167 grpc_iomgr_closure *on_recv;
168 struct grpc_chttp2_outstanding_ping *next;
169 struct grpc_chttp2_outstanding_ping *prev;
Craig Tillerb084d902015-06-12 07:50:02 -0700170} grpc_chttp2_outstanding_ping;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700171
172typedef struct {
173 grpc_status_code status;
174 gpr_slice debug;
Craig Tillerb084d902015-06-12 07:50:02 -0700175} grpc_chttp2_pending_goaway;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700176
Craig Tillerd20efd22015-06-12 16:17:09 -0700177typedef struct {
178 /** data to write next write */
179 gpr_slice_buffer qbuf;
180 /** queued callbacks */
181 grpc_iomgr_closure *pending_closures;
182
183 /** window available for us to send to peer */
184 gpr_uint32 outgoing_window;
Craig Tiller3719f072015-06-12 17:19:51 -0700185 /** window available for peer to send to us - updated after parse */
186 gpr_uint32 incoming_window;
Craig Tillerd20efd22015-06-12 16:17:09 -0700187 /** how much window would we like to have for incoming_window */
188 gpr_uint32 connection_window_target;
189
Craig Tiller3719f072015-06-12 17:19:51 -0700190 /** is this transport a client? */
191 gpr_uint8 is_client;
Craig Tillerd20efd22015-06-12 16:17:09 -0700192 /** are the local settings dirty and need to be sent? */
193 gpr_uint8 dirtied_local_settings;
194 /** have local settings been sent? */
195 gpr_uint8 sent_local_settings;
196 /** bitmask of setting indexes to send out */
197 gpr_uint32 force_send_settings;
198 /** settings values */
199 gpr_uint32 settings[NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS];
200
Craig Tiller606d8742015-06-15 06:58:50 -0700201 /** has there been a connection level error, and have we notified
202 anyone about it? */
203 grpc_chttp2_error_state error_state;
204
205 /** what is the next stream id to be allocated by this peer?
206 copied to next_stream_id in parsing when parsing commences */
207 gpr_uint32 next_stream_id;
208
Craig Tillerd20efd22015-06-12 16:17:09 -0700209 /** last received stream id */
210 gpr_uint32 last_incoming_stream_id;
Craig Tiller3719f072015-06-12 17:19:51 -0700211
212 /** pings awaiting responses */
213 grpc_chttp2_outstanding_ping pings;
Craig Tiller606d8742015-06-15 06:58:50 -0700214 /** next payload for an outgoing ping */
215 gpr_uint64 ping_counter;
216
217 /** concurrent stream count: updated when not parsing,
218 so this is a strict over-estimation on the client */
219 gpr_uint32 concurrent_stream_count;
220
221 /** is there a goaway available? */
222 gpr_uint8 have_goaway;
223 /** what is the debug text of the goaway? */
224 gpr_slice goaway_text;
225 /** what is the status code of the goaway? */
226 grpc_status_code goaway_error;
Craig Tillerd20efd22015-06-12 16:17:09 -0700227} grpc_chttp2_transport_global;
228
229typedef struct {
230 /** data to write now */
231 gpr_slice_buffer outbuf;
232 /** hpack encoding */
233 grpc_chttp2_hpack_compressor hpack_compressor;
234} grpc_chttp2_transport_writing;
235
236struct grpc_chttp2_transport_parsing {
237 /** is this transport a client? (boolean) */
238 gpr_uint8 is_client;
239
240 /** were settings updated? */
241 gpr_uint8 settings_updated;
242 /** was a settings ack received? */
243 gpr_uint8 settings_ack_received;
244 /** was a goaway frame received? */
245 gpr_uint8 goaway_received;
246
Craig Tiller3719f072015-06-12 17:19:51 -0700247 /** initial window change */
248 gpr_int64 initial_window_update;
249
Craig Tillerd20efd22015-06-12 16:17:09 -0700250 /** data to write later - after parsing */
251 gpr_slice_buffer qbuf;
252 /* metadata object cache */
253 grpc_mdstr *str_grpc_timeout;
254 /** parser for headers */
255 grpc_chttp2_hpack_parser hpack_parser;
256 /** simple one shot parsers */
257 union {
258 grpc_chttp2_window_update_parser window_update;
259 grpc_chttp2_settings_parser settings;
260 grpc_chttp2_ping_parser ping;
261 grpc_chttp2_rst_stream_parser rst_stream;
262 } simple;
263 /** parser for goaway frames */
264 grpc_chttp2_goaway_parser goaway_parser;
265
266 /** window available for peer to send to us */
267 gpr_uint32 incoming_window;
268
269 /** next stream id available at the time of beginning parsing */
270 gpr_uint32 next_stream_id;
271 gpr_uint32 last_incoming_stream_id;
272
273 /* deframing */
274 grpc_chttp2_deframe_transport_state deframe_state;
275 gpr_uint8 incoming_frame_type;
276 gpr_uint8 incoming_frame_flags;
277 gpr_uint8 header_eof;
278 gpr_uint32 expect_continuation_stream_id;
279 gpr_uint32 incoming_frame_size;
280 gpr_uint32 incoming_stream_id;
281
282 /* active parser */
283 void *parser_data;
284 grpc_chttp2_stream_parsing *incoming_stream;
285 grpc_chttp2_parse_error (*parser)(void *parser_user_data,
286 grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing,
287 gpr_slice slice, int is_last);
288
289 /* received settings */
290 gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS];
291
292 /* goaway data */
293 grpc_status_code goaway_error;
294 gpr_uint32 goaway_last_stream_index;
295 gpr_slice goaway_text;
Craig Tiller3719f072015-06-12 17:19:51 -0700296
297 gpr_uint64 outgoing_window_update;
298
299 /** pings awaiting responses */
300 grpc_chttp2_outstanding_ping pings;
Craig Tillerd20efd22015-06-12 16:17:09 -0700301};
302
Craig Tillerb084d902015-06-12 07:50:02 -0700303struct grpc_chttp2_transport {
Craig Tiller9b8671c2015-06-12 07:41:54 -0700304 grpc_transport base; /* must be first */
305 grpc_endpoint *ep;
306 grpc_mdctx *metadata_context;
307 gpr_refcount refs;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700308
309 gpr_mu mu;
Craig Tiller606d8742015-06-15 06:58:50 -0700310
311 /** is the transport destroying itself? */
312 gpr_uint8 destroying;
313 /** has the upper layer closed the transport? */
314 gpr_uint8 closed;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700315
Craig Tillerd20efd22015-06-12 16:17:09 -0700316 /** is a thread currently writing */
317 gpr_uint8 writing_active;
Craig Tiller606d8742015-06-15 06:58:50 -0700318 /** is a thread currently parsing */
319 gpr_uint8 parsing_active;
Craig Tillerd20efd22015-06-12 16:17:09 -0700320
Craig Tiller606d8742015-06-15 06:58:50 -0700321 /** is there a read request to the endpoint outstanding? */
322 gpr_uint8 endpoint_reading;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700323
Craig Tiller606d8742015-06-15 06:58:50 -0700324 /** various lists of streams */
Craig Tillerb084d902015-06-12 07:50:02 -0700325 grpc_chttp2_stream_list lists[STREAM_LIST_COUNT];
Craig Tiller9b8671c2015-06-12 07:41:54 -0700326
Craig Tiller606d8742015-06-15 06:58:50 -0700327 /** global state for reading/writing */
Craig Tillerd20efd22015-06-12 16:17:09 -0700328 grpc_chttp2_transport_global global;
Craig Tiller606d8742015-06-15 06:58:50 -0700329 /** state only accessible by the chain of execution that
330 set writing_active=1 */
Craig Tillerd20efd22015-06-12 16:17:09 -0700331 grpc_chttp2_transport_writing writing;
Craig Tiller606d8742015-06-15 06:58:50 -0700332 /** state only accessible by the chain of execution that
333 set parsing_active=1 */
Craig Tillerd20efd22015-06-12 16:17:09 -0700334 grpc_chttp2_transport_parsing parsing;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700335
Craig Tiller606d8742015-06-15 06:58:50 -0700336 /** maps stream id to grpc_chttp2_stream objects;
337 owned by the parsing thread when parsing */
338 grpc_chttp2_stream_map parsing_stream_map;
339
340 /** streams created by the client (possibly during parsing);
341 merged with parsing_stream_map during unlock when no
342 parsing is occurring */
343 grpc_chttp2_stream_map new_stream_map;
344
Craig Tillerd20efd22015-06-12 16:17:09 -0700345 /** closure to execute writing */
346 grpc_iomgr_closure writing_action;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700347
Craig Tiller606d8742015-06-15 06:58:50 -0700348 /** address to place a newly accepted stream - set and unset by
349 grpc_chttp2_parsing_accept_stream; used by init_stream to
350 publish the accepted server stream */
351 grpc_chttp2_stream **accepting_stream;
352
Craig Tiller9b8671c2015-06-12 07:41:54 -0700353 struct {
354 /** is a thread currently performing channel callbacks */
355 gpr_uint8 executing;
356 /** transport channel-level callback */
357 const grpc_transport_callbacks *cb;
358 /** user data for cb calls */
359 void *cb_user_data;
360 /** closure for notifying transport closure */
361 grpc_iomgr_closure notify_closed;
362 } channel_callback;
Craig Tiller606d8742015-06-15 06:58:50 -0700363
364#if 0
365 /* basic state management - what are we doing at the moment? */
366 gpr_uint8 reading;
367 /** are we calling back any grpc_transport_op completion events */
368 gpr_uint8 calling_back_ops;
369 gpr_uint8 destroying;
370 gpr_uint8 closed;
371
372 /* stream indexing */
373 gpr_uint32 next_stream_id;
374
375 /* window management */
376 gpr_uint32 outgoing_window_update;
377
378 /* state for a stream that's not yet been created */
379 grpc_stream_op_buffer new_stream_sopb;
380
381 /* stream ops that need to be destroyed, but outside of the lock */
382 grpc_stream_op_buffer nuke_later_sopb;
383
384 /* pings */
385 gpr_int64 ping_counter;
386
387
388 grpc_chttp2_stream **accepting_stream;
389
390#endif
Craig Tiller9b8671c2015-06-12 07:41:54 -0700391};
392
Craig Tillerd20efd22015-06-12 16:17:09 -0700393typedef struct {
394 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
Craig Tiller9b8671c2015-06-12 07:41:54 -0700395 gpr_uint32 id;
396
Craig Tillerd20efd22015-06-12 16:17:09 -0700397 grpc_iomgr_closure *send_done_closure;
398 grpc_iomgr_closure *recv_done_closure;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700399
Craig Tillerd20efd22015-06-12 16:17:09 -0700400 /** window available for us to send to peer */
401 gpr_int64 outgoing_window;
Craig Tiller3719f072015-06-12 17:19:51 -0700402 /** window available for peer to send to us - updated after parse */
403 gpr_uint32 incoming_window;
Craig Tillerd20efd22015-06-12 16:17:09 -0700404 /** stream ops the transport user would like to send */
405 grpc_stream_op_buffer *outgoing_sopb;
406 /** when the application requests writes be closed, the write_closed is
407 'queued'; when the close is flow controlled into the send path, we are
408 'sending' it; when the write has been performed it is 'sent' */
409 grpc_chttp2_write_state write_state;
410 /** is this stream closed (boolean) */
411 gpr_uint8 read_closed;
Craig Tiller606d8742015-06-15 06:58:50 -0700412
413 /** stream state already published to the upper layer */
414 grpc_stream_state published_state;
415 /** address to publish next stream state to */
416 grpc_stream_state *publish_state;
417 /** pointer to sop buffer to fill in with new stream ops */
418 grpc_stream_op_buffer *incoming_sopb;
Craig Tillerd20efd22015-06-12 16:17:09 -0700419} grpc_chttp2_stream_global;
420
421typedef struct {
422 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
423 gpr_uint32 id;
424 /** sops that have passed flow control to be written */
425 grpc_stream_op_buffer sopb;
426 /** how strongly should we indicate closure with the next write */
427 grpc_chttp2_send_closed send_closed;
428} grpc_chttp2_stream_writing;
429
430struct grpc_chttp2_stream_parsing {
431 /** HTTP2 stream id for this stream, or zero if one has not been assigned */
432 gpr_uint32 id;
433 /** has this stream received a close */
434 gpr_uint8 received_close;
Craig Tillerd20efd22015-06-12 16:17:09 -0700435 /** saw an error on this stream during parsing (it should be cancelled) */
436 gpr_uint8 saw_error;
Craig Tiller3719f072015-06-12 17:19:51 -0700437 /** saw a rst_stream */
438 gpr_uint8 saw_rst_stream;
Craig Tiller606d8742015-06-15 06:58:50 -0700439 /** incoming_window has been reduced by this much during parsing */
440 gpr_uint32 incoming_window_delta;
Craig Tillerd20efd22015-06-12 16:17:09 -0700441 /** window available for peer to send to us */
442 gpr_uint32 incoming_window;
443 /** parsing state for data frames */
444 grpc_chttp2_data_parser data_parser;
Craig Tiller3719f072015-06-12 17:19:51 -0700445 /** reason give to rst_stream */
446 gpr_uint32 rst_stream_reason;
447 /* amount of window given */
448 gpr_uint64 outgoing_window_update;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700449
450 /* incoming metadata */
451 grpc_linked_mdelem *incoming_metadata;
452 size_t incoming_metadata_count;
453 size_t incoming_metadata_capacity;
454 grpc_linked_mdelem *old_incoming_metadata;
455 gpr_timespec incoming_deadline;
Craig Tillerd20efd22015-06-12 16:17:09 -0700456};
457
458struct grpc_chttp2_stream {
459 grpc_chttp2_stream_global global;
460 grpc_chttp2_stream_writing writing;
Craig Tiller606d8742015-06-15 06:58:50 -0700461 grpc_chttp2_stream_parsing parsing;
Craig Tillerd20efd22015-06-12 16:17:09 -0700462
463 grpc_chttp2_stream_link links[STREAM_LIST_COUNT];
464 gpr_uint8 included[STREAM_LIST_COUNT];
Craig Tiller9b8671c2015-06-12 07:41:54 -0700465
Craig Tiller606d8742015-06-15 06:58:50 -0700466#if 0
467 gpr_uint32 outgoing_window_update;
468 gpr_uint8 cancelled;
Craig Tiller9b8671c2015-06-12 07:41:54 -0700469
Craig Tiller9b8671c2015-06-12 07:41:54 -0700470 grpc_stream_state callback_state;
471 grpc_stream_op_buffer callback_sopb;
Craig Tiller606d8742015-06-15 06:58:50 -0700472#endif
Craig Tiller9b8671c2015-06-12 07:41:54 -0700473};
474
Craig Tillerd20efd22015-06-12 16:17:09 -0700475/** Transport writing call flow:
476 chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes are required;
477 if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the writes.
478 Once writes have been completed (meaning another write could potentially be started),
479 grpc_chttp2_terminate_writing is called. This will call grpc_chttp2_cleanup_writing, at which
480 point the write phase is complete. */
481
Craig Tiller3208e392015-06-12 08:17:02 -0700482/** Someone is unlocking the transport mutex: check to see if writes
483 are required, and schedule them if so */
Craig Tillerd20efd22015-06-12 16:17:09 -0700484int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, grpc_chttp2_transport_writing *writing);
485void grpc_chttp2_perform_writes(grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint);
486void grpc_chttp2_terminate_writing(grpc_chttp2_transport_writing *transport_writing, int success);
487void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, grpc_chttp2_transport_writing *writing);
488
489/** Process one slice of incoming data */
Craig Tiller606d8742015-06-15 06:58:50 -0700490void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, grpc_chttp2_transport_parsing *parsing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700491int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, gpr_slice slice);
492void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, grpc_chttp2_transport_parsing *parsing);
493
494/** Get a writable stream
495 \return non-zero if there was a stream available */
496void grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global);
497int grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_writing *transport_writing,
498 grpc_chttp2_stream_global **stream_global, grpc_chttp2_stream_writing **stream_writing);
499
500void grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing *stream_writing);
501int grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport_writing *transport_writing);
502int grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing **stream_writing);
503
504void grpc_chttp2_list_add_written_stream(grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_stream_writing *stream_writing);
505int 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);
506
Craig Tiller606d8742015-06-15 06:58:50 -0700507void grpc_chttp2_list_add_writable_window_update_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global);
Craig Tillerd20efd22015-06-12 16:17:09 -0700508int grpc_chttp2_list_pop_writable_window_update_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global **stream_global);
509
510void grpc_chttp2_list_add_parsing_seen_stream(grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing);
Craig Tiller606d8742015-06-15 06:58:50 -0700511int grpc_chttp2_list_pop_parsing_seen_stream(grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_global **stream_global, grpc_chttp2_stream_parsing **stream_parsing);
Craig Tillerd20efd22015-06-12 16:17:09 -0700512
513void grpc_chttp2_schedule_closure(grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure, int success);
514void grpc_chttp2_read_write_state_changed(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global);
515
516grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
517grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
518
Craig Tiller3719f072015-06-12 17:19:51 -0700519void grpc_chttp2_parsing_add_metadata_batch(grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing);
520
Craig Tillerd20efd22015-06-12 16:17:09 -0700521#define GRPC_CHTTP2_FLOW_CTL_TRACE(a,b,c,d,e) do {} while (0)
522
523#define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
524#define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING)-1)
525
526extern int grpc_http_trace;
527
528#define IF_TRACING(stmt) \
529 if (!(grpc_http_trace)) \
530 ; \
531 else \
532 stmt
Craig Tiller3208e392015-06-12 08:17:02 -0700533
Craig Tiller9b8671c2015-06-12 07:41:54 -0700534#endif