| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 client/server QUIC streams. | 5 // The base class for client/server QUIC streams. |
| 6 | 6 |
| 7 // It does not contain the entire interface needed by an application to interact | 7 // It does not contain the entire interface needed by an application to interact |
| 8 // with a QUIC stream. Some parts of the interface must be obtained by | 8 // with a QUIC stream. Some parts of the interface must be obtained by |
| 9 // accessing the owning session object. A subclass of QuicStream | 9 // accessing the owning session object. A subclass of QuicStream |
| 10 // connects the object and the application that generates and consumes the data | 10 // connects the object and the application that generates and consumes the data |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include <list> | 22 #include <list> |
| 23 #include <string> | 23 #include <string> |
| 24 | 24 |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "net/base/iovec.h" | 26 #include "net/base/iovec.h" |
| 27 #include "net/quic/core/quic_flow_controller.h" | 27 #include "net/quic/core/quic_flow_controller.h" |
| 28 #include "net/quic/core/quic_iovector.h" | 28 #include "net/quic/core/quic_iovector.h" |
| 29 #include "net/quic/core/quic_packets.h" | 29 #include "net/quic/core/quic_packets.h" |
| 30 #include "net/quic/core/quic_stream_sequencer.h" | 30 #include "net/quic/core/quic_stream_sequencer.h" |
| 31 #include "net/quic/core/quic_types.h" | 31 #include "net/quic/core/quic_types.h" |
| 32 #include "net/quic/core/stream_notifier_interface.h" |
| 32 #include "net/quic/platform/api/quic_export.h" | 33 #include "net/quic/platform/api/quic_export.h" |
| 33 #include "net/quic/platform/api/quic_reference_counted.h" | 34 #include "net/quic/platform/api/quic_reference_counted.h" |
| 34 #include "net/quic/platform/api/quic_string_piece.h" | 35 #include "net/quic/platform/api/quic_string_piece.h" |
| 35 | 36 |
| 36 namespace net { | 37 namespace net { |
| 37 | 38 |
| 38 namespace test { | 39 namespace test { |
| 39 class QuicStreamPeer; | 40 class QuicStreamPeer; |
| 40 } // namespace test | 41 } // namespace test |
| 41 | 42 |
| 42 class QuicSession; | 43 class QuicSession; |
| 43 | 44 |
| 44 class QUIC_EXPORT_PRIVATE QuicStream { | 45 class QUIC_EXPORT_PRIVATE QuicStream : public StreamNotifierInterface { |
| 45 public: | 46 public: |
| 46 QuicStream(QuicStreamId id, QuicSession* session); | 47 QuicStream(QuicStreamId id, QuicSession* session); |
| 47 | 48 |
| 48 virtual ~QuicStream(); | 49 ~QuicStream() override; |
| 49 | 50 |
| 50 // Not in use currently. | 51 // Not in use currently. |
| 51 void SetFromConfig(); | 52 void SetFromConfig(); |
| 52 | 53 |
| 53 // Called by the session when a (potentially duplicate) stream frame has been | 54 // Called by the session when a (potentially duplicate) stream frame has been |
| 54 // received for this stream. | 55 // received for this stream. |
| 55 virtual void OnStreamFrame(const QuicStreamFrame& frame); | 56 virtual void OnStreamFrame(const QuicStreamFrame& frame); |
| 56 | 57 |
| 57 // Called by the session when the connection becomes writeable to allow the | 58 // Called by the session when the connection becomes writeable to allow the |
| 58 // stream to write any pending data. | 59 // stream to write any pending data. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 | 85 |
| 85 // Called by the subclass or the sequencer to reset the stream from this | 86 // Called by the subclass or the sequencer to reset the stream from this |
| 86 // end. | 87 // end. |
| 87 virtual void Reset(QuicRstStreamErrorCode error); | 88 virtual void Reset(QuicRstStreamErrorCode error); |
| 88 | 89 |
| 89 // Called by the subclass or the sequencer to close the entire connection from | 90 // Called by the subclass or the sequencer to close the entire connection from |
| 90 // this end. | 91 // this end. |
| 91 virtual void CloseConnectionWithDetails(QuicErrorCode error, | 92 virtual void CloseConnectionWithDetails(QuicErrorCode error, |
| 92 const std::string& details); | 93 const std::string& details); |
| 93 | 94 |
| 95 // Returns true if this stream is still waiting for acks of sent data. |
| 96 // This will return false if all data has been acked, or if the stream |
| 97 // is no longer interested in data being acked (which happens when |
| 98 // a stream is reset because of an error). |
| 99 bool IsWaitingForAcks() const; |
| 100 |
| 94 QuicStreamId id() const { return id_; } | 101 QuicStreamId id() const { return id_; } |
| 95 | 102 |
| 96 QuicRstStreamErrorCode stream_error() const { return stream_error_; } | 103 QuicRstStreamErrorCode stream_error() const { return stream_error_; } |
| 97 QuicErrorCode connection_error() const { return connection_error_; } | 104 QuicErrorCode connection_error() const { return connection_error_; } |
| 98 | 105 |
| 99 bool reading_stopped() const { | 106 bool reading_stopped() const { |
| 100 return sequencer_.ignore_read_data() || read_side_closed_; | 107 return sequencer_.ignore_read_data() || read_side_closed_; |
| 101 } | 108 } |
| 102 bool write_side_closed() const { return write_side_closed_; } | 109 bool write_side_closed() const { return write_side_closed_; } |
| 103 | 110 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // If fin is true: if it is immediately passed on to the session, | 189 // If fin is true: if it is immediately passed on to the session, |
| 183 // write_side_closed() becomes true, otherwise fin_buffered_ becomes true. | 190 // write_side_closed() becomes true, otherwise fin_buffered_ becomes true. |
| 184 void WriteOrBufferData( | 191 void WriteOrBufferData( |
| 185 QuicStringPiece data, | 192 QuicStringPiece data, |
| 186 bool fin, | 193 bool fin, |
| 187 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); | 194 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 188 | 195 |
| 189 // Adds random padding after the fin is consumed for this stream. | 196 // Adds random padding after the fin is consumed for this stream. |
| 190 void AddRandomPaddingAfterFin(); | 197 void AddRandomPaddingAfterFin(); |
| 191 | 198 |
| 199 // StreamNotifierInterface methods: |
| 200 void OnStreamFrameAcked(const QuicStreamFrame& frame, |
| 201 QuicTime::Delta ack_delay_time) override; |
| 202 void OnStreamFrameRetransmitted(const QuicStreamFrame& frame) override; |
| 203 |
| 192 protected: | 204 protected: |
| 193 // Sends as many bytes in the first |count| buffers of |iov| to the connection | 205 // Sends as many bytes in the first |count| buffers of |iov| to the connection |
| 194 // as the connection will consume. | 206 // as the connection will consume. |
| 195 // If |ack_listener| is provided, then it will be notified once all | 207 // If |ack_listener| is provided, then it will be notified once all |
| 196 // the ACKs for this write have been received. | 208 // the ACKs for this write have been received. |
| 197 // Returns the number of bytes consumed by the connection. | 209 // Returns the number of bytes consumed by the connection. |
| 198 QuicConsumedData WritevData( | 210 QuicConsumedData WritevData( |
| 199 const struct iovec* iov, | 211 const struct iovec* iov, |
| 200 int iov_count, | 212 int iov_count, |
| 201 bool fin, | 213 bool fin, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 219 const QuicSession* session() const { return session_; } | 231 const QuicSession* session() const { return session_; } |
| 220 QuicSession* session() { return session_; } | 232 QuicSession* session() { return session_; } |
| 221 | 233 |
| 222 const QuicStreamSequencer* sequencer() const { return &sequencer_; } | 234 const QuicStreamSequencer* sequencer() const { return &sequencer_; } |
| 223 QuicStreamSequencer* sequencer() { return &sequencer_; } | 235 QuicStreamSequencer* sequencer() { return &sequencer_; } |
| 224 | 236 |
| 225 void DisableConnectionFlowControlForThisStream() { | 237 void DisableConnectionFlowControlForThisStream() { |
| 226 stream_contributes_to_connection_flow_control_ = false; | 238 stream_contributes_to_connection_flow_control_ = false; |
| 227 } | 239 } |
| 228 | 240 |
| 241 void set_ack_listener( |
| 242 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 243 ack_listener_ = std::move(ack_listener); |
| 244 } |
| 245 |
| 229 private: | 246 private: |
| 230 friend class test::QuicStreamPeer; | 247 friend class test::QuicStreamPeer; |
| 231 friend class QuicStreamUtils; | 248 friend class QuicStreamUtils; |
| 232 | 249 |
| 233 // Close the read side of the socket. May cause the stream to be closed. | 250 // Close the read side of the socket. May cause the stream to be closed. |
| 234 // Subclasses and consumers should use StopReading to terminate reading early. | 251 // Subclasses and consumers should use StopReading to terminate reading early. |
| 235 void CloseReadSide(); | 252 void CloseReadSide(); |
| 236 | 253 |
| 237 // Subclasses and consumers should use reading_stopped. | 254 // Subclasses and consumers should use reading_stopped. |
| 238 bool read_side_closed() const { return read_side_closed_; } | 255 bool read_side_closed() const { return read_side_closed_; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 263 uint64_t queued_data_bytes_; | 280 uint64_t queued_data_bytes_; |
| 264 | 281 |
| 265 QuicStreamSequencer sequencer_; | 282 QuicStreamSequencer sequencer_; |
| 266 QuicStreamId id_; | 283 QuicStreamId id_; |
| 267 // Pointer to the owning QuicSession object. | 284 // Pointer to the owning QuicSession object. |
| 268 QuicSession* session_; | 285 QuicSession* session_; |
| 269 // Bytes read and written refer to payload bytes only: they do not include | 286 // Bytes read and written refer to payload bytes only: they do not include |
| 270 // framing, encryption overhead etc. | 287 // framing, encryption overhead etc. |
| 271 uint64_t stream_bytes_read_; | 288 uint64_t stream_bytes_read_; |
| 272 uint64_t stream_bytes_written_; | 289 uint64_t stream_bytes_written_; |
| 290 // Written bytes which have been acked. |
| 291 uint64_t stream_bytes_acked_; |
| 273 | 292 |
| 274 // Stream error code received from a RstStreamFrame or error code sent by the | 293 // Stream error code received from a RstStreamFrame or error code sent by the |
| 275 // visitor or sequencer in the RstStreamFrame. | 294 // visitor or sequencer in the RstStreamFrame. |
| 276 QuicRstStreamErrorCode stream_error_; | 295 QuicRstStreamErrorCode stream_error_; |
| 277 // Connection error code due to which the stream was closed. |stream_error_| | 296 // Connection error code due to which the stream was closed. |stream_error_| |
| 278 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers | 297 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers |
| 279 // should check |connection_error_|. | 298 // should check |connection_error_|. |
| 280 QuicErrorCode connection_error_; | 299 QuicErrorCode connection_error_; |
| 281 | 300 |
| 282 // True if the read side is closed and further frames should be rejected. | 301 // True if the read side is closed and further frames should be rejected. |
| 283 bool read_side_closed_; | 302 bool read_side_closed_; |
| 284 // True if the write side is closed, and further writes should fail. | 303 // True if the write side is closed, and further writes should fail. |
| 285 bool write_side_closed_; | 304 bool write_side_closed_; |
| 286 | 305 |
| 287 // True if the subclass has written a FIN with WriteOrBufferData, but it was | 306 // True if the subclass has written a FIN with WriteOrBufferData, but it was |
| 288 // buffered in queued_data_ rather than being sent to the session. | 307 // buffered in queued_data_ rather than being sent to the session. |
| 289 bool fin_buffered_; | 308 bool fin_buffered_; |
| 290 // True if a FIN has been sent to the session. | 309 // True if a FIN has been sent to the session. |
| 291 bool fin_sent_; | 310 bool fin_sent_; |
| 311 // True if a FIN has been acked. |
| 312 bool fin_acked_; |
| 292 | 313 |
| 293 // True if this stream has received (and the sequencer has accepted) a | 314 // True if this stream has received (and the sequencer has accepted) a |
| 294 // StreamFrame with the FIN set. | 315 // StreamFrame with the FIN set. |
| 295 bool fin_received_; | 316 bool fin_received_; |
| 296 | 317 |
| 297 // True if an RST_STREAM has been sent to the session. | 318 // True if an RST_STREAM has been sent to the session. |
| 298 // In combination with fin_sent_, used to ensure that a FIN and/or a | 319 // In combination with fin_sent_, used to ensure that a FIN and/or a |
| 299 // RST_STREAM is always sent to terminate the stream. | 320 // RST_STREAM is always sent to terminate the stream. |
| 300 bool rst_sent_; | 321 bool rst_sent_; |
| 301 | 322 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 317 bool stream_contributes_to_connection_flow_control_; | 338 bool stream_contributes_to_connection_flow_control_; |
| 318 | 339 |
| 319 // A counter incremented when OnCanWrite() is called and no progress is made. | 340 // A counter incremented when OnCanWrite() is called and no progress is made. |
| 320 // For debugging only. | 341 // For debugging only. |
| 321 size_t busy_counter_; | 342 size_t busy_counter_; |
| 322 | 343 |
| 323 // Indicates whether paddings will be added after the fin is consumed for this | 344 // Indicates whether paddings will be added after the fin is consumed for this |
| 324 // stream. | 345 // stream. |
| 325 bool add_random_padding_after_fin_; | 346 bool add_random_padding_after_fin_; |
| 326 | 347 |
| 348 // Ack listener of this stream, and it is notified when any of written bytes |
| 349 // are acked. |
| 350 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener_; |
| 351 |
| 327 DISALLOW_COPY_AND_ASSIGN(QuicStream); | 352 DISALLOW_COPY_AND_ASSIGN(QuicStream); |
| 328 }; | 353 }; |
| 329 | 354 |
| 330 } // namespace net | 355 } // namespace net |
| 331 | 356 |
| 332 #endif // NET_QUIC_CORE_QUIC_STREAM_H_ | 357 #endif // NET_QUIC_CORE_QUIC_STREAM_H_ |
| OLD | NEW |