OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_BUFFER_H_ | 5 #ifndef NET_QUIC_QUIC_STREAM_SEQUENCER_BUFFER_H_ |
6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_BUFFER_H_ | 6 #define NET_QUIC_QUIC_STREAM_SEQUENCER_BUFFER_H_ |
7 | 7 |
8 // QuicStreamSequencerBuffer implements QuicStreamSequencerBufferInterface. | 8 // QuicStreamSequencerBuffer implements QuicStreamSequencerBufferInterface. |
9 // It is a circular stream buffer with random write and | 9 // It is a circular stream buffer with random write and |
10 // in-sequence read. It consists of a vector of pointers pointing | 10 // in-sequence read. It consists of a vector of pointers pointing |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // Called after GetReadableRegions() to free up |bytes_used| space if these | 146 // Called after GetReadableRegions() to free up |bytes_used| space if these |
147 // bytes are processed. | 147 // bytes are processed. |
148 // Pre-requisite: bytes_used <= available bytes to read. | 148 // Pre-requisite: bytes_used <= available bytes to read. |
149 bool MarkConsumed(size_t bytes_buffered); | 149 bool MarkConsumed(size_t bytes_buffered); |
150 | 150 |
151 // Deletes and records as consumed any buffered data and clear the buffer. | 151 // Deletes and records as consumed any buffered data and clear the buffer. |
152 // (To be called only after sequencer's StopReading has been called.) | 152 // (To be called only after sequencer's StopReading has been called.) |
153 size_t FlushBufferedFrames(); | 153 size_t FlushBufferedFrames(); |
154 | 154 |
| 155 // Free the memory of buffered data. |
| 156 void ReleaseWholeBuffer(); |
| 157 |
155 // Whether there are bytes can be read out. | 158 // Whether there are bytes can be read out. |
156 bool HasBytesToRead() const; | 159 bool HasBytesToRead() const; |
157 | 160 |
158 // Count how many bytes have been consumed (read out of buffer). | 161 // Count how many bytes have been consumed (read out of buffer). |
159 QuicStreamOffset BytesConsumed() const; | 162 QuicStreamOffset BytesConsumed() const; |
160 | 163 |
161 // Count how many bytes are in buffer at this moment. | 164 // Count how many bytes are in buffer at this moment. |
162 size_t BytesBuffered() const; | 165 size_t BytesBuffered() const; |
163 | 166 |
| 167 bool reduce_sequencer_buffer_memory_life_time() const { |
| 168 return reduce_sequencer_buffer_memory_life_time_; |
| 169 } |
| 170 |
164 private: | 171 private: |
165 friend class test::QuicStreamSequencerBufferPeer; | 172 friend class test::QuicStreamSequencerBufferPeer; |
166 | 173 |
167 // Dispose the given buffer block. | 174 // Dispose the given buffer block. |
168 // After calling this method, blocks_[index] is set to nullptr | 175 // After calling this method, blocks_[index] is set to nullptr |
169 // in order to indicate that no memory set is allocated for that block. | 176 // in order to indicate that no memory set is allocated for that block. |
170 void RetireBlock(size_t index); | 177 void RetireBlock(size_t index); |
171 | 178 |
172 // Should only be called after the indexed block is read till the end of the | 179 // Should only be called after the indexed block is read till the end of the |
173 // block or a gap has been reached. | 180 // block or a gap has been reached. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 228 |
222 // How many blocks this buffer would need when it reaches full capacity. | 229 // How many blocks this buffer would need when it reaches full capacity. |
223 const size_t blocks_count_; | 230 const size_t blocks_count_; |
224 | 231 |
225 // Number of bytes read out of buffer. | 232 // Number of bytes read out of buffer. |
226 QuicStreamOffset total_bytes_read_; | 233 QuicStreamOffset total_bytes_read_; |
227 | 234 |
228 // Contains Gaps which represents currently missing data. | 235 // Contains Gaps which represents currently missing data. |
229 std::list<Gap> gaps_; | 236 std::list<Gap> gaps_; |
230 | 237 |
| 238 // If true, allocate buffer memory upon the first frame arrival and release |
| 239 // the memory when stream is read closed. |
| 240 bool reduce_sequencer_buffer_memory_life_time_; |
| 241 |
231 // An ordered, variable-length list of blocks, with the length limited | 242 // An ordered, variable-length list of blocks, with the length limited |
232 // such that the number of blocks never exceeds blocks_count_. | 243 // such that the number of blocks never exceeds blocks_count_. |
233 // Each list entry can hold up to kBlockSizeBytes bytes. | 244 // Each list entry can hold up to kBlockSizeBytes bytes. |
234 std::vector<BufferBlock*> blocks_; | 245 std::unique_ptr<BufferBlock* []> blocks_; |
235 | 246 |
236 // Number of bytes in buffer. | 247 // Number of bytes in buffer. |
237 size_t num_bytes_buffered_; | 248 size_t num_bytes_buffered_; |
238 | 249 |
239 // Stores all the buffered frames' start offset, length and arrival time. | 250 // Stores all the buffered frames' start offset, length and arrival time. |
240 std::map<QuicStreamOffset, FrameInfo> frame_arrival_time_map_; | 251 std::map<QuicStreamOffset, FrameInfo> frame_arrival_time_map_; |
241 | 252 |
242 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer); | 253 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer); |
243 }; | 254 }; |
244 } // namespace net | 255 } // namespace net |
245 | 256 |
246 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_BUFFER_H_ | 257 #endif // NET_QUIC_QUIC_STREAM_SEQUENCER_BUFFER_H_ |
OLD | NEW |