| 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 #include "net/quic/quic_stream_sequencer.h" | 5 #include "net/quic/quic_stream_sequencer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "net/quic/quic_bug_tracker.h" | 14 #include "net/quic/quic_bug_tracker.h" |
| 15 #include "net/quic/quic_clock.h" | 15 #include "net/quic/quic_clock.h" |
| 16 #include "net/quic/quic_flags.h" | 16 #include "net/quic/quic_flags.h" |
| 17 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/quic_stream_sequencer_buffer.h" | 18 #include "net/quic/quic_stream_sequencer_buffer.h" |
| 19 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
| 20 #include "net/quic/reliable_quic_stream.h" | 20 #include "net/quic/reliable_quic_stream.h" |
| 21 | 21 |
| 22 using base::IntToString; |
| 22 using base::StringPiece; | 23 using base::StringPiece; |
| 23 using std::min; | 24 using std::min; |
| 24 using std::numeric_limits; | 25 using std::numeric_limits; |
| 25 using std::string; | 26 using std::string; |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| 28 | 29 |
| 29 QuicStreamSequencer::QuicStreamSequencer(ReliableQuicStream* quic_stream, | 30 QuicStreamSequencer::QuicStreamSequencer(ReliableQuicStream* quic_stream, |
| 30 const QuicClock* clock) | 31 const QuicClock* clock) |
| 31 : stream_(quic_stream), | 32 : stream_(quic_stream), |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 bool QuicStreamSequencer::IsClosed() const { | 152 bool QuicStreamSequencer::IsClosed() const { |
| 152 return buffered_frames_.BytesConsumed() >= close_offset_; | 153 return buffered_frames_.BytesConsumed() >= close_offset_; |
| 153 } | 154 } |
| 154 | 155 |
| 155 void QuicStreamSequencer::MarkConsumed(size_t num_bytes_consumed) { | 156 void QuicStreamSequencer::MarkConsumed(size_t num_bytes_consumed) { |
| 156 DCHECK(!blocked_); | 157 DCHECK(!blocked_); |
| 157 bool result = buffered_frames_.MarkConsumed(num_bytes_consumed); | 158 bool result = buffered_frames_.MarkConsumed(num_bytes_consumed); |
| 158 if (!result) { | 159 if (!result) { |
| 159 QUIC_BUG << "Invalid argument to MarkConsumed." | 160 QUIC_BUG << "Invalid argument to MarkConsumed." |
| 160 << " expect to consume: " << num_bytes_consumed | 161 << " expect to consume: " << num_bytes_consumed |
| 161 << ", but not enough bytes available."; | 162 << ", but not enough bytes available. " << DebugString(); |
| 162 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); | 163 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); |
| 163 return; | 164 return; |
| 164 } | 165 } |
| 165 stream_->AddBytesConsumed(num_bytes_consumed); | 166 stream_->AddBytesConsumed(num_bytes_consumed); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void QuicStreamSequencer::SetBlockedUntilFlush() { | 169 void QuicStreamSequencer::SetBlockedUntilFlush() { |
| 169 blocked_ = true; | 170 blocked_ = true; |
| 170 } | 171 } |
| 171 | 172 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 195 } | 196 } |
| 196 | 197 |
| 197 size_t QuicStreamSequencer::NumBytesBuffered() const { | 198 size_t QuicStreamSequencer::NumBytesBuffered() const { |
| 198 return buffered_frames_.BytesBuffered(); | 199 return buffered_frames_.BytesBuffered(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 QuicStreamOffset QuicStreamSequencer::NumBytesConsumed() const { | 202 QuicStreamOffset QuicStreamSequencer::NumBytesConsumed() const { |
| 202 return buffered_frames_.BytesConsumed(); | 203 return buffered_frames_.BytesConsumed(); |
| 203 } | 204 } |
| 204 | 205 |
| 206 const string QuicStreamSequencer::DebugString() const { |
| 207 // clang-format off |
| 208 return "QuicStreamSequencer:" |
| 209 "\n bytes buffered: " + IntToString(NumBytesBuffered()) + |
| 210 "\n bytes consumed: " + IntToString( NumBytesConsumed()) + |
| 211 "\n has bytes to read: " + (HasBytesToRead() ? "true" : "false") + |
| 212 "\n frames received: " + IntToString(num_frames_received()) + |
| 213 "\n close offset bytes: " + IntToString( close_offset_) + |
| 214 "\n is closed: " + (IsClosed() ? "true" : "false"); |
| 215 // clang-format on |
| 216 } |
| 217 |
| 205 } // namespace net | 218 } // namespace net |
| OLD | NEW |