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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 // Returns true if the sequncer has bytes available for reading. | 52 // Returns true if the sequncer has bytes available for reading. |
53 bool HasBytesToRead() const; | 53 bool HasBytesToRead() const; |
54 | 54 |
55 // Returns true if the sequencer has delivered the fin. | 55 // Returns true if the sequencer has delivered the fin. |
56 bool IsClosed() const; | 56 bool IsClosed() const; |
57 | 57 |
58 // Returns true if the sequencer has received this frame before. | 58 // Returns true if the sequencer has received this frame before. |
59 bool IsDuplicate(const QuicStreamFrame& frame) const; | 59 bool IsDuplicate(const QuicStreamFrame& frame) const; |
60 | 60 |
| 61 // Returns true if |frame| contains data which overlaps buffered data |
| 62 // (indicating an invalid stream frame has been received). |
| 63 bool FrameOverlapsBufferedData(const QuicStreamFrame& frame) const; |
| 64 |
61 // Calls |ProcessRawData| on |stream_| for each buffered frame that may | 65 // Calls |ProcessRawData| on |stream_| for each buffered frame that may |
62 // be processed. | 66 // be processed. |
63 void FlushBufferedFrames(); | 67 void FlushBufferedFrames(); |
64 | 68 |
65 // Blocks processing of frames until |FlushBufferedFrames| is called. | 69 // Blocks processing of frames until |FlushBufferedFrames| is called. |
66 void SetBlockedUntilFlush(); | 70 void SetBlockedUntilFlush(); |
67 | 71 |
68 size_t num_bytes_buffered() const { return num_bytes_buffered_; } | 72 size_t num_bytes_buffered() const { return num_bytes_buffered_; } |
69 QuicStreamOffset num_bytes_consumed() const { return num_bytes_consumed_; } | 73 QuicStreamOffset num_bytes_consumed() const { return num_bytes_consumed_; } |
70 | 74 |
(...skipping 17 matching lines...) Expand all Loading... |
88 // num_bytes_consumed_ and num_bytes_buffered_. | 92 // num_bytes_consumed_ and num_bytes_buffered_. |
89 void RecordBytesConsumed(size_t bytes_consumed); | 93 void RecordBytesConsumed(size_t bytes_consumed); |
90 | 94 |
91 // The stream which owns this sequencer. | 95 // The stream which owns this sequencer. |
92 ReliableQuicStream* stream_; | 96 ReliableQuicStream* stream_; |
93 | 97 |
94 // The last data consumed by the stream. | 98 // The last data consumed by the stream. |
95 QuicStreamOffset num_bytes_consumed_; | 99 QuicStreamOffset num_bytes_consumed_; |
96 | 100 |
97 // TODO(alyssar) use something better than strings. | 101 // TODO(alyssar) use something better than strings. |
| 102 // TODO(rjshade): In future we may support retransmission of partial stream |
| 103 // frames, in which case we will have to allow receipt of overlapping frames. |
| 104 // Maybe write new frames into a ring buffer, and keep track of consumed |
| 105 // bytes, and gaps. |
98 typedef map<QuicStreamOffset, string> FrameMap; | 106 typedef map<QuicStreamOffset, string> FrameMap; |
99 | 107 |
100 // Stores buffered frames (maps from sequence number -> frame data as string). | 108 // Stores buffered frames (maps from sequence number -> frame data as string). |
101 FrameMap buffered_frames_; | 109 FrameMap buffered_frames_; |
102 | 110 |
103 // The offset, if any, we got a stream termination for. When this many bytes | 111 // The offset, if any, we got a stream termination for. When this many bytes |
104 // have been processed, the sequencer will be closed. | 112 // have been processed, the sequencer will be closed. |
105 QuicStreamOffset close_offset_; | 113 QuicStreamOffset close_offset_; |
106 | 114 |
107 // If true, the sequencer is blocked from passing data to the stream and will | 115 // If true, the sequencer is blocked from passing data to the stream and will |
108 // buffer all new incoming data until FlushBufferedFrames is called. | 116 // buffer all new incoming data until FlushBufferedFrames is called. |
109 bool blocked_; | 117 bool blocked_; |
110 | 118 |
111 // Tracks how many bytes the sequencer has buffered. | 119 // Tracks how many bytes the sequencer has buffered. |
112 size_t num_bytes_buffered_; | 120 size_t num_bytes_buffered_; |
113 | 121 |
114 // Count of the number of frames received. | 122 // Count of the number of frames received. |
115 int num_frames_received_; | 123 int num_frames_received_; |
116 | 124 |
117 // Count of the number of duplicate frames received. | 125 // Count of the number of duplicate frames received. |
118 int num_duplicate_frames_received_; | 126 int num_duplicate_frames_received_; |
119 | 127 |
120 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencer); | 128 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencer); |
121 }; | 129 }; |
122 | 130 |
123 } // namespace net | 131 } // namespace net |
124 | 132 |
125 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 133 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
OLD | NEW |