Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: net/quic/core/quic_stream_sequencer_buffer.cc

Issue 2487613002: Landing Recent QUIC changes until 12:43 PM, Nov 5, 2016 UTC+8 (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/quic/core/quic_stream_sequencer_buffer.h" 5 #include "net/quic/core/quic_stream_sequencer_buffer.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 QuicStreamSequencerBuffer::FrameInfo::FrameInfo(size_t length, 44 QuicStreamSequencerBuffer::FrameInfo::FrameInfo(size_t length,
45 QuicTime timestamp) 45 QuicTime timestamp)
46 : length(length), timestamp(timestamp) {} 46 : length(length), timestamp(timestamp) {}
47 47
48 QuicStreamSequencerBuffer::QuicStreamSequencerBuffer(size_t max_capacity_bytes) 48 QuicStreamSequencerBuffer::QuicStreamSequencerBuffer(size_t max_capacity_bytes)
49 : max_buffer_capacity_bytes_(max_capacity_bytes), 49 : max_buffer_capacity_bytes_(max_capacity_bytes),
50 blocks_count_( 50 blocks_count_(
51 ceil(static_cast<double>(max_capacity_bytes) / kBlockSizeBytes)), 51 ceil(static_cast<double>(max_capacity_bytes) / kBlockSizeBytes)),
52 total_bytes_read_(0), 52 total_bytes_read_(0),
53 reduce_sequencer_buffer_memory_life_time_( 53 blocks_(nullptr) {
54 FLAGS_quic_reduce_sequencer_buffer_memory_life_time), // NOLINT
55 blocks_(reduce_sequencer_buffer_memory_life_time_
56 ? nullptr
57 : new BufferBlock*[blocks_count_]()) {
58 Clear(); 54 Clear();
59 } 55 }
60 56
61 QuicStreamSequencerBuffer::~QuicStreamSequencerBuffer() { 57 QuicStreamSequencerBuffer::~QuicStreamSequencerBuffer() {
62 Clear(); 58 Clear();
63 } 59 }
64 60
65 void QuicStreamSequencerBuffer::Clear() { 61 void QuicStreamSequencerBuffer::Clear() {
66 if (!reduce_sequencer_buffer_memory_life_time_ || blocks_ != nullptr) { 62 if (blocks_ != nullptr) {
67 for (size_t i = 0; i < blocks_count_; ++i) { 63 for (size_t i = 0; i < blocks_count_; ++i) {
68 if (blocks_[i] != nullptr) { 64 if (blocks_[i] != nullptr) {
69 RetireBlock(i); 65 RetireBlock(i);
70 } 66 }
71 } 67 }
72 } 68 }
73 num_bytes_buffered_ = 0; 69 num_bytes_buffered_ = 0;
74 // Reset gaps_ so that buffer is in a state as if all data before 70 // Reset gaps_ so that buffer is in a state as if all data before
75 // total_bytes_read_ has been consumed, and those after total_bytes_read_ 71 // total_bytes_read_ has been consumed, and those after total_bytes_read_
76 // has never arrived. 72 // has never arrived.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 170
175 size_t block_capacity = GetBlockCapacity(write_block_num); 171 size_t block_capacity = GetBlockCapacity(write_block_num);
176 size_t bytes_avail = block_capacity - write_block_offset; 172 size_t bytes_avail = block_capacity - write_block_offset;
177 173
178 // If this write meets the upper boundary of the buffer, 174 // If this write meets the upper boundary of the buffer,
179 // reduce the available free bytes. 175 // reduce the available free bytes.
180 if (offset + bytes_avail > total_bytes_read_ + max_buffer_capacity_bytes_) { 176 if (offset + bytes_avail > total_bytes_read_ + max_buffer_capacity_bytes_) {
181 bytes_avail = total_bytes_read_ + max_buffer_capacity_bytes_ - offset; 177 bytes_avail = total_bytes_read_ + max_buffer_capacity_bytes_ - offset;
182 } 178 }
183 179
184 if (reduce_sequencer_buffer_memory_life_time_ && blocks_ == nullptr) { 180 if (blocks_ == nullptr) {
185 blocks_.reset(new BufferBlock*[blocks_count_]()); 181 blocks_.reset(new BufferBlock*[blocks_count_]());
186 for (size_t i = 0; i < blocks_count_; ++i) { 182 for (size_t i = 0; i < blocks_count_; ++i) {
187 blocks_[i] = nullptr; 183 blocks_[i] = nullptr;
188 } 184 }
189 } 185 }
190 186
191 if (write_block_num >= blocks_count_) { 187 if (write_block_num >= blocks_count_) {
192 *error_details = StringPrintf( 188 *error_details = StringPrintf(
193 "QuicStreamSequencerBuffer error: OnStreamData() exceed array bounds." 189 "QuicStreamSequencerBuffer error: OnStreamData() exceed array bounds."
194 "write offset = %" PRIu64 " write_block_num = %" PRIuS 190 "write offset = %" PRIu64 " write_block_num = %" PRIuS
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 451 }
456 452
457 size_t QuicStreamSequencerBuffer::FlushBufferedFrames() { 453 size_t QuicStreamSequencerBuffer::FlushBufferedFrames() {
458 size_t prev_total_bytes_read = total_bytes_read_; 454 size_t prev_total_bytes_read = total_bytes_read_;
459 total_bytes_read_ = gaps_.back().begin_offset; 455 total_bytes_read_ = gaps_.back().begin_offset;
460 Clear(); 456 Clear();
461 return total_bytes_read_ - prev_total_bytes_read; 457 return total_bytes_read_ - prev_total_bytes_read;
462 } 458 }
463 459
464 void QuicStreamSequencerBuffer::ReleaseWholeBuffer() { 460 void QuicStreamSequencerBuffer::ReleaseWholeBuffer() {
465 if (!reduce_sequencer_buffer_memory_life_time_) {
466 // Don't release buffer if flag is off.
467 return;
468 }
469 Clear(); 461 Clear();
470 blocks_.reset(nullptr); 462 blocks_.reset(nullptr);
471 } 463 }
472 464
473 size_t QuicStreamSequencerBuffer::ReadableBytes() const { 465 size_t QuicStreamSequencerBuffer::ReadableBytes() const {
474 return gaps_.front().begin_offset - total_bytes_read_; 466 return gaps_.front().begin_offset - total_bytes_read_;
475 } 467 }
476 468
477 bool QuicStreamSequencerBuffer::HasBytesToRead() const { 469 bool QuicStreamSequencerBuffer::HasBytesToRead() const {
478 return ReadableBytes() > 0; 470 return ReadableBytes() > 0;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 QuicStreamOffset current_frame_end_offset = 582 QuicStreamOffset current_frame_end_offset =
591 it.second.length + current_frame_begin_offset; 583 it.second.length + current_frame_begin_offset;
592 current_frames_string = string(StringPrintf( 584 current_frames_string = string(StringPrintf(
593 "%s[%" PRIu64 ", %" PRIu64 ") ", current_frames_string.c_str(), 585 "%s[%" PRIu64 ", %" PRIu64 ") ", current_frames_string.c_str(),
594 current_frame_begin_offset, current_frame_end_offset)); 586 current_frame_begin_offset, current_frame_end_offset));
595 } 587 }
596 return current_frames_string; 588 return current_frames_string;
597 } 589 }
598 590
599 } // namespace net 591 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_stream_sequencer_buffer.h ('k') | net/quic/core/quic_stream_sequencer_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698