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 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 37 | #include "src/core/iomgr/endpoint.h" |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 38 | #include "src/core/transport/chttp2/frame.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 39 | #include "src/core/transport/chttp2/frame_data.h" |
| 40 | #include "src/core/transport/chttp2/frame_goaway.h" |
| 41 | #include "src/core/transport/chttp2/frame_ping.h" |
| 42 | #include "src/core/transport/chttp2/frame_rst_stream.h" |
| 43 | #include "src/core/transport/chttp2/frame_settings.h" |
| 44 | #include "src/core/transport/chttp2/frame_window_update.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 45 | #include "src/core/transport/chttp2/hpack_parser.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 46 | #include "src/core/transport/chttp2/incoming_metadata.h" |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 47 | #include "src/core/transport/chttp2/stream_encoder.h" |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 48 | #include "src/core/transport/chttp2/stream_map.h" |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame^] | 49 | #include "src/core/transport/connectivity_state.h" |
| 50 | #include "src/core/transport/transport_impl.h" |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 51 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 52 | typedef struct grpc_chttp2_transport grpc_chttp2_transport; |
| 53 | typedef struct grpc_chttp2_stream grpc_chttp2_stream; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 54 | |
| 55 | /* streams are kept in various linked lists depending on what things need to |
| 56 | happen to them... this enum labels each list */ |
| 57 | typedef enum { |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 58 | GRPC_CHTTP2_LIST_ALL_STREAMS, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 59 | GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 60 | GRPC_CHTTP2_LIST_WRITABLE, |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 61 | GRPC_CHTTP2_LIST_WRITING, |
| 62 | GRPC_CHTTP2_LIST_WRITTEN, |
| 63 | GRPC_CHTTP2_LIST_WRITABLE_WINDOW_UPDATE, |
| 64 | GRPC_CHTTP2_LIST_PARSING_SEEN, |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 65 | GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING, |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 66 | GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED, |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 67 | /** streams that are waiting to start because there are too many concurrent |
| 68 | streams on the connection */ |
| 69 | GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 70 | STREAM_LIST_COUNT /* must be last */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 71 | } grpc_chttp2_stream_list_id; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 72 | |
| 73 | /* deframer state for the overall http2 stream of bytes */ |
| 74 | typedef enum { |
| 75 | /* prefix: one entry per http2 connection prefix byte */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 76 | GRPC_DTS_CLIENT_PREFIX_0 = 0, |
| 77 | GRPC_DTS_CLIENT_PREFIX_1, |
| 78 | GRPC_DTS_CLIENT_PREFIX_2, |
| 79 | GRPC_DTS_CLIENT_PREFIX_3, |
| 80 | GRPC_DTS_CLIENT_PREFIX_4, |
| 81 | GRPC_DTS_CLIENT_PREFIX_5, |
| 82 | GRPC_DTS_CLIENT_PREFIX_6, |
| 83 | GRPC_DTS_CLIENT_PREFIX_7, |
| 84 | GRPC_DTS_CLIENT_PREFIX_8, |
| 85 | GRPC_DTS_CLIENT_PREFIX_9, |
| 86 | GRPC_DTS_CLIENT_PREFIX_10, |
| 87 | GRPC_DTS_CLIENT_PREFIX_11, |
| 88 | GRPC_DTS_CLIENT_PREFIX_12, |
| 89 | GRPC_DTS_CLIENT_PREFIX_13, |
| 90 | GRPC_DTS_CLIENT_PREFIX_14, |
| 91 | GRPC_DTS_CLIENT_PREFIX_15, |
| 92 | GRPC_DTS_CLIENT_PREFIX_16, |
| 93 | GRPC_DTS_CLIENT_PREFIX_17, |
| 94 | GRPC_DTS_CLIENT_PREFIX_18, |
| 95 | GRPC_DTS_CLIENT_PREFIX_19, |
| 96 | GRPC_DTS_CLIENT_PREFIX_20, |
| 97 | GRPC_DTS_CLIENT_PREFIX_21, |
| 98 | GRPC_DTS_CLIENT_PREFIX_22, |
| 99 | GRPC_DTS_CLIENT_PREFIX_23, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 100 | /* frame header byte 0... */ |
| 101 | /* must follow from the prefix states */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 102 | GRPC_DTS_FH_0, |
| 103 | GRPC_DTS_FH_1, |
| 104 | GRPC_DTS_FH_2, |
| 105 | GRPC_DTS_FH_3, |
| 106 | GRPC_DTS_FH_4, |
| 107 | GRPC_DTS_FH_5, |
| 108 | GRPC_DTS_FH_6, |
| 109 | GRPC_DTS_FH_7, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 110 | /* ... frame header byte 8 */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 111 | GRPC_DTS_FH_8, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 112 | /* inside a http2 frame */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 113 | GRPC_DTS_FRAME |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 114 | } grpc_chttp2_deframe_transport_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 115 | |
| 116 | typedef enum { |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 117 | GRPC_WRITE_STATE_OPEN, |
| 118 | GRPC_WRITE_STATE_QUEUED_CLOSE, |
| 119 | GRPC_WRITE_STATE_SENT_CLOSE |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 120 | } grpc_chttp2_write_state; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 121 | |
| 122 | typedef enum { |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 123 | GRPC_DONT_SEND_CLOSED = 0, |
| 124 | GRPC_SEND_CLOSED, |
| 125 | GRPC_SEND_CLOSED_WITH_RST_STREAM |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 126 | } grpc_chttp2_send_closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 127 | |
| 128 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 129 | grpc_chttp2_stream *head; |
| 130 | grpc_chttp2_stream *tail; |
| 131 | } grpc_chttp2_stream_list; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 132 | |
| 133 | typedef struct { |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 134 | grpc_chttp2_stream *next; |
| 135 | grpc_chttp2_stream *prev; |
| 136 | } grpc_chttp2_stream_link; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 137 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 138 | /* We keep several sets of connection wide parameters */ |
| 139 | typedef enum { |
| 140 | /* The settings our peer has asked for (and we have acked) */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 141 | GRPC_PEER_SETTINGS = 0, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 142 | /* The settings we'd like to have */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 143 | GRPC_LOCAL_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 144 | /* The settings we've published to our peer */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 145 | GRPC_SENT_SETTINGS, |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 146 | /* The settings the peer has acked */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 147 | GRPC_ACKED_SETTINGS, |
| 148 | GRPC_NUM_SETTING_SETS |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 149 | } grpc_chttp2_setting_set; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 150 | |
| 151 | /* Outstanding ping request data */ |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 152 | typedef struct grpc_chttp2_outstanding_ping { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 153 | gpr_uint8 id[8]; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 154 | grpc_iomgr_closure *on_recv; |
| 155 | struct grpc_chttp2_outstanding_ping *next; |
| 156 | struct grpc_chttp2_outstanding_ping *prev; |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 157 | } grpc_chttp2_outstanding_ping; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 158 | |
| 159 | typedef struct { |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 160 | /** data to write next write */ |
| 161 | gpr_slice_buffer qbuf; |
| 162 | /** queued callbacks */ |
| 163 | grpc_iomgr_closure *pending_closures; |
| 164 | |
| 165 | /** window available for us to send to peer */ |
| 166 | gpr_uint32 outgoing_window; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 167 | /** window available for peer to send to us - updated after parse */ |
| 168 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 169 | /** how much window would we like to have for incoming_window */ |
| 170 | gpr_uint32 connection_window_target; |
| 171 | |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 172 | /** have we seen a goaway */ |
| 173 | gpr_uint8 seen_goaway; |
| 174 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 175 | /** is this transport a client? */ |
| 176 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 177 | /** are the local settings dirty and need to be sent? */ |
| 178 | gpr_uint8 dirtied_local_settings; |
| 179 | /** have local settings been sent? */ |
| 180 | gpr_uint8 sent_local_settings; |
| 181 | /** bitmask of setting indexes to send out */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 182 | gpr_uint32 force_send_settings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 183 | /** settings values */ |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 184 | gpr_uint32 settings[GRPC_NUM_SETTING_SETS][GRPC_CHTTP2_NUM_SETTINGS]; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 185 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 186 | /** what is the next stream id to be allocated by this peer? |
| 187 | copied to next_stream_id in parsing when parsing commences */ |
| 188 | gpr_uint32 next_stream_id; |
| 189 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 190 | /** last received stream id */ |
| 191 | gpr_uint32 last_incoming_stream_id; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 192 | |
| 193 | /** pings awaiting responses */ |
| 194 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 195 | /** next payload for an outgoing ping */ |
| 196 | gpr_uint64 ping_counter; |
| 197 | |
| 198 | /** concurrent stream count: updated when not parsing, |
| 199 | so this is a strict over-estimation on the client */ |
| 200 | gpr_uint32 concurrent_stream_count; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 201 | } grpc_chttp2_transport_global; |
| 202 | |
| 203 | typedef struct { |
| 204 | /** data to write now */ |
| 205 | gpr_slice_buffer outbuf; |
| 206 | /** hpack encoding */ |
| 207 | grpc_chttp2_hpack_compressor hpack_compressor; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 208 | /** is this a client? */ |
| 209 | gpr_uint8 is_client; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 210 | } grpc_chttp2_transport_writing; |
| 211 | |
| 212 | struct grpc_chttp2_transport_parsing { |
| 213 | /** is this transport a client? (boolean) */ |
| 214 | gpr_uint8 is_client; |
| 215 | |
| 216 | /** were settings updated? */ |
| 217 | gpr_uint8 settings_updated; |
| 218 | /** was a settings ack received? */ |
| 219 | gpr_uint8 settings_ack_received; |
| 220 | /** was a goaway frame received? */ |
| 221 | gpr_uint8 goaway_received; |
| 222 | |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 223 | /** initial window change */ |
| 224 | gpr_int64 initial_window_update; |
| 225 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 226 | /** data to write later - after parsing */ |
| 227 | gpr_slice_buffer qbuf; |
| 228 | /* metadata object cache */ |
| 229 | grpc_mdstr *str_grpc_timeout; |
| 230 | /** parser for headers */ |
| 231 | grpc_chttp2_hpack_parser hpack_parser; |
| 232 | /** simple one shot parsers */ |
| 233 | union { |
| 234 | grpc_chttp2_window_update_parser window_update; |
| 235 | grpc_chttp2_settings_parser settings; |
| 236 | grpc_chttp2_ping_parser ping; |
| 237 | grpc_chttp2_rst_stream_parser rst_stream; |
| 238 | } simple; |
| 239 | /** parser for goaway frames */ |
| 240 | grpc_chttp2_goaway_parser goaway_parser; |
| 241 | |
| 242 | /** window available for peer to send to us */ |
| 243 | gpr_uint32 incoming_window; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 244 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 245 | |
| 246 | /** next stream id available at the time of beginning parsing */ |
| 247 | gpr_uint32 next_stream_id; |
| 248 | gpr_uint32 last_incoming_stream_id; |
| 249 | |
| 250 | /* deframing */ |
| 251 | grpc_chttp2_deframe_transport_state deframe_state; |
| 252 | gpr_uint8 incoming_frame_type; |
| 253 | gpr_uint8 incoming_frame_flags; |
| 254 | gpr_uint8 header_eof; |
| 255 | gpr_uint32 expect_continuation_stream_id; |
| 256 | gpr_uint32 incoming_frame_size; |
| 257 | gpr_uint32 incoming_stream_id; |
| 258 | |
| 259 | /* active parser */ |
| 260 | void *parser_data; |
| 261 | grpc_chttp2_stream_parsing *incoming_stream; |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 262 | grpc_chttp2_parse_error (*parser)( |
| 263 | void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing, |
| 264 | grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 265 | |
| 266 | /* received settings */ |
| 267 | gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS]; |
| 268 | |
| 269 | /* goaway data */ |
| 270 | grpc_status_code goaway_error; |
| 271 | gpr_uint32 goaway_last_stream_index; |
| 272 | gpr_slice goaway_text; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 273 | |
| 274 | gpr_uint64 outgoing_window_update; |
| 275 | |
| 276 | /** pings awaiting responses */ |
| 277 | grpc_chttp2_outstanding_ping pings; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 280 | struct grpc_chttp2_transport { |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 281 | grpc_transport base; /* must be first */ |
| 282 | grpc_endpoint *ep; |
| 283 | grpc_mdctx *metadata_context; |
| 284 | gpr_refcount refs; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 285 | |
| 286 | gpr_mu mu; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 287 | |
| 288 | /** is the transport destroying itself? */ |
| 289 | gpr_uint8 destroying; |
| 290 | /** has the upper layer closed the transport? */ |
| 291 | gpr_uint8 closed; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 292 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 293 | /** is a thread currently writing */ |
| 294 | gpr_uint8 writing_active; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 295 | /** is a thread currently parsing */ |
| 296 | gpr_uint8 parsing_active; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 297 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 298 | /** is there a read request to the endpoint outstanding? */ |
| 299 | gpr_uint8 endpoint_reading; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 300 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 301 | /** various lists of streams */ |
Craig Tiller | b084d90 | 2015-06-12 07:50:02 -0700 | [diff] [blame] | 302 | grpc_chttp2_stream_list lists[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 303 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 304 | /** global state for reading/writing */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 305 | grpc_chttp2_transport_global global; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 306 | /** state only accessible by the chain of execution that |
| 307 | set writing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 308 | grpc_chttp2_transport_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 309 | /** state only accessible by the chain of execution that |
| 310 | set parsing_active=1 */ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 311 | grpc_chttp2_transport_parsing parsing; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 312 | |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 313 | /** maps stream id to grpc_chttp2_stream objects; |
| 314 | owned by the parsing thread when parsing */ |
| 315 | grpc_chttp2_stream_map parsing_stream_map; |
| 316 | |
| 317 | /** streams created by the client (possibly during parsing); |
| 318 | merged with parsing_stream_map during unlock when no |
| 319 | parsing is occurring */ |
| 320 | grpc_chttp2_stream_map new_stream_map; |
| 321 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 322 | /** closure to execute writing */ |
| 323 | grpc_iomgr_closure writing_action; |
Craig Tiller | 8b2f1d7 | 2015-06-18 13:38:38 -0700 | [diff] [blame] | 324 | /** closure to start reading from the endpoint */ |
| 325 | grpc_iomgr_closure reading_action; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 326 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 327 | /** address to place a newly accepted stream - set and unset by |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 328 | grpc_chttp2_parsing_accept_stream; used by init_stream to |
| 329 | publish the accepted server stream */ |
| 330 | grpc_chttp2_stream **accepting_stream; |
| 331 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 332 | struct { |
Craig Tiller | 1064f8b | 2015-06-25 13:52:57 -0700 | [diff] [blame] | 333 | /* accept stream callback */ |
| 334 | void (*accept_stream)(void *user_data, grpc_transport *transport, |
| 335 | const void *server_data); |
| 336 | void *accept_stream_user_data; |
| 337 | |
| 338 | /** connectivity tracking */ |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame^] | 339 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 340 | } channel_callback; |
| 341 | }; |
| 342 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 343 | typedef struct { |
| 344 | /** 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] | 345 | gpr_uint32 id; |
| 346 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 347 | grpc_iomgr_closure *send_done_closure; |
| 348 | grpc_iomgr_closure *recv_done_closure; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 349 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 350 | /** window available for us to send to peer */ |
| 351 | gpr_int64 outgoing_window; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 352 | /** window available for peer to send to us - updated after parse */ |
| 353 | gpr_uint32 incoming_window; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 354 | /** stream ops the transport user would like to send */ |
| 355 | grpc_stream_op_buffer *outgoing_sopb; |
| 356 | /** when the application requests writes be closed, the write_closed is |
| 357 | 'queued'; when the close is flow controlled into the send path, we are |
| 358 | 'sending' it; when the write has been performed it is 'sent' */ |
| 359 | grpc_chttp2_write_state write_state; |
| 360 | /** is this stream closed (boolean) */ |
| 361 | gpr_uint8 read_closed; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 362 | /** has this stream been cancelled? (boolean) */ |
| 363 | gpr_uint8 cancelled; |
Craig Tiller | cec9eb9 | 2015-06-17 17:16:48 -0700 | [diff] [blame] | 364 | grpc_status_code cancelled_status; |
| 365 | /** have we told the upper layer that this stream is cancelled? */ |
| 366 | gpr_uint8 published_cancelled; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 367 | /** is this stream in the stream map? (boolean) */ |
| 368 | gpr_uint8 in_stream_map; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 369 | |
| 370 | /** stream state already published to the upper layer */ |
| 371 | grpc_stream_state published_state; |
| 372 | /** address to publish next stream state to */ |
| 373 | grpc_stream_state *publish_state; |
| 374 | /** pointer to sop buffer to fill in with new stream ops */ |
Craig Tiller | 6905b7c | 2015-06-16 15:33:33 -0700 | [diff] [blame] | 375 | grpc_stream_op_buffer *publish_sopb; |
| 376 | grpc_stream_op_buffer incoming_sopb; |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 377 | |
| 378 | /** incoming metadata */ |
| 379 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
Craig Tiller | b787c50 | 2015-06-15 16:14:52 -0700 | [diff] [blame] | 380 | grpc_chttp2_incoming_metadata_live_op_buffer outstanding_metadata; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 381 | } grpc_chttp2_stream_global; |
| 382 | |
| 383 | typedef struct { |
| 384 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 385 | gpr_uint32 id; |
| 386 | /** sops that have passed flow control to be written */ |
| 387 | grpc_stream_op_buffer sopb; |
| 388 | /** how strongly should we indicate closure with the next write */ |
| 389 | grpc_chttp2_send_closed send_closed; |
| 390 | } grpc_chttp2_stream_writing; |
| 391 | |
| 392 | struct grpc_chttp2_stream_parsing { |
| 393 | /** HTTP2 stream id for this stream, or zero if one has not been assigned */ |
| 394 | gpr_uint32 id; |
| 395 | /** has this stream received a close */ |
| 396 | gpr_uint8 received_close; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 397 | /** saw a rst_stream */ |
| 398 | gpr_uint8 saw_rst_stream; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 399 | /** incoming_window has been reduced by this much during parsing */ |
| 400 | gpr_uint32 incoming_window_delta; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 401 | /** window available for peer to send to us */ |
| 402 | gpr_uint32 incoming_window; |
| 403 | /** parsing state for data frames */ |
| 404 | grpc_chttp2_data_parser data_parser; |
Craig Tiller | 3719f07 | 2015-06-12 17:19:51 -0700 | [diff] [blame] | 405 | /** reason give to rst_stream */ |
| 406 | gpr_uint32 rst_stream_reason; |
| 407 | /* amount of window given */ |
| 408 | gpr_uint64 outgoing_window_update; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 409 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 410 | /** incoming metadata */ |
| 411 | grpc_chttp2_incoming_metadata_buffer incoming_metadata; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | struct grpc_chttp2_stream { |
| 415 | grpc_chttp2_stream_global global; |
| 416 | grpc_chttp2_stream_writing writing; |
Craig Tiller | 606d874 | 2015-06-15 06:58:50 -0700 | [diff] [blame] | 417 | grpc_chttp2_stream_parsing parsing; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 418 | |
| 419 | grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; |
| 420 | gpr_uint8 included[STREAM_LIST_COUNT]; |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 421 | }; |
| 422 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 423 | /** Transport writing call flow: |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 424 | chttp2_transport.c calls grpc_chttp2_unlocking_check_writes to see if writes |
| 425 | are required; |
| 426 | if they are, chttp2_transport.c calls grpc_chttp2_perform_writes to do the |
| 427 | writes. |
| 428 | Once writes have been completed (meaning another write could potentially be |
| 429 | started), |
| 430 | grpc_chttp2_terminate_writing is called. This will call |
| 431 | grpc_chttp2_cleanup_writing, at which |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 432 | point the write phase is complete. */ |
| 433 | |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 434 | /** Someone is unlocking the transport mutex: check to see if writes |
| 435 | are required, and schedule them if so */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 436 | int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, |
| 437 | grpc_chttp2_transport_writing *writing); |
| 438 | void grpc_chttp2_perform_writes( |
| 439 | grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint); |
| 440 | void grpc_chttp2_terminate_writing( |
| 441 | grpc_chttp2_transport_writing *transport_writing, int success); |
| 442 | void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, |
| 443 | grpc_chttp2_transport_writing *writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 444 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 445 | void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, |
| 446 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 447 | /** Process one slice of incoming data; return 1 if the connection is still |
| 448 | viable after reading, or 0 if the connection should be torn down */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 449 | int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, |
| 450 | gpr_slice slice); |
| 451 | void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, |
| 452 | grpc_chttp2_transport_parsing *parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 453 | |
| 454 | /** Get a writable stream |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 455 | returns non-zero if there was a stream available */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 456 | void grpc_chttp2_list_add_writable_stream( |
| 457 | grpc_chttp2_transport_global *transport_global, |
| 458 | grpc_chttp2_stream_global *stream_global); |
| 459 | int grpc_chttp2_list_pop_writable_stream( |
| 460 | grpc_chttp2_transport_global *transport_global, |
| 461 | grpc_chttp2_transport_writing *transport_writing, |
| 462 | grpc_chttp2_stream_global **stream_global, |
| 463 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 464 | |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 465 | void grpc_chttp2_list_add_incoming_window_updated( |
| 466 | grpc_chttp2_transport_global *transport_global, |
| 467 | grpc_chttp2_stream_global *stream_global); |
| 468 | int grpc_chttp2_list_pop_incoming_window_updated( |
| 469 | grpc_chttp2_transport_global *transport_global, |
| 470 | grpc_chttp2_transport_parsing *transport_parsing, |
| 471 | grpc_chttp2_stream_global **stream_global, |
| 472 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | 759eb32 | 2015-06-16 22:41:18 -0700 | [diff] [blame] | 473 | void grpc_chttp2_list_remove_incoming_window_updated( |
| 474 | grpc_chttp2_transport_global *transport_global, |
| 475 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | cf1e319 | 2015-06-16 14:28:22 -0700 | [diff] [blame] | 476 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 477 | void grpc_chttp2_list_add_writing_stream( |
| 478 | grpc_chttp2_transport_writing *transport_writing, |
| 479 | grpc_chttp2_stream_writing *stream_writing); |
| 480 | int grpc_chttp2_list_have_writing_streams( |
| 481 | grpc_chttp2_transport_writing *transport_writing); |
| 482 | int grpc_chttp2_list_pop_writing_stream( |
| 483 | grpc_chttp2_transport_writing *transport_writing, |
| 484 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 485 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 486 | void grpc_chttp2_list_add_written_stream( |
| 487 | grpc_chttp2_transport_writing *transport_writing, |
| 488 | grpc_chttp2_stream_writing *stream_writing); |
| 489 | int grpc_chttp2_list_pop_written_stream( |
| 490 | grpc_chttp2_transport_global *transport_global, |
| 491 | grpc_chttp2_transport_writing *transport_writing, |
| 492 | grpc_chttp2_stream_global **stream_global, |
| 493 | grpc_chttp2_stream_writing **stream_writing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 494 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 495 | void grpc_chttp2_list_add_writable_window_update_stream( |
| 496 | grpc_chttp2_transport_global *transport_global, |
| 497 | grpc_chttp2_stream_global *stream_global); |
| 498 | int grpc_chttp2_list_pop_writable_window_update_stream( |
| 499 | grpc_chttp2_transport_global *transport_global, |
| 500 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | b951df1 | 2015-06-18 15:46:58 -0700 | [diff] [blame] | 501 | void grpc_chttp2_list_remove_writable_window_update_stream( |
| 502 | grpc_chttp2_transport_global *transport_global, |
| 503 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 504 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 505 | void grpc_chttp2_list_add_parsing_seen_stream( |
| 506 | grpc_chttp2_transport_parsing *transport_parsing, |
| 507 | grpc_chttp2_stream_parsing *stream_parsing); |
| 508 | int grpc_chttp2_list_pop_parsing_seen_stream( |
| 509 | grpc_chttp2_transport_global *transport_global, |
| 510 | grpc_chttp2_transport_parsing *transport_parsing, |
| 511 | grpc_chttp2_stream_global **stream_global, |
| 512 | grpc_chttp2_stream_parsing **stream_parsing); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 513 | |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 514 | void grpc_chttp2_list_add_waiting_for_concurrency( |
| 515 | grpc_chttp2_transport_global *transport_global, |
| 516 | grpc_chttp2_stream_global *stream_global); |
| 517 | int grpc_chttp2_list_pop_waiting_for_concurrency( |
| 518 | grpc_chttp2_transport_global *transport_global, |
| 519 | grpc_chttp2_stream_global **stream_global); |
| 520 | |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 521 | void grpc_chttp2_list_add_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 522 | grpc_chttp2_transport_global *transport_global, |
| 523 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | 83fb070 | 2015-06-16 21:13:07 -0700 | [diff] [blame] | 524 | int grpc_chttp2_list_pop_closed_waiting_for_parsing( |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 525 | grpc_chttp2_transport_global *transport_global, |
| 526 | grpc_chttp2_stream_global **stream_global); |
| 527 | |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 528 | void grpc_chttp2_list_add_read_write_state_changed( |
| 529 | grpc_chttp2_transport_global *transport_global, |
| 530 | grpc_chttp2_stream_global *stream_global); |
Craig Tiller | f73fcd1 | 2015-06-16 16:25:26 -0700 | [diff] [blame] | 531 | int grpc_chttp2_list_pop_read_write_state_changed( |
| 532 | grpc_chttp2_transport_global *transport_global, |
| 533 | grpc_chttp2_stream_global **stream_global); |
Craig Tiller | 6459db4 | 2015-06-15 17:11:45 -0700 | [diff] [blame] | 534 | |
Craig Tiller | 1937b06 | 2015-06-16 08:47:38 -0700 | [diff] [blame] | 535 | /** schedule a closure to run without the transport lock taken */ |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 536 | void grpc_chttp2_schedule_closure( |
| 537 | grpc_chttp2_transport_global *transport_global, grpc_iomgr_closure *closure, |
| 538 | int success); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 539 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 540 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream( |
| 541 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
| 542 | grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream( |
| 543 | grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 544 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 545 | void grpc_chttp2_add_incoming_goaway( |
| 546 | grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error, |
| 547 | gpr_slice goaway_text); |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 548 | |
Craig Tiller | 9850510 | 2015-06-16 11:33:15 -0700 | [diff] [blame] | 549 | void grpc_chttp2_register_stream(grpc_chttp2_transport *t, |
| 550 | grpc_chttp2_stream *s); |
| 551 | void grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, |
| 552 | grpc_chttp2_stream *s); |
| 553 | void grpc_chttp2_for_all_streams( |
| 554 | grpc_chttp2_transport_global *transport_global, void *user_data, |
| 555 | void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, |
| 556 | grpc_chttp2_stream_global *stream_global)); |
Craig Tiller | 5dc3b30 | 2015-06-15 16:06:50 -0700 | [diff] [blame] | 557 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 558 | void grpc_chttp2_parsing_become_skip_parser( |
| 559 | grpc_chttp2_transport_parsing *transport_parsing); |
Craig Tiller | 66abdaa | 2015-06-17 08:00:39 -0700 | [diff] [blame] | 560 | |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 561 | #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] | 562 | #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ |
| 563 | (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 564 | |
| 565 | extern int grpc_http_trace; |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 566 | extern int grpc_flowctl_trace; |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 567 | |
Craig Tiller | ab63073 | 2015-06-25 11:20:01 -0700 | [diff] [blame] | 568 | #define GRPC_CHTTP2_IF_TRACING(stmt) \ |
| 569 | if (!(grpc_http_trace)) \ |
| 570 | ; \ |
| 571 | else \ |
Craig Tiller | d20efd2 | 2015-06-12 16:17:09 -0700 | [diff] [blame] | 572 | stmt |
Craig Tiller | 3208e39 | 2015-06-12 08:17:02 -0700 | [diff] [blame] | 573 | |
Craig Tiller | 285b882 | 2015-06-17 15:58:13 -0700 | [diff] [blame] | 574 | #define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \ |
| 575 | delta) \ |
| 576 | if (!(grpc_flowctl_trace)) { \ |
| 577 | } else { \ |
| 578 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 579 | transport->is_client, context->id, context->var, \ |
| 580 | delta); \ |
| 581 | } |
| 582 | |
| 583 | #define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \ |
| 584 | if (!(grpc_flowctl_trace)) { \ |
| 585 | } else { \ |
| 586 | grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ |
| 587 | context->is_client, 0, context->var, delta); \ |
| 588 | } |
| 589 | |
| 590 | void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason, |
| 591 | const char *context, const char *var, |
| 592 | int is_client, gpr_uint32 stream_id, |
| 593 | gpr_int64 current_value, gpr_int64 delta); |
| 594 | |
Craig Tiller | 9b8671c | 2015-06-12 07:41:54 -0700 | [diff] [blame] | 595 | #endif |