| 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 #ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 5 #ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
| 6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // If the frame is the next one we need in order to process in-order data, | 42 // If the frame is the next one we need in order to process in-order data, |
| 43 // ProcessData will be immediately called on the stream until all buffered | 43 // ProcessData will be immediately called on the stream until all buffered |
| 44 // data is processed or the stream fails to consume data. Any unconsumed | 44 // data is processed or the stream fails to consume data. Any unconsumed |
| 45 // data will be buffered. | 45 // data will be buffered. |
| 46 // | 46 // |
| 47 // If the frame is not the next in line, it will either be buffered, and | 47 // If the frame is not the next in line, it will either be buffered, and |
| 48 // this will return true, or it will be rejected and this will return false. | 48 // this will return true, or it will be rejected and this will return false. |
| 49 bool OnStreamFrame(const QuicStreamFrame& frame); | 49 bool OnStreamFrame(const QuicStreamFrame& frame); |
| 50 | 50 |
| 51 // Wait until we've seen 'offset' bytes, and then terminate the stream. | 51 // Wait until we've seen 'offset' bytes, and then terminate the stream. |
| 52 // TODO(ianswett): Simplify this method by removing half_close, now that |
| 53 // the sequencer is bypassed for stream resets and half_close is always true. |
| 52 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); | 54 void CloseStreamAtOffset(QuicStreamOffset offset, bool half_close); |
| 53 | 55 |
| 54 // Once data is buffered, it's up to the stream to read it when the stream | 56 // Once data is buffered, it's up to the stream to read it when the stream |
| 55 // can handle more data. The following three functions make that possible. | 57 // can handle more data. The following three functions make that possible. |
| 56 | 58 |
| 57 // Returns true if the sequncer has bytes available for reading. | 59 // Returns true if the sequncer has bytes available for reading. |
| 58 bool HasBytesToRead() const; | 60 bool HasBytesToRead() const; |
| 59 | 61 |
| 60 // Returns true if the sequencer has delivered a half close. | 62 // Returns true if the sequencer has delivered a half close. |
| 61 bool IsHalfClosed() const; | 63 bool IsHalfClosed() const; |
| 62 | 64 |
| 63 // Returns true if the sequencer has delivered a full close. | 65 // Returns true if the sequencer has delivered a full close. |
| 64 bool IsClosed() const; | 66 bool IsClosed() const; |
| 65 | 67 |
| 68 // Returns true if the sequencer has received this frame before. |
| 69 bool IsDuplicate(const QuicStreamFrame& frame) const; |
| 70 |
| 66 private: | 71 private: |
| 67 friend class test::QuicStreamSequencerPeer; | 72 friend class test::QuicStreamSequencerPeer; |
| 68 | 73 |
| 69 // TODO(alyssar) use something better than strings. | 74 // TODO(alyssar) use something better than strings. |
| 70 typedef map<QuicStreamOffset, string> FrameMap; | 75 typedef map<QuicStreamOffset, string> FrameMap; |
| 71 | 76 |
| 72 void FlushBufferedFrames(); | 77 void FlushBufferedFrames(); |
| 73 | 78 |
| 74 bool MaybeCloseStream(); | 79 bool MaybeCloseStream(); |
| 75 | 80 |
| 76 ReliableQuicStream* stream_; // The stream which owns this sequencer. | 81 ReliableQuicStream* stream_; // The stream which owns this sequencer. |
| 77 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream | 82 QuicStreamOffset num_bytes_consumed_; // The last data consumed by the stream |
| 78 FrameMap frames_; // sequence number -> frame | 83 FrameMap frames_; // sequence number -> frame |
| 79 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. | 84 size_t max_frame_memory_; // the maximum memory the sequencer can buffer. |
| 80 // The offset, if any, we got a stream cancelation for. When this many bytes | 85 // The offset, if any, we got a stream cancelation for. When this many bytes |
| 81 // have been processed, the stream will be half or full closed depending on | 86 // have been processed, the stream will be half or full closed depending on |
| 82 // the half_close_ bool. | 87 // the half_close_ bool. |
| 83 QuicStreamOffset close_offset_; | 88 QuicStreamOffset close_offset_; |
| 84 // Only valid if close_offset_ is set. Indicates if it's a half or a full | 89 // Only valid if close_offset_ is set. Indicates if it's a half or a full |
| 85 // close. | 90 // close. |
| 86 bool half_close_; | 91 bool half_close_; |
| 87 }; | 92 }; |
| 88 | 93 |
| 89 } // namespace net | 94 } // namespace net |
| 90 | 95 |
| 91 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 96 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
| OLD | NEW |