| 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_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ |
| 6 #define NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ | 6 #define NET_QUIC_CORE_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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 // Whether there are bytes can be read out. | 162 // Whether there are bytes can be read out. |
| 163 bool HasBytesToRead() const; | 163 bool HasBytesToRead() const; |
| 164 | 164 |
| 165 // Count how many bytes have been consumed (read out of buffer). | 165 // Count how many bytes have been consumed (read out of buffer). |
| 166 QuicStreamOffset BytesConsumed() const; | 166 QuicStreamOffset BytesConsumed() const; |
| 167 | 167 |
| 168 // Count how many bytes are in buffer at this moment. | 168 // Count how many bytes are in buffer at this moment. |
| 169 size_t BytesBuffered() const; | 169 size_t BytesBuffered() const; |
| 170 | 170 |
| 171 bool reduce_sequencer_buffer_memory_life_time() const { |
| 172 return reduce_sequencer_buffer_memory_life_time_; |
| 173 } |
| 174 |
| 171 private: | 175 private: |
| 172 friend class test::QuicStreamSequencerBufferPeer; | 176 friend class test::QuicStreamSequencerBufferPeer; |
| 173 | 177 |
| 174 // Dispose the given buffer block. | 178 // Dispose the given buffer block. |
| 175 // After calling this method, blocks_[index] is set to nullptr | 179 // After calling this method, blocks_[index] is set to nullptr |
| 176 // in order to indicate that no memory set is allocated for that block. | 180 // in order to indicate that no memory set is allocated for that block. |
| 177 // Returns true on success, false otherwise. | 181 // Returns true on success, false otherwise. |
| 178 bool RetireBlock(size_t index); | 182 bool RetireBlock(size_t index); |
| 179 | 183 |
| 180 // Should only be called after the indexed block is read till the end of the | 184 // Should only be called after the indexed block is read till the end of the |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 234 |
| 231 // How many blocks this buffer would need when it reaches full capacity. | 235 // How many blocks this buffer would need when it reaches full capacity. |
| 232 const size_t blocks_count_; | 236 const size_t blocks_count_; |
| 233 | 237 |
| 234 // Number of bytes read out of buffer. | 238 // Number of bytes read out of buffer. |
| 235 QuicStreamOffset total_bytes_read_; | 239 QuicStreamOffset total_bytes_read_; |
| 236 | 240 |
| 237 // Contains Gaps which represents currently missing data. | 241 // Contains Gaps which represents currently missing data. |
| 238 std::list<Gap> gaps_; | 242 std::list<Gap> gaps_; |
| 239 | 243 |
| 244 // If true, allocate buffer memory upon the first frame arrival and release |
| 245 // the memory when stream is read closed. |
| 246 bool reduce_sequencer_buffer_memory_life_time_; |
| 247 |
| 240 // An ordered, variable-length list of blocks, with the length limited | 248 // An ordered, variable-length list of blocks, with the length limited |
| 241 // such that the number of blocks never exceeds blocks_count_. | 249 // such that the number of blocks never exceeds blocks_count_. |
| 242 // Each list entry can hold up to kBlockSizeBytes bytes. | 250 // Each list entry can hold up to kBlockSizeBytes bytes. |
| 243 std::unique_ptr<BufferBlock* []> blocks_; | 251 std::unique_ptr<BufferBlock* []> blocks_; |
| 244 | 252 |
| 245 // Number of bytes in buffer. | 253 // Number of bytes in buffer. |
| 246 size_t num_bytes_buffered_; | 254 size_t num_bytes_buffered_; |
| 247 | 255 |
| 248 // Stores all the buffered frames' start offset, length and arrival time. | 256 // Stores all the buffered frames' start offset, length and arrival time. |
| 249 std::map<QuicStreamOffset, FrameInfo> frame_arrival_time_map_; | 257 std::map<QuicStreamOffset, FrameInfo> frame_arrival_time_map_; |
| 250 | 258 |
| 251 // For debugging use after free, assigned to 123456 in constructor and 654321 | 259 // For debugging use after free, assigned to 123456 in constructor and 654321 |
| 252 // in destructor. As long as it's not 123456, this means either use after free | 260 // in destructor. As long as it's not 123456, this means either use after free |
| 253 // or memory corruption. | 261 // or memory corruption. |
| 254 int32_t destruction_indicator_; | 262 int32_t destruction_indicator_; |
| 255 | 263 |
| 256 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer); | 264 DISALLOW_COPY_AND_ASSIGN(QuicStreamSequencerBuffer); |
| 257 }; | 265 }; |
| 258 } // namespace net | 266 } // namespace net |
| 259 | 267 |
| 260 #endif // NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ | 268 #endif // NET_QUIC_CORE_QUIC_STREAM_SEQUENCER_BUFFER_H_ |
| OLD | NEW |