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 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 void SetUnblocked(); | 71 void SetUnblocked(); |
72 | 72 |
73 // Blocks processing of frames until |SetUnblocked| is called. | 73 // Blocks processing of frames until |SetUnblocked| is called. |
74 void SetBlockedUntilFlush(); | 74 void SetBlockedUntilFlush(); |
75 | 75 |
76 // Sets the sequencer to discard all incoming data itself and not call | 76 // Sets the sequencer to discard all incoming data itself and not call |
77 // |stream_->OnDataAvailable()|. |stream_->OnFinRead()| will be called | 77 // |stream_->OnDataAvailable()|. |stream_->OnFinRead()| will be called |
78 // automatically when the FIN is consumed (which may be immediately). | 78 // automatically when the FIN is consumed (which may be immediately). |
79 void StopReading(); | 79 void StopReading(); |
80 | 80 |
81 size_t num_bytes_buffered() const { return num_bytes_buffered_; } | 81 // Number of bytes in the buffer right now. |
82 QuicStreamOffset num_bytes_consumed() const { return num_bytes_consumed_; } | 82 size_t NumBytesBuffered() const; |
83 | |
84 // Number of bytes has been consumed. | |
85 QuicStreamOffset NumBytesConsumed() const; | |
83 | 86 |
84 int num_frames_received() const { return num_frames_received_; } | 87 int num_frames_received() const { return num_frames_received_; } |
85 | 88 |
86 int num_duplicate_frames_received() const { | 89 int num_duplicate_frames_received() const { |
87 return num_duplicate_frames_received_; | 90 return num_duplicate_frames_received_; |
88 } | 91 } |
89 | 92 |
90 int num_early_frames_received() const { return num_early_frames_received_; } | 93 int num_early_frames_received() const { return num_early_frames_received_; } |
91 | 94 |
92 bool ignore_read_data() const { return ignore_read_data_; } | 95 bool ignore_read_data() const { return ignore_read_data_; } |
93 | 96 |
94 private: | 97 private: |
95 friend class test::QuicStreamSequencerPeer; | 98 friend class test::QuicStreamSequencerPeer; |
96 | 99 |
97 // Deletes and records as consumed any buffered data that is now in-sequence. | 100 // Deletes and records as consumed any buffered data that is now in-sequence. |
98 // (To be called only after StopReading has been called.) | 101 // (To be called only after StopReading has been called.) |
99 void FlushBufferedFrames(); | 102 void FlushBufferedFrames(); |
100 | 103 |
101 // Wait until we've seen 'offset' bytes, and then terminate the stream. | 104 // Wait until we've seen 'offset' bytes, and then terminate the stream. |
102 void CloseStreamAtOffset(QuicStreamOffset offset); | 105 void CloseStreamAtOffset(QuicStreamOffset offset); |
103 | 106 |
104 // If we've received a FIN and have processed all remaining data, then inform | 107 // If we've received a FIN and have processed all remaining data, then inform |
105 // the stream of FIN, and clear buffers. | 108 // the stream of FIN, and clear buffers. |
106 bool MaybeCloseStream(); | 109 bool MaybeCloseStream(); |
107 | 110 |
108 // Called whenever bytes are consumed by the stream. Updates | |
109 // num_bytes_consumed_ and num_bytes_buffered_. | |
110 void RecordBytesConsumed(size_t bytes_consumed); | |
111 | |
112 // The stream which owns this sequencer. | 111 // The stream which owns this sequencer. |
113 ReliableQuicStream* stream_; | 112 ReliableQuicStream* stream_; |
114 | 113 |
115 // The last data consumed by the stream. | 114 // Stores received data in offset order. |
116 QuicStreamOffset num_bytes_consumed_; | 115 std::unique_ptr<QuicStreamSequencerBufferInterface> buffered_frames_; |
Ryan Hamilton
2015/10/21 16:44:52
use scoped_ptr instead of std::unique_ptr or this
| |
117 | |
118 // Stores buffered frames in offset order. | |
119 QuicFrameList buffered_frames_; | |
120 | 116 |
121 // The offset, if any, we got a stream termination for. When this many bytes | 117 // The offset, if any, we got a stream termination for. When this many bytes |
122 // have been processed, the sequencer will be closed. | 118 // have been processed, the sequencer will be closed. |
123 QuicStreamOffset close_offset_; | 119 QuicStreamOffset close_offset_; |
124 | 120 |
125 // If true, the sequencer is blocked from passing data to the stream and will | 121 // If true, the sequencer is blocked from passing data to the stream and will |
126 // buffer all new incoming data until FlushBufferedFrames is called. | 122 // buffer all new incoming data until FlushBufferedFrames is called. |
127 bool blocked_; | 123 bool blocked_; |
128 | 124 |
129 // Tracks how many bytes the sequencer has buffered. | |
130 size_t num_bytes_buffered_; | |
131 | |
132 // Count of the number of frames received. | 125 // Count of the number of frames received. |
133 int num_frames_received_; | 126 int num_frames_received_; |
134 | 127 |
135 // Count of the number of duplicate frames received. | 128 // Count of the number of duplicate frames received. |
136 int num_duplicate_frames_received_; | 129 int num_duplicate_frames_received_; |
137 | 130 |
138 // Count of the number of frames received before all previous frames were | 131 // Count of the number of frames received before all previous frames were |
139 // received. | 132 // received. |
140 int num_early_frames_received_; | 133 int num_early_frames_received_; |
141 | 134 |
142 // Not owned. | 135 // Not owned. |
143 const QuicClock* clock_; | 136 const QuicClock* clock_; |
144 | 137 |
145 // If true, all incoming data will be discarded. | 138 // If true, all incoming data will be discarded. |
146 bool ignore_read_data_; | 139 bool ignore_read_data_; |
147 | 140 |
148 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencer); | 141 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencer); |
149 }; | 142 }; |
150 | 143 |
151 } // namespace net | 144 } // namespace net |
152 | 145 |
153 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ | 146 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_H_ |
OLD | NEW |