| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // The base class for streams which deliver data to/from an application. | 5 // The base class for streams which deliver data to/from an application. |
| 6 // In each direction, the data on such a stream first contains compressed | 6 // In each direction, the data on such a stream first contains compressed |
| 7 // headers then body data. | 7 // headers then body data. |
| 8 | 8 |
| 9 #ifndef NET_QUIC_QUIC_SPDY_STREAM_H_ | 9 #ifndef NET_QUIC_QUIC_SPDY_STREAM_H_ |
| 10 #define NET_QUIC_QUIC_SPDY_STREAM_H_ | 10 #define NET_QUIC_QUIC_SPDY_STREAM_H_ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // when the stream has not received all the data. | 71 // when the stream has not received all the data. |
| 72 void CloseWriteSide() override; | 72 void CloseWriteSide() override; |
| 73 void StopReading() override; | 73 void StopReading() override; |
| 74 | 74 |
| 75 // ReliableQuicStream implementation | 75 // ReliableQuicStream implementation |
| 76 void OnClose() override; | 76 void OnClose() override; |
| 77 | 77 |
| 78 // Override to maybe close the write side after writing. | 78 // Override to maybe close the write side after writing. |
| 79 void OnCanWrite() override; | 79 void OnCanWrite() override; |
| 80 | 80 |
| 81 // Called by the session when decompressed headers data is received | |
| 82 // for this stream. | |
| 83 // May be called multiple times, with each call providing additional headers | |
| 84 // data until OnStreamHeadersComplete is called. | |
| 85 virtual void OnStreamHeaders(base::StringPiece headers_data); | |
| 86 | |
| 87 // Called by the session when headers with a priority have been received | 81 // Called by the session when headers with a priority have been received |
| 88 // for this stream. This method will only be called for server streams. | 82 // for this stream. This method will only be called for server streams. |
| 89 virtual void OnStreamHeadersPriority(SpdyPriority priority); | 83 virtual void OnStreamHeadersPriority(SpdyPriority priority); |
| 90 | 84 |
| 91 // Called by the session when decompressed headers have been completely | 85 // Called by the session when decompressed headers have been completely |
| 92 // delivered to this stream. If |fin| is true, then this stream | 86 // delivered to this stream. If |fin| is true, then this stream |
| 93 // should be closed; no more data will be sent by the peer. | 87 // should be closed; no more data will be sent by the peer. |
| 94 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len); | |
| 95 | |
| 96 // Called by the session when decompressed headers have been completely | |
| 97 // delivered to this stream. If |fin| is true, then this stream | |
| 98 // should be closed; no more data will be sent by the peer. | |
| 99 virtual void OnStreamHeaderList(bool fin, | 88 virtual void OnStreamHeaderList(bool fin, |
| 100 size_t frame_len, | 89 size_t frame_len, |
| 101 const QuicHeaderList& header_list); | 90 const QuicHeaderList& header_list); |
| 102 | 91 |
| 103 // Called when the received headers are too large. By default this will | 92 // Called when the received headers are too large. By default this will |
| 104 // reset the stream. | 93 // reset the stream. |
| 105 virtual void OnHeadersTooLarge(); | 94 virtual void OnHeadersTooLarge(); |
| 106 | 95 |
| 107 // Called by the session when decompressed PUSH_PROMISE headers data | |
| 108 // is received for this stream. | |
| 109 // May be called multiple times, with each call providing additional headers | |
| 110 // data until OnPromiseHeadersComplete is called. | |
| 111 virtual void OnPromiseHeaders(base::StringPiece headers_data); | |
| 112 | |
| 113 // Called by the session when decompressed push promise headers have | |
| 114 // been completely delivered to this stream. | |
| 115 virtual void OnPromiseHeadersComplete(QuicStreamId promised_id, | |
| 116 size_t frame_len); | |
| 117 | |
| 118 // Called by the session when decompressed push promise headers have | 96 // Called by the session when decompressed push promise headers have |
| 119 // been completely delivered to this stream. | 97 // been completely delivered to this stream. |
| 120 virtual void OnPromiseHeaderList(QuicStreamId promised_id, | 98 virtual void OnPromiseHeaderList(QuicStreamId promised_id, |
| 121 size_t frame_len, | 99 size_t frame_len, |
| 122 const QuicHeaderList& header_list); | 100 const QuicHeaderList& header_list); |
| 123 | 101 |
| 124 // Override the base class to not discard response when receiving | 102 // Override the base class to not discard response when receiving |
| 125 // QUIC_STREAM_NO_ERROR. | 103 // QUIC_STREAM_NO_ERROR. |
| 126 void OnStreamReset(const QuicRstStreamFrame& frame) override; | 104 void OnStreamReset(const QuicRstStreamFrame& frame) override; |
| 127 | 105 |
| 128 // Writes the headers contained in |header_block| to the dedicated | 106 // Writes the headers contained in |header_block| to the dedicated |
| 129 // headers stream. | 107 // headers stream. |
| 130 virtual size_t WriteHeaders(SpdyHeaderBlock header_block, | 108 virtual size_t WriteHeaders(SpdyHeaderBlock header_block, |
| 131 bool fin, | 109 bool fin, |
| 132 QuicAckListenerInterface* ack_notifier_delegate); | 110 QuicAckListenerInterface* ack_notifier_delegate); |
| 133 | 111 |
| 134 // Sends |data| to the peer, or buffers if it can't be sent immediately. | 112 // Sends |data| to the peer, or buffers if it can't be sent immediately. |
| 135 void WriteOrBufferBody(const std::string& data, | 113 void WriteOrBufferBody(const std::string& data, |
| 136 bool fin, | 114 bool fin, |
| 137 QuicAckListenerInterface* ack_notifier_delegate); | 115 QuicAckListenerInterface* ack_notifier_delegate); |
| 138 | 116 |
| 139 // Writes the trailers contained in |trailer_block| to the dedicated | 117 // Writes the trailers contained in |trailer_block| to the dedicated |
| 140 // headers stream. Trailers will always have the FIN set. | 118 // headers stream. Trailers will always have the FIN set. |
| 141 virtual size_t WriteTrailers(SpdyHeaderBlock trailer_block, | 119 virtual size_t WriteTrailers(SpdyHeaderBlock trailer_block, |
| 142 QuicAckListenerInterface* ack_notifier_delegate); | 120 QuicAckListenerInterface* ack_notifier_delegate); |
| 143 | 121 |
| 144 // Marks |bytes_consumed| of the headers data as consumed. | |
| 145 void MarkHeadersConsumed(size_t bytes_consumed); | |
| 146 | |
| 147 // Marks |bytes_consumed| of the trailers data as consumed. This applies to | |
| 148 // the case where this object receives headers and trailers data via calls to | |
| 149 // OnStreamHeaders(). | |
| 150 void MarkTrailersConsumed(size_t bytes_consumed); | |
| 151 | |
| 152 // Marks the trailers as consumed. This applies to the case where this object | 122 // Marks the trailers as consumed. This applies to the case where this object |
| 153 // receives headers and trailers as QuicHeaderLists via calls to | 123 // receives headers and trailers as QuicHeaderLists via calls to |
| 154 // OnStreamHeaderList(). | 124 // OnStreamHeaderList(). |
| 155 void MarkTrailersConsumed(); | 125 void MarkTrailersConsumed(); |
| 156 | 126 |
| 157 // Clears |header_list_|. | 127 // Clears |header_list_|. |
| 158 void ConsumeHeaderList(); | 128 void ConsumeHeaderList(); |
| 159 | 129 |
| 160 // This block of functions wraps the sequencer's functions of the same | 130 // This block of functions wraps the sequencer's functions of the same |
| 161 // name. These methods return uncompressed data until that has | 131 // name. These methods return uncompressed data until that has |
| 162 // been fully processed. Then they simply delegate to the sequencer. | 132 // been fully processed. Then they simply delegate to the sequencer. |
| 163 virtual size_t Readv(const struct iovec* iov, size_t iov_len); | 133 virtual size_t Readv(const struct iovec* iov, size_t iov_len); |
| 164 virtual int GetReadableRegions(iovec* iov, size_t iov_len) const; | 134 virtual int GetReadableRegions(iovec* iov, size_t iov_len) const; |
| 165 void MarkConsumed(size_t num_bytes); | 135 void MarkConsumed(size_t num_bytes); |
| 166 | 136 |
| 167 // Returns true if header contains a valid 3-digit status and parse the status | 137 // Returns true if header contains a valid 3-digit status and parse the status |
| 168 // code to |status_code|. | 138 // code to |status_code|. |
| 169 bool ParseHeaderStatusCode(const SpdyHeaderBlock& header, | 139 bool ParseHeaderStatusCode(const SpdyHeaderBlock& header, |
| 170 int* status_code) const; | 140 int* status_code) const; |
| 171 | 141 |
| 172 // Returns true when all data has been read from the peer, including the fin. | 142 // Returns true when all data has been read from the peer, including the fin. |
| 173 bool IsDoneReading() const; | 143 bool IsDoneReading() const; |
| 174 bool HasBytesToRead() const; | 144 bool HasBytesToRead() const; |
| 175 | 145 |
| 176 void set_visitor(Visitor* visitor) { visitor_ = visitor; } | 146 void set_visitor(Visitor* visitor) { visitor_ = visitor; } |
| 177 | 147 |
| 178 bool headers_decompressed() const { return headers_decompressed_; } | 148 bool headers_decompressed() const { return headers_decompressed_; } |
| 179 | 149 |
| 180 const std::string& decompressed_headers() const { | |
| 181 return decompressed_headers_; | |
| 182 } | |
| 183 | |
| 184 const QuicHeaderList& header_list() const { return header_list_; } | 150 const QuicHeaderList& header_list() const { return header_list_; } |
| 185 | 151 |
| 186 bool trailers_decompressed() const { return trailers_decompressed_; } | 152 bool trailers_decompressed() const { return trailers_decompressed_; } |
| 187 | 153 |
| 188 const std::string& decompressed_trailers() const { | |
| 189 return decompressed_trailers_; | |
| 190 } | |
| 191 | |
| 192 // Returns whatever trailers have been received for this stream. | 154 // Returns whatever trailers have been received for this stream. |
| 193 const SpdyHeaderBlock& received_trailers() const { | 155 const SpdyHeaderBlock& received_trailers() const { |
| 194 return received_trailers_; | 156 return received_trailers_; |
| 195 } | 157 } |
| 196 | 158 |
| 197 // Returns true if headers have been fully read and consumed. | 159 // Returns true if headers have been fully read and consumed. |
| 198 bool FinishedReadingHeaders() const; | 160 bool FinishedReadingHeaders() const; |
| 199 | 161 |
| 200 // Returns true if trailers have been fully read and consumed, or FIN has | 162 // Returns true if trailers have been fully read and consumed, or FIN has |
| 201 // been received and there are no trailers. | 163 // been received and there are no trailers. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 215 // will be available. | 177 // will be available. |
| 216 bool IsClosed() { return sequencer()->IsClosed(); } | 178 bool IsClosed() { return sequencer()->IsClosed(); } |
| 217 | 179 |
| 218 void set_allow_bidirectional_data(bool value) { | 180 void set_allow_bidirectional_data(bool value) { |
| 219 allow_bidirectional_data_ = value; | 181 allow_bidirectional_data_ = value; |
| 220 } | 182 } |
| 221 | 183 |
| 222 bool allow_bidirectional_data() const { return allow_bidirectional_data_; } | 184 bool allow_bidirectional_data() const { return allow_bidirectional_data_; } |
| 223 | 185 |
| 224 protected: | 186 protected: |
| 225 // Called by OnStreamHeadersComplete depending on which type (initial or | |
| 226 // trailing) headers are expected next. | |
| 227 virtual void OnInitialHeadersComplete(bool fin, size_t frame_len); | |
| 228 virtual void OnTrailingHeadersComplete(bool fin, size_t frame_len); | |
| 229 virtual void OnInitialHeadersComplete(bool fin, | 187 virtual void OnInitialHeadersComplete(bool fin, |
| 230 size_t frame_len, | 188 size_t frame_len, |
| 231 const QuicHeaderList& header_list); | 189 const QuicHeaderList& header_list); |
| 232 virtual void OnTrailingHeadersComplete(bool fin, | 190 virtual void OnTrailingHeadersComplete(bool fin, |
| 233 size_t frame_len, | 191 size_t frame_len, |
| 234 const QuicHeaderList& header_list); | 192 const QuicHeaderList& header_list); |
| 235 QuicSpdySession* spdy_session() const { return spdy_session_; } | 193 QuicSpdySession* spdy_session() const { return spdy_session_; } |
| 236 Visitor* visitor() { return visitor_; } | 194 Visitor* visitor() { return visitor_; } |
| 237 | 195 |
| 238 // Redirects to the headers stream if force HOL blocking enabled, | 196 // Redirects to the headers stream if force HOL blocking enabled, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 251 QuicSpdySession* spdy_session_; | 209 QuicSpdySession* spdy_session_; |
| 252 | 210 |
| 253 Visitor* visitor_; | 211 Visitor* visitor_; |
| 254 // If true, allow sending of a request to continue while the response is | 212 // If true, allow sending of a request to continue while the response is |
| 255 // arriving. | 213 // arriving. |
| 256 bool allow_bidirectional_data_; | 214 bool allow_bidirectional_data_; |
| 257 // True if the headers have been completely decompressed. | 215 // True if the headers have been completely decompressed. |
| 258 bool headers_decompressed_; | 216 bool headers_decompressed_; |
| 259 // The priority of the stream, once parsed. | 217 // The priority of the stream, once parsed. |
| 260 SpdyPriority priority_; | 218 SpdyPriority priority_; |
| 261 // Contains a copy of the decompressed headers until they are consumed | 219 // Contains a copy of the decompressed header (name, value) std::pairs until |
| 262 // via ProcessData or Readv. | 220 // they |
| 263 std::string decompressed_headers_; | |
| 264 // Contains a copy of the decompressed header (name, value) pairs until they | |
| 265 // are consumed via Readv. | 221 // are consumed via Readv. |
| 266 QuicHeaderList header_list_; | 222 QuicHeaderList header_list_; |
| 267 | 223 |
| 268 // True if the trailers have been completely decompressed. | 224 // True if the trailers have been completely decompressed. |
| 269 bool trailers_decompressed_; | 225 bool trailers_decompressed_; |
| 270 // True if the trailers have been consumed. | 226 // True if the trailers have been consumed. |
| 271 bool trailers_consumed_; | 227 bool trailers_consumed_; |
| 272 // Contains a copy of the decompressed trailers until they are consumed | |
| 273 // via ProcessData or Readv. | |
| 274 std::string decompressed_trailers_; | |
| 275 // The parsed trailers received from the peer. | 228 // The parsed trailers received from the peer. |
| 276 SpdyHeaderBlock received_trailers_; | 229 SpdyHeaderBlock received_trailers_; |
| 277 | 230 |
| 278 DISALLOW_COPY_AND_ASSIGN(QuicSpdyStream); | 231 DISALLOW_COPY_AND_ASSIGN(QuicSpdyStream); |
| 279 }; | 232 }; |
| 280 | 233 |
| 281 } // namespace net | 234 } // namespace net |
| 282 | 235 |
| 283 #endif // NET_QUIC_QUIC_SPDY_STREAM_H_ | 236 #endif // NET_QUIC_QUIC_SPDY_STREAM_H_ |
| OLD | NEW |