Craig Tiller | 640d3bd | 2015-06-12 07:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
murgatroid99 | 3466c4b | 2016-01-12 10:26:04 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Craig Tiller | 640d3bd | 2015-06-12 07:51:51 -0700 | [diff] [blame] | 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 | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_TRANSPORT_CHTTP2_INTERNAL_H |
| 35 | #define GRPC_CORE_LIB_TRANSPORT_CHTTP2_INTERNAL_H |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 36 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 37 | #include <assert.h> |
yang-g | 55b1b59 | 2016-01-28 12:03:03 -0800 | [diff] [blame] | 38 | #include <stdbool.h> |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 39 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 40 | #include "src/core/iomgr/endpoint.h" |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 41 | #include "src/core/transport/chttp2/frame.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 42 | #include "src/core/transport/chttp2/frame_data.h" |
| 43 | #include "src/core/transport/chttp2/frame_goaway.h" |
| 44 | #include "src/core/transport/chttp2/frame_ping.h" |
| 45 | #include "src/core/transport/chttp2/frame_rst_stream.h" |
| 46 | #include "src/core/transport/chttp2/frame_settings.h" |
| 47 | #include "src/core/transport/chttp2/frame_window_update.h" |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 48 | #include "src/core/transport/chttp2/hpack_encoder.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 49 | #include "src/core/transport/chttp2/hpack_parser.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 50 | #include "src/core/transport/chttp2/incoming_metadata.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 51 | #include "src/core/transport/chttp2/stream_map.h" |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame] | 52 | #include "src/core/transport/connectivity_state.h" |
| 53 | #include "src/core/transport/transport_impl.h" |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 54 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 55 | typedef struct grpc_chttp2_transport grpc_chttp2_transport; |
| 56 | typedef struct grpc_chttp2_stream grpc_chttp2_stream; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 57 | |
| 58 | /* streams are kept in various linked lists depending on what things need to |
| 59 | happen to them... this enum labels each list */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 60 | typedef enum { |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 61 | GRPC_CHTTP2_LIST_ALL_STREAMS, |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 62 | GRPC_CHTTP2_LIST_CHECK_READ_OPS, |
| 63 | GRPC_CHTTP2_LIST_UNANNOUNCED_INCOMING_WINDOW_AVAILABLE, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 64 | GRPC_CHTTP2_LIST_WRITABLE, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 65 | GRPC_CHTTP2_LIST_WRITING, |
| 66 | GRPC_CHTTP2_LIST_WRITTEN, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 67 | GRPC_CHTTP2_LIST_PARSING_SEEN, |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 68 | GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING, |
Craig Tiller | abb2e3d | 2015-12-15 06:23:59 -0800 | [diff] [blame] | 69 | GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_WRITING, |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 70 | GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT, |
yang-g | 348f3a2 | 2016-01-27 16:17:32 -0800 | [diff] [blame] | 71 | /* streams waiting for the outgoing window in the writing path, they will be |
| 72 | * merged to the stalled list or writable list under transport lock. */ |
| 73 | GRPC_CHTTP2_LIST_WRITING_STALLED_BY_TRANSPORT, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 74 | /** streams that are waiting to start because there are too many concurrent |
| 75 | streams on the connection */ |
| 76 | GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY, |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 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 */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 81 | typedef enum { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 82 | /* prefix: one entry per http2 connection prefix byte */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 83 | GRPC_DTS_CLIENT_PREFIX_0 = 0, |
| 84 | GRPC_DTS_CLIENT_PREFIX_1, |
| 85 | GRPC_DTS_CLIENT_PREFIX_2, |
| 86 | GRPC_DTS_CLIENT_PREFIX_3, |
| 87 | GRPC_DTS_CLIENT_PREFIX_4, |
| 88 | GRPC_DTS_CLIENT_PREFIX_5, |
| 89 | GRPC_DTS_CLIENT_PREFIX_6, |
| 90 | GRPC_DTS_CLIENT_PREFIX_7, |
| 91 | GRPC_DTS_CLIENT_PREFIX_8, |
| 92 | GRPC_DTS_CLIENT_PREFIX_9, |
| 93 | GRPC_DTS_CLIENT_PREFIX_10, |
| 94 | GRPC_DTS_CLIENT_PREFIX_11, |
| 95 | GRPC_DTS_CLIENT_PREFIX_12, |
| 96 | GRPC_DTS_CLIENT_PREFIX_13, |
| 97 | GRPC_DTS_CLIENT_PREFIX_14, |
| 98 | GRPC_DTS_CLIENT_PREFIX_15, |
| 99 | GRPC_DTS_CLIENT_PREFIX_16, |
| 100 | GRPC_DTS_CLIENT_PREFIX_17, |
| 101 | GRPC_DTS_CLIENT_PREFIX_18, |
| 102 | GRPC_DTS_CLIENT_PREFIX_19, |
| 103 | GRPC_DTS_CLIENT_PREFIX_20, |
| 104 | GRPC_DTS_CLIENT_PREFIX_21, |
| 105 | GRPC_DTS_CLIENT_PREFIX_22, |
| 106 | GRPC_DTS_CLIENT_PREFIX_23, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 107 | /* frame header byte 0... */ |
| 108 | /* must follow from the prefix states */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 109 | GRPC_DTS_FH_0, |
| 110 | GRPC_DTS_FH_1, |
| 111 | GRPC_DTS_FH_2, |
| 112 | GRPC_DTS_FH_3, |
| 113 | GRPC_DTS_FH_4, |
| 114 | GRPC_DTS_FH_5, |
| 115 | GRPC_DTS_FH_6, |
| 116 | GRPC_DTS_FH_7, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 117 | /* ... frame header byte 8 */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 118 | GRPC_DTS_FH_8, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 119 | /* inside a http2 frame */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 120 | GRPC_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 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 123 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 124 | grpc_chttp2_stream *head; |
| 125 | grpc_chttp2_stream *tail; |
| 126 | } grpc_chttp2_stream_list; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 127 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 128 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 129 | grpc_chttp2_stream *next; |
| 130 | grpc_chttp2_stream *prev; |
| 131 | } grpc_chttp2_stream_link; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 132 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 133 | /* We keep several sets of connection wide parameters */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 134 | typedef enum { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 135 | /* The settings our peer has asked for (and we have acked) */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 136 | GRPC_PEER_SETTINGS = 0, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 137 | /* The settings we'd like to have */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 138 | GRPC_LOCAL_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 139 | /* The settings we've published to our peer */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 140 | GRPC_SENT_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 141 | /* The settings the peer has acked */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 142 | GRPC_ACKED_SETTINGS, |
| 143 | GRPC_NUM_SETTING_SETS |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 144 | } grpc_chttp2_setting_set; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 145 | |
| 146 | /* Outstanding ping request data */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 147 | typedef struct grpc_chttp2_outstanding_ping { |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 148 | uint8_t id[8]; |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 149 | grpc_closure *on_recv; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 150 | struct grpc_chttp2_outstanding_ping *next; |
| 151 | struct grpc_chttp2_outstanding_ping *prev; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 152 | } grpc_chttp2_outstanding_ping; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 153 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 154 | /* forward declared in frame_data.h */ |
| 155 | struct grpc_chttp2_incoming_byte_stream { |
| 156 | grpc_byte_stream base; |
| 157 | gpr_refcount refs; |
| 158 | struct grpc_chttp2_incoming_byte_stream *next_message; |
Craig Tiller | 38edec6 | 2015-12-14 15:01:29 -0800 | [diff] [blame] | 159 | int failed; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 160 | |
| 161 | grpc_chttp2_transport *transport; |
| 162 | grpc_chttp2_stream *stream; |
| 163 | int is_tail; |
| 164 | gpr_slice_buffer slices; |
| 165 | grpc_closure *on_next; |
| 166 | gpr_slice *next; |
| 167 | }; |
| 168 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 169 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 170 | /** data to write next write */ |
| 171 | gpr_slice_buffer qbuf; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 172 | |
| 173 | /** window available for us to send to peer */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 174 | int64_t outgoing_window; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 175 | /** window available to announce to peer */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 176 | int64_t announce_incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 177 | /** how much window would we like to have for incoming_window */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 178 | uint32_t connection_window_target; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 179 | |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 180 | /** have we seen a goaway */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 181 | uint8_t seen_goaway; |
Craig Tiller | 9188d7a | 2015-07-05 12:44:37 -0700 | [diff] [blame] | 182 | /** have we sent a goaway */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 183 | uint8_t sent_goaway; |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 184 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 185 | /** is this transport a client? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 186 | uint8_t is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 187 | /** are the local settings dirty and need to be sent? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 188 | uint8_t dirtied_local_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 189 | /** have local settings been sent? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 190 | uint8_t sent_local_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 191 | /** bitmask of setting indexes to send out */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 192 | uint32_t force_send_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 193 | /** settings values */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 194 | uint32_t settings[GRPC_NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS]; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 195 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 196 | /** what is the next stream id to be allocated by this peer? |
| 197 | copied to next_stream_id in parsing when parsing commences */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 198 | uint32_t next_stream_id; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 199 | |
Craig Tiller | a8d6809 | 2015-11-17 08:02:29 -0800 | [diff] [blame] | 200 | /** how far to lookahead in a stream? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 201 | uint32_t stream_lookahead; |
Craig Tiller | a8d6809 | 2015-11-17 08:02:29 -0800 | [diff] [blame] | 202 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 203 | /** last received stream id */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 204 | uint32_t last_incoming_stream_id; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 205 | |
| 206 | /** pings awaiting responses */ |
| 207 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 208 | /** next payload for an outgoing ping */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 209 | uint64_t ping_counter; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 210 | |
| 211 | /** concurrent stream count: updated when not parsing, |
| 212 | so this is a strict over-estimation on the client */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 213 | uint32_t concurrent_stream_count; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 214 | } grpc_chttp2_transport_global; |
| 215 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 216 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 217 | /** data to write now */ |
| 218 | gpr_slice_buffer outbuf; |
| 219 | /** hpack encoding */ |
| 220 | grpc_chttp2_hpack_compressor hpack_compressor; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 221 | int64_t outgoing_window; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 222 | /** is this a client? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 223 | uint8_t is_client; |
Craig Tiller | b029859 | 2015-08-27 07:38:01 -0700 | [diff] [blame] | 224 | /** callback for when writing is done */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 225 | grpc_closure done_cb; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 226 | } grpc_chttp2_transport_writing; |
| 227 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 228 | struct grpc_chttp2_transport_parsing { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 229 | /** is this transport a client? (boolean) */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 230 | uint8_t is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 231 | |
| 232 | /** were settings updated? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 233 | uint8_t settings_updated; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 234 | /** was a settings ack received? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 235 | uint8_t settings_ack_received; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 236 | /** was a goaway frame received? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 237 | uint8_t goaway_received; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 238 | |
Craig Tiller | 027a74c | 2015-11-10 08:37:46 +0000 | [diff] [blame] | 239 | /** the last sent max_table_size setting */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 240 | uint32_t last_sent_max_table_size; |
Craig Tiller | 027a74c | 2015-11-10 08:37:46 +0000 | [diff] [blame] | 241 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 242 | /** initial window change */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 243 | int64_t initial_window_update; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 244 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 245 | /** data to write later - after parsing */ |
| 246 | gpr_slice_buffer qbuf; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 247 | /** parser for headers */ |
| 248 | grpc_chttp2_hpack_parser hpack_parser; |
| 249 | /** simple one shot parsers */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 250 | union { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 251 | grpc_chttp2_window_update_parser window_update; |
| 252 | grpc_chttp2_settings_parser settings; |
| 253 | grpc_chttp2_ping_parser ping; |
| 254 | grpc_chttp2_rst_stream_parser rst_stream; |
| 255 | } simple; |
| 256 | /** parser for goaway frames */ |
| 257 | grpc_chttp2_goaway_parser goaway_parser; |
| 258 | |
| 259 | /** window available for peer to send to us */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 260 | int64_t incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 261 | |
| 262 | /** next stream id available at the time of beginning parsing */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 263 | uint32_t next_stream_id; |
| 264 | uint32_t last_incoming_stream_id; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 265 | |
| 266 | /* deframing */ |
| 267 | grpc_chttp2_deframe_transport_state deframe_state; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 268 | uint8_t incoming_frame_type; |
| 269 | uint8_t incoming_frame_flags; |
| 270 | uint8_t header_eof; |
| 271 | uint32_t expect_continuation_stream_id; |
| 272 | uint32_t incoming_frame_size; |
| 273 | uint32_t incoming_stream_id; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 274 | |
| 275 | /* active parser */ |
| 276 | void *parser_data; |
| 277 | grpc_chttp2_stream_parsing *incoming_stream; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 278 | grpc_chttp2_parse_error (*parser)( |
| 279 | grpc_exec_ctx *exec_ctx, void *parser_user_data, |
| 280 | grpc_chttp2_transport_parsing *transport_parsing, |
| 281 | grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 282 | |
| 283 | /* received settings */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 284 | uint32_t settings[GRPC_CHTTP2_NUM_SETTINGS]; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 285 | |
| 286 | /* goaway data */ |
| 287 | grpc_status_code goaway_error; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 288 | uint32_t goaway_last_stream_index; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 289 | gpr_slice goaway_text; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 290 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 291 | int64_t outgoing_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 292 | }; |
| 293 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 294 | struct grpc_chttp2_transport { |
| 295 | grpc_transport base; /* must be first */ |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 296 | grpc_endpoint *ep; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 297 | gpr_refcount refs; |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 298 | char *peer_string; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 299 | |
Craig Tiller | 9f80fcf | 2015-08-28 08:22:48 -0700 | [diff] [blame] | 300 | /** when this drops to zero it's safe to shutdown the endpoint */ |
| 301 | gpr_refcount shutdown_ep_refs; |
| 302 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 303 | gpr_mu mu; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 304 | |
| 305 | /** is the transport destroying itself? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 306 | uint8_t destroying; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 307 | /** has the upper layer closed the transport? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 308 | uint8_t closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 309 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 310 | /** is a thread currently writing */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 311 | uint8_t writing_active; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 312 | /** is a thread currently parsing */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 313 | uint8_t parsing_active; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 314 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 315 | /** is there a read request to the endpoint outstanding? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 316 | uint8_t endpoint_reading; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 317 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 318 | /** various lists of streams */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 319 | grpc_chttp2_stream_list lists[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 320 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 321 | /** global state for reading/writing */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 322 | grpc_chttp2_transport_global global; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 323 | /** state only accessible by the chain of execution that |
| 324 | set writing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 325 | grpc_chttp2_transport_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 326 | /** state only accessible by the chain of execution that |
| 327 | set parsing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 328 | grpc_chttp2_transport_parsing parsing; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 329 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 330 | /** maps stream id to grpc_chttp2_stream objects; |
| 331 | owned by the parsing thread when parsing */ |
| 332 | grpc_chttp2_stream_map parsing_stream_map; |
| 333 | |
| 334 | /** streams created by the client (possibly during parsing); |
| 335 | merged with parsing_stream_map during unlock when no |
| 336 | parsing is occurring */ |
| 337 | grpc_chttp2_stream_map new_stream_map; |
| 338 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 339 | /** closure to execute writing */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 340 | grpc_closure writing_action; |
Craig Tiller | b029859 | 2015-08-27 07:38:01 -0700 | [diff] [blame] | 341 | /** closure to finish reading from the endpoint */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 342 | grpc_closure recv_data; |
Craig Tiller | b029859 | 2015-08-27 07:38:01 -0700 | [diff] [blame] | 343 | |
| 344 | /** incoming read bytes */ |
| 345 | gpr_slice_buffer read_buffer; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 346 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 347 | /** address to place a newly accepted stream - set and unset by |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 348 | grpc_chttp2_parsing_accept_stream; used by init_stream to |
| 349 | publish the accepted server stream */ |
| 350 | grpc_chttp2_stream **accepting_stream; |
| 351 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 352 | struct { |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 353 | /* accept stream callback */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 354 | void (*accept_stream)(grpc_exec_ctx *exec_ctx, void *user_data, |
| 355 | grpc_transport *transport, const void *server_data); |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 356 | void *accept_stream_user_data; |
| 357 | |
| 358 | /** connectivity tracking */ |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame] | 359 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 360 | } channel_callback; |
Craig Tiller | d7f12e3 | 2016-03-03 10:08:31 -0800 | [diff] [blame] | 361 | |
| 362 | /** Transport op to be applied post-parsing */ |
| 363 | grpc_transport_op *post_parsing_op; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 366 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 367 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 368 | uint32_t id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 369 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 370 | /** window available for us to send to peer */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 371 | int64_t outgoing_window; |
Craig Tiller | 27166a6 | 2015-07-05 21:08:33 -0700 | [diff] [blame] | 372 | /** The number of bytes the upper layers have offered to receive. |
| 373 | As the upper layer offers more bytes, this value increases. |
| 374 | As bytes are read, this value decreases. */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 375 | uint32_t max_recv_bytes; |
Craig Tiller | 27166a6 | 2015-07-05 21:08:33 -0700 | [diff] [blame] | 376 | /** The number of bytes the upper layer has offered to read but we have |
| 377 | not yet announced to HTTP2 flow control. |
| 378 | As the upper layers offer to read more bytes, this value increases. |
| 379 | As we advertise incoming flow control window, this value decreases. */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 380 | uint32_t unannounced_incoming_window_for_parse; |
| 381 | uint32_t unannounced_incoming_window_for_writing; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 382 | /** things the upper layers would like to send */ |
| 383 | grpc_metadata_batch *send_initial_metadata; |
| 384 | grpc_closure *send_initial_metadata_finished; |
| 385 | grpc_byte_stream *send_message; |
| 386 | grpc_closure *send_message_finished; |
| 387 | grpc_metadata_batch *send_trailing_metadata; |
| 388 | grpc_closure *send_trailing_metadata_finished; |
| 389 | |
| 390 | grpc_metadata_batch *recv_initial_metadata; |
Craig Tiller | a44cbfc | 2016-02-03 16:02:49 -0800 | [diff] [blame] | 391 | grpc_closure *recv_initial_metadata_ready; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 392 | grpc_byte_stream **recv_message; |
| 393 | grpc_closure *recv_message_ready; |
| 394 | grpc_metadata_batch *recv_trailing_metadata; |
| 395 | grpc_closure *recv_trailing_metadata_finished; |
| 396 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 397 | /** when the application requests writes be closed, the write_closed is |
| 398 | 'queued'; when the close is flow controlled into the send path, we are |
| 399 | 'sending' it; when the write has been performed it is 'sent' */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 400 | uint8_t write_closed; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 401 | /** is this stream reading half-closed (boolean) */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 402 | uint8_t read_closed; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 403 | /** is this stream in the stream map? (boolean) */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 404 | uint8_t in_stream_map; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 405 | /** has this stream seen an error? if 1, then pending incoming frames |
| 406 | can be thrown away */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 407 | uint8_t seen_error; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 408 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 409 | uint8_t published_initial_metadata; |
| 410 | uint8_t published_trailing_metadata; |
| 411 | uint8_t faked_trailing_metadata; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 412 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 413 | grpc_chttp2_incoming_metadata_buffer received_initial_metadata; |
| 414 | grpc_chttp2_incoming_metadata_buffer received_trailing_metadata; |
| 415 | |
| 416 | grpc_chttp2_incoming_frame_queue incoming_frames; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 417 | } grpc_chttp2_stream_global; |
| 418 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 419 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 420 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 421 | uint32_t id; |
| 422 | uint8_t fetching; |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 423 | bool sent_initial_metadata; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 424 | uint8_t sent_message; |
| 425 | uint8_t sent_trailing_metadata; |
| 426 | uint8_t read_closed; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 427 | /** send this initial metadata */ |
| 428 | grpc_metadata_batch *send_initial_metadata; |
| 429 | grpc_byte_stream *send_message; |
| 430 | grpc_metadata_batch *send_trailing_metadata; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 431 | int64_t outgoing_window; |
Craig Tiller | 8631652 | 2015-07-15 11:35:07 -0700 | [diff] [blame] | 432 | /** how much window should we announce? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 433 | uint32_t announce_window; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 434 | gpr_slice_buffer flow_controlled_buffer; |
| 435 | gpr_slice fetching_slice; |
| 436 | size_t stream_fetched; |
| 437 | grpc_closure finished_fetch; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 438 | } grpc_chttp2_stream_writing; |
| 439 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 440 | struct grpc_chttp2_stream_parsing { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 441 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 442 | uint32_t id; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 443 | /** has this stream received a close */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 444 | uint8_t received_close; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 445 | /** saw a rst_stream */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 446 | uint8_t saw_rst_stream; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 447 | /** how many header frames have we received? */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 448 | uint8_t header_frames_received; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 449 | /** which metadata did we get (on this parse) */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 450 | uint8_t got_metadata_on_parse[2]; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 451 | /** should we raise the seen_error flag in transport_global */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 452 | uint8_t seen_error; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 453 | /** window available for peer to send to us */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 454 | int64_t incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 455 | /** parsing state for data frames */ |
| 456 | grpc_chttp2_data_parser data_parser; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 457 | /** reason give to rst_stream */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 458 | uint32_t rst_stream_reason; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 459 | /** amount of window given */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 460 | int64_t outgoing_window; |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 461 | /** number of bytes received - reset at end of parse thread execution */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 462 | int64_t received_bytes; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 463 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 464 | /** incoming metadata */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 465 | grpc_chttp2_incoming_metadata_buffer metadata_buffer[2]; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 466 | }; |
| 467 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 468 | struct grpc_chttp2_stream { |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 469 | grpc_stream_refcount *refcount; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 470 | grpc_chttp2_stream_global global; |
| 471 | grpc_chttp2_stream_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 472 | grpc_chttp2_stream_parsing parsing; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 473 | |
| 474 | grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 475 | uint8_t included[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 476 | }; |
| 477 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 478 | /** Transport writing call flow: |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 479 | chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes |
| 480 | are required; |
| 481 | if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the |
| 482 | writes. |
| 483 | Once writes have been completed (meaning another write could potentially be |
| 484 | started), |
| 485 | grpc_chttp2_terminate_writing is called. This will call |
| 486 | grpc_chttp2_cleanup_writing, at which |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 487 | point the write phase is complete. */ |
| 488 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 489 | /** Someone is unlocking the transport mutex: check to see if writes |
| 490 | are required, and schedule them if so */ |
yang-g | 276e32d | 2016-02-22 13:15:30 -0800 | [diff] [blame] | 491 | int grpc_chttp2_unlocking_check_writes(grpc_exec_ctx *exec_ctx, |
| 492 | grpc_chttp2_transport_global *global, |
Craig Tiller | 027a74c | 2015-11-10 08:37:46 +0000 | [diff] [blame] | 493 | grpc_chttp2_transport_writing *writing, |
| 494 | int is_parsing); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 495 | void grpc_chttp2_perform_writes( |
| 496 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_writing *transport_writing, |
| 497 | grpc_endpoint *endpoint); |
| 498 | void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 499 | void *transport_writing, bool success); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 500 | void grpc_chttp2_cleanup_writing(grpc_exec_ctx *exec_ctx, |
| 501 | grpc_chttp2_transport_global *global, |
| 502 | grpc_chttp2_transport_writing *writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 503 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 504 | void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, |
| 505 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 506 | /** Process one slice of incoming data; return 1 if the connection is still |
| 507 | viable after reading, or 0 if the connection should be torn down */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 508 | int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, |
| 509 | grpc_chttp2_transport_parsing *transport_parsing, |
| 510 | gpr_slice slice); |
| 511 | void grpc_chttp2_publish_reads(grpc_exec_ctx *exec_ctx, |
| 512 | grpc_chttp2_transport_global *global, |
| 513 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 514 | |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 515 | bool grpc_chttp2_list_add_writable_stream( |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 516 | grpc_chttp2_transport_global *transport_global, |
| 517 | grpc_chttp2_stream_global *stream_global); |
yang-g | 348f3a2 | 2016-01-27 16:17:32 -0800 | [diff] [blame] | 518 | /** Get a writable stream |
| 519 | returns non-zero if there was a stream available */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 520 | int grpc_chttp2_list_pop_writable_stream( |
| 521 | grpc_chttp2_transport_global *transport_global, |
| 522 | grpc_chttp2_transport_writing *transport_writing, |
| 523 | grpc_chttp2_stream_global **stream_global, |
| 524 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 525 | bool grpc_chttp2_list_remove_writable_stream( |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 526 | grpc_chttp2_transport_global *transport_global, |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 527 | grpc_chttp2_stream_global *stream_global) GRPC_MUST_USE_RESULT; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 528 | |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 529 | void grpc_chttp2_list_add_writing_stream( |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 530 | grpc_chttp2_transport_writing *transport_writing, |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 531 | grpc_chttp2_stream_writing *stream_writing); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 532 | int grpc_chttp2_list_have_writing_streams( |
| 533 | grpc_chttp2_transport_writing *transport_writing); |
| 534 | int grpc_chttp2_list_pop_writing_stream( |
| 535 | grpc_chttp2_transport_writing *transport_writing, |
| 536 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 537 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 538 | void grpc_chttp2_list_add_written_stream( |
| 539 | grpc_chttp2_transport_writing *transport_writing, |
| 540 | grpc_chttp2_stream_writing *stream_writing); |
| 541 | int grpc_chttp2_list_pop_written_stream( |
| 542 | grpc_chttp2_transport_global *transport_global, |
| 543 | grpc_chttp2_transport_writing *transport_writing, |
| 544 | grpc_chttp2_stream_global **stream_global, |
| 545 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 546 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 547 | void grpc_chttp2_list_add_parsing_seen_stream( |
| 548 | grpc_chttp2_transport_parsing *transport_parsing, |
| 549 | grpc_chttp2_stream_parsing *stream_parsing); |
| 550 | int grpc_chttp2_list_pop_parsing_seen_stream( |
| 551 | grpc_chttp2_transport_global *transport_global, |
| 552 | grpc_chttp2_transport_parsing *transport_parsing, |
| 553 | grpc_chttp2_stream_global **stream_global, |
| 554 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 555 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 556 | void grpc_chttp2_list_add_waiting_for_concurrency( |
| 557 | grpc_chttp2_transport_global *transport_global, |
| 558 | grpc_chttp2_stream_global *stream_global); |
| 559 | int grpc_chttp2_list_pop_waiting_for_concurrency( |
| 560 | grpc_chttp2_transport_global *transport_global, |
| 561 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 562 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 563 | void grpc_chttp2_list_add_check_read_ops( |
| 564 | grpc_chttp2_transport_global *transport_global, |
| 565 | grpc_chttp2_stream_global *stream_global); |
| 566 | int grpc_chttp2_list_pop_check_read_ops( |
| 567 | grpc_chttp2_transport_global *transport_global, |
| 568 | grpc_chttp2_stream_global **stream_global); |
| 569 | |
yang-g | 348f3a2 | 2016-01-27 16:17:32 -0800 | [diff] [blame] | 570 | void grpc_chttp2_list_add_writing_stalled_by_transport( |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 571 | grpc_chttp2_transport_writing *transport_writing, |
| 572 | grpc_chttp2_stream_writing *stream_writing); |
yang-g | 348f3a2 | 2016-01-27 16:17:32 -0800 | [diff] [blame] | 573 | void grpc_chttp2_list_flush_writing_stalled_by_transport( |
yang-g | 276e32d | 2016-02-22 13:15:30 -0800 | [diff] [blame] | 574 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_writing *transport_writing, |
| 575 | bool is_window_available); |
yang-g | 348f3a2 | 2016-01-27 16:17:32 -0800 | [diff] [blame] | 576 | |
yang-g | 276e32d | 2016-02-22 13:15:30 -0800 | [diff] [blame] | 577 | void grpc_chttp2_list_add_stalled_by_transport( |
| 578 | grpc_chttp2_transport_writing *transport_writing, |
| 579 | grpc_chttp2_stream_writing *stream_writing); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 580 | int grpc_chttp2_list_pop_stalled_by_transport( |
| 581 | grpc_chttp2_transport_global *transport_global, |
| 582 | grpc_chttp2_stream_global **stream_global); |
yang-g | 0db9032 | 2015-12-21 13:38:56 -0800 | [diff] [blame] | 583 | void grpc_chttp2_list_remove_stalled_by_transport( |
| 584 | grpc_chttp2_transport_global *transport_global, |
| 585 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 586 | |
| 587 | void grpc_chttp2_list_add_unannounced_incoming_window_available( |
| 588 | grpc_chttp2_transport_global *transport_global, |
| 589 | grpc_chttp2_stream_global *stream_global); |
| 590 | void grpc_chttp2_list_remove_unannounced_incoming_window_available( |
| 591 | grpc_chttp2_transport_global *transport_global, |
| 592 | grpc_chttp2_stream_global *stream_global); |
| 593 | int grpc_chttp2_list_pop_unannounced_incoming_window_available( |
| 594 | grpc_chttp2_transport_global *transport_global, |
| 595 | grpc_chttp2_transport_parsing *transport_parsing, |
| 596 | grpc_chttp2_stream_global **stream_global, |
| 597 | grpc_chttp2_stream_parsing **stream_parsing); |
| 598 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 599 | void grpc_chttp2_list_add_closed_waiting_for_parsing( |
| 600 | grpc_chttp2_transport_global *transport_global, |
| 601 | grpc_chttp2_stream_global *stream_global); |
| 602 | int grpc_chttp2_list_pop_closed_waiting_for_parsing( |
| 603 | grpc_chttp2_transport_global *transport_global, |
| 604 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 605 | |
Craig Tiller | abb2e3d | 2015-12-15 06:23:59 -0800 | [diff] [blame] | 606 | void grpc_chttp2_list_add_closed_waiting_for_writing( |
| 607 | grpc_chttp2_transport_global *transport_global, |
| 608 | grpc_chttp2_stream_global *stream_global); |
| 609 | int grpc_chttp2_list_pop_closed_waiting_for_writing( |
| 610 | grpc_chttp2_transport_global *transport_global, |
| 611 | grpc_chttp2_stream_global **stream_global); |
| 612 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 613 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream( |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 614 | grpc_chttp2_transport_parsing *transport_parsing, uint32_t id); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 615 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream( |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 616 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 617 | uint32_t id); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 618 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 619 | void grpc_chttp2_add_incoming_goaway( |
| 620 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 621 | uint32_t goaway_error, gpr_slice goaway_text); |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 622 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 623 | void grpc_chttp2_register_stream(grpc_chttp2_transport *t, |
| 624 | grpc_chttp2_stream *s); |
Craig Tiller | 9188d7a | 2015-07-05 12:44:37 -0700 | [diff] [blame] | 625 | /* returns 1 if this is the last stream, 0 otherwise */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 626 | int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, |
| 627 | grpc_chttp2_stream *s) GRPC_MUST_USE_RESULT; |
| 628 | int grpc_chttp2_has_streams(grpc_chttp2_transport *t); |
| 629 | void grpc_chttp2_for_all_streams( |
| 630 | grpc_chttp2_transport_global *transport_global, void *user_data, |
| 631 | void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, |
| 632 | grpc_chttp2_stream_global *stream_global)); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 633 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 634 | void grpc_chttp2_parsing_become_skip_parser( |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 635 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); |
| 636 | |
| 637 | void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, |
| 638 | grpc_closure **pclosure, int success); |
Craig Tiller | 66abdaa | 2015-06-17 08:00:39 -0700 | [diff] [blame] | 639 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 640 | #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] | 641 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ |
| 642 | (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 643 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 644 | extern int grpc_http_trace; |
| 645 | extern int grpc_flowctl_trace; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 646 | |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 647 | #define GRPC_CHTTP2_IF_TRACING(stmt) \ |
| 648 | if (!(grpc_http_trace)) \ |
| 649 | ; \ |
| 650 | else \ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 651 | stmt |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 652 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 653 | typedef enum { |
| 654 | GRPC_CHTTP2_FLOWCTL_MOVE, |
| 655 | GRPC_CHTTP2_FLOWCTL_CREDIT, |
| 656 | GRPC_CHTTP2_FLOWCTL_DEBIT |
| 657 | } grpc_chttp2_flowctl_op; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 658 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 659 | #define GRPC_CHTTP2_FLOW_MOVE_COMMON(phase, transport, id1, id2, dst_context, \ |
| 660 | dst_var, src_context, src_var) \ |
| 661 | do { \ |
| 662 | assert(id1 == id2); \ |
| 663 | if (grpc_flowctl_trace) { \ |
| 664 | grpc_chttp2_flowctl_trace( \ |
| 665 | __FILE__, __LINE__, phase, GRPC_CHTTP2_FLOWCTL_MOVE, #dst_context, \ |
| 666 | #dst_var, #src_context, #src_var, transport->is_client, id1, \ |
| 667 | dst_context->dst_var, src_context->src_var); \ |
| 668 | } \ |
| 669 | dst_context->dst_var += src_context->src_var; \ |
| 670 | src_context->src_var = 0; \ |
| 671 | } while (0) |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 672 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 673 | #define GRPC_CHTTP2_FLOW_MOVE_STREAM(phase, transport, dst_context, dst_var, \ |
| 674 | src_context, src_var) \ |
| 675 | GRPC_CHTTP2_FLOW_MOVE_COMMON(phase, transport, dst_context->id, \ |
| 676 | src_context->id, dst_context, dst_var, \ |
| 677 | src_context, src_var) |
| 678 | #define GRPC_CHTTP2_FLOW_MOVE_TRANSPORT(phase, dst_context, dst_var, \ |
| 679 | src_context, src_var) \ |
| 680 | GRPC_CHTTP2_FLOW_MOVE_COMMON(phase, dst_context, 0, 0, dst_context, dst_var, \ |
| 681 | src_context, src_var) |
| 682 | |
| 683 | #define GRPC_CHTTP2_FLOW_CREDIT_COMMON(phase, transport, id, dst_context, \ |
| 684 | dst_var, amount) \ |
| 685 | do { \ |
| 686 | if (grpc_flowctl_trace) { \ |
| 687 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, phase, \ |
| 688 | GRPC_CHTTP2_FLOWCTL_CREDIT, #dst_context, \ |
| 689 | #dst_var, NULL, #amount, transport->is_client, \ |
| 690 | id, dst_context->dst_var, amount); \ |
| 691 | } \ |
| 692 | dst_context->dst_var += amount; \ |
| 693 | } while (0) |
| 694 | |
| 695 | #define GRPC_CHTTP2_FLOW_CREDIT_STREAM(phase, transport, dst_context, dst_var, \ |
| 696 | amount) \ |
| 697 | GRPC_CHTTP2_FLOW_CREDIT_COMMON(phase, transport, dst_context->id, \ |
| 698 | dst_context, dst_var, amount) |
| 699 | #define GRPC_CHTTP2_FLOW_CREDIT_TRANSPORT(phase, dst_context, dst_var, amount) \ |
| 700 | GRPC_CHTTP2_FLOW_CREDIT_COMMON(phase, dst_context, 0, dst_context, dst_var, \ |
| 701 | amount) |
| 702 | |
| 703 | #define GRPC_CHTTP2_FLOW_DEBIT_COMMON(phase, transport, id, dst_context, \ |
| 704 | dst_var, amount) \ |
| 705 | do { \ |
| 706 | if (grpc_flowctl_trace) { \ |
| 707 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, phase, \ |
| 708 | GRPC_CHTTP2_FLOWCTL_DEBIT, #dst_context, \ |
| 709 | #dst_var, NULL, #amount, transport->is_client, \ |
| 710 | id, dst_context->dst_var, amount); \ |
| 711 | } \ |
| 712 | dst_context->dst_var -= amount; \ |
| 713 | } while (0) |
| 714 | |
| 715 | #define GRPC_CHTTP2_FLOW_DEBIT_STREAM(phase, transport, dst_context, dst_var, \ |
| 716 | amount) \ |
| 717 | GRPC_CHTTP2_FLOW_DEBIT_COMMON(phase, transport, dst_context->id, \ |
| 718 | dst_context, dst_var, amount) |
| 719 | #define GRPC_CHTTP2_FLOW_DEBIT_TRANSPORT(phase, dst_context, dst_var, amount) \ |
| 720 | GRPC_CHTTP2_FLOW_DEBIT_COMMON(phase, dst_context, 0, dst_context, dst_var, \ |
| 721 | amount) |
| 722 | |
| 723 | void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase, |
| 724 | grpc_chttp2_flowctl_op op, const char *context1, |
| 725 | const char *var1, const char *context2, |
| 726 | const char *var2, int is_client, |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 727 | uint32_t stream_id, int64_t val1, int64_t val2); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 728 | |
| 729 | void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, |
| 730 | grpc_chttp2_transport_global *transport_global, |
| 731 | grpc_chttp2_stream_global *stream, |
| 732 | grpc_status_code status, gpr_slice *details); |
| 733 | void grpc_chttp2_mark_stream_closed( |
| 734 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, |
| 735 | grpc_chttp2_stream_global *stream_global, int close_reads, |
| 736 | int close_writes); |
| 737 | void grpc_chttp2_start_writing(grpc_exec_ctx *exec_ctx, |
| 738 | grpc_chttp2_transport_global *transport_global); |
| 739 | |
| 740 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
| 741 | #define GRPC_CHTTP2_STREAM_REF(stream_global, reason) \ |
| 742 | grpc_chttp2_stream_ref(stream_global, reason) |
| 743 | #define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream_global, reason) \ |
| 744 | grpc_chttp2_stream_unref(exec_ctx, stream_global, reason) |
| 745 | void grpc_chttp2_stream_ref(grpc_chttp2_stream_global *stream_global, |
| 746 | const char *reason); |
| 747 | void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, |
| 748 | grpc_chttp2_stream_global *stream_global, |
| 749 | const char *reason); |
| 750 | #else |
| 751 | #define GRPC_CHTTP2_STREAM_REF(stream_global, reason) \ |
| 752 | grpc_chttp2_stream_ref(stream_global) |
| 753 | #define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream_global, reason) \ |
| 754 | grpc_chttp2_stream_unref(exec_ctx, stream_global) |
| 755 | void grpc_chttp2_stream_ref(grpc_chttp2_stream_global *stream_global); |
| 756 | void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, |
| 757 | grpc_chttp2_stream_global *stream_global); |
| 758 | #endif |
| 759 | |
| 760 | grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create( |
Craig Tiller | 20df14e | 2015-11-06 09:10:49 -0800 | [diff] [blame] | 761 | grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 762 | grpc_chttp2_stream_parsing *stream_parsing, uint32_t frame_size, |
| 763 | uint32_t flags, grpc_chttp2_incoming_frame_queue *add_to_queue); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 764 | void grpc_chttp2_incoming_byte_stream_push(grpc_exec_ctx *exec_ctx, |
| 765 | grpc_chttp2_incoming_byte_stream *bs, |
| 766 | gpr_slice slice); |
| 767 | void grpc_chttp2_incoming_byte_stream_finished( |
Craig Tiller | 38edec6 | 2015-12-14 15:01:29 -0800 | [diff] [blame] | 768 | grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, int success, |
| 769 | int from_parsing_thread); |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 770 | |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 771 | void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, |
| 772 | grpc_chttp2_transport_parsing *parsing, |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 773 | const uint8_t *opaque_8bytes); |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 774 | |
Craig Tiller | 0cb803d | 2016-03-02 22:17:24 -0800 | [diff] [blame] | 775 | /** add a ref to the stream and add it to the writable list; |
| 776 | ref will be dropped in writing.c */ |
| 777 | void grpc_chttp2_become_writable(grpc_chttp2_transport_global *transport_global, |
| 778 | grpc_chttp2_stream_global *stream_global); |
| 779 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 780 | #endif /* GRPC_CORE_LIB_TRANSPORT_CHTTP2_INTERNAL_H */ |