| 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/core/quic_stream_sequencer.h" | 5 #include "net/quic/core/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/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "net/quic/core/quic_bug_tracker.h" | 16 #include "net/quic/core/quic_bug_tracker.h" |
| 17 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
| 18 #include "net/quic/core/quic_packets.h" | 18 #include "net/quic/core/quic_packets.h" |
| 19 #include "net/quic/core/quic_stream.h" | 19 #include "net/quic/core/quic_stream.h" |
| 20 #include "net/quic/core/quic_stream_sequencer_buffer.h" | 20 #include "net/quic/core/quic_stream_sequencer_buffer.h" |
| 21 #include "net/quic/core/quic_utils.h" | 21 #include "net/quic/core/quic_utils.h" |
| 22 #include "net/quic/platform/api/quic_clock.h" | 22 #include "net/quic/platform/api/quic_clock.h" |
| 23 #include "net/quic/platform/api/quic_str_cat.h" |
| 23 | 24 |
| 24 using base::IntToString; | 25 using base::IntToString; |
| 25 using base::StringPiece; | 26 using base::StringPiece; |
| 26 using base::StringPrintf; | 27 using base::StringPrintf; |
| 27 using std::string; | 28 using std::string; |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 QuicStreamSequencer::QuicStreamSequencer(QuicStream* quic_stream, | 32 QuicStreamSequencer::QuicStreamSequencer(QuicStream* quic_stream, |
| 32 const QuicClock* clock) | 33 const QuicClock* clock) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 51 if (data_len == 0) { | 52 if (data_len == 0) { |
| 52 return; | 53 return; |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 size_t bytes_written; | 56 size_t bytes_written; |
| 56 string error_details; | 57 string error_details; |
| 57 QuicErrorCode result = buffered_frames_.OnStreamData( | 58 QuicErrorCode result = buffered_frames_.OnStreamData( |
| 58 byte_offset, StringPiece(frame.data_buffer, frame.data_length), | 59 byte_offset, StringPiece(frame.data_buffer, frame.data_length), |
| 59 clock_->ApproximateNow(), &bytes_written, &error_details); | 60 clock_->ApproximateNow(), &bytes_written, &error_details); |
| 60 if (result != QUIC_NO_ERROR) { | 61 if (result != QUIC_NO_ERROR) { |
| 61 string details = "Stream" + base::Uint64ToString(stream_->id()) + ": " + | 62 string details = QuicStrCat( |
| 62 QuicErrorCodeToString(result) + ": " + error_details + | 63 "Stream ", stream_->id(), ": ", QuicErrorCodeToString(result), ": ", |
| 63 "\nPeer Address: " + | 64 error_details, "\nPeer Address: ", |
| 64 stream_->PeerAddressOfLatestPacket().ToString(); | 65 stream_->PeerAddressOfLatestPacket().ToString()); |
| 65 DLOG(WARNING) << QuicErrorCodeToString(result); | 66 DLOG(WARNING) << QuicErrorCodeToString(result); |
| 66 DLOG(WARNING) << details; | 67 DLOG(WARNING) << details; |
| 67 stream_->CloseConnectionWithDetails(result, details); | 68 stream_->CloseConnectionWithDetails(result, details); |
| 68 return; | 69 return; |
| 69 } | 70 } |
| 70 | 71 |
| 71 if (bytes_written == 0) { | 72 if (bytes_written == 0) { |
| 72 ++num_duplicate_frames_received_; | 73 ++num_duplicate_frames_received_; |
| 73 // Silently ignore duplicates. | 74 // Silently ignore duplicates. |
| 74 return; | 75 return; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return buffered_frames_.GetReadableRegion(iov, timestamp); | 136 return buffered_frames_.GetReadableRegion(iov, timestamp); |
| 136 } | 137 } |
| 137 | 138 |
| 138 int QuicStreamSequencer::Readv(const struct iovec* iov, size_t iov_len) { | 139 int QuicStreamSequencer::Readv(const struct iovec* iov, size_t iov_len) { |
| 139 DCHECK(!blocked_); | 140 DCHECK(!blocked_); |
| 140 string error_details; | 141 string error_details; |
| 141 size_t bytes_read; | 142 size_t bytes_read; |
| 142 QuicErrorCode read_error = | 143 QuicErrorCode read_error = |
| 143 buffered_frames_.Readv(iov, iov_len, &bytes_read, &error_details); | 144 buffered_frames_.Readv(iov, iov_len, &bytes_read, &error_details); |
| 144 if (read_error != QUIC_NO_ERROR) { | 145 if (read_error != QUIC_NO_ERROR) { |
| 145 string details = StringPrintf("Stream %" PRIu32 ": %s", stream_->id(), | 146 string details = QuicStrCat("Stream ", stream_->id(), ": ", error_details); |
| 146 error_details.c_str()); | |
| 147 stream_->CloseConnectionWithDetails(read_error, details); | 147 stream_->CloseConnectionWithDetails(read_error, details); |
| 148 return static_cast<int>(bytes_read); | 148 return static_cast<int>(bytes_read); |
| 149 } | 149 } |
| 150 | 150 |
| 151 stream_->AddBytesConsumed(bytes_read); | 151 stream_->AddBytesConsumed(bytes_read); |
| 152 return static_cast<int>(bytes_read); | 152 return static_cast<int>(bytes_read); |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool QuicStreamSequencer::HasBytesToRead() const { | 155 bool QuicStreamSequencer::HasBytesToRead() const { |
| 156 return buffered_frames_.HasBytesToRead(); | 156 return buffered_frames_.HasBytesToRead(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 size_t QuicStreamSequencer::NumBytesBuffered() const { | 215 size_t QuicStreamSequencer::NumBytesBuffered() const { |
| 216 return buffered_frames_.BytesBuffered(); | 216 return buffered_frames_.BytesBuffered(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 QuicStreamOffset QuicStreamSequencer::NumBytesConsumed() const { | 219 QuicStreamOffset QuicStreamSequencer::NumBytesConsumed() const { |
| 220 return buffered_frames_.BytesConsumed(); | 220 return buffered_frames_.BytesConsumed(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 const string QuicStreamSequencer::DebugString() const { | 223 const string QuicStreamSequencer::DebugString() const { |
| 224 // clang-format off | 224 // clang-format off |
| 225 return "QuicStreamSequencer:" | 225 return QuicStrCat("QuicStreamSequencer:", |
| 226 "\n bytes buffered: " + IntToString(NumBytesBuffered()) + | 226 "\n bytes buffered: ", NumBytesBuffered(), |
| 227 "\n bytes consumed: " + IntToString( NumBytesConsumed()) + | 227 "\n bytes consumed: ", NumBytesConsumed(), |
| 228 "\n has bytes to read: " + (HasBytesToRead() ? "true" : "false") + | 228 "\n has bytes to read: ", HasBytesToRead() ? "true" : "false", |
| 229 "\n frames received: " + IntToString(num_frames_received()) + | 229 "\n frames received: ", num_frames_received(), |
| 230 "\n close offset bytes: " + IntToString( close_offset_) + | 230 "\n close offset bytes: ", close_offset_, |
| 231 "\n is closed: " + (IsClosed() ? "true" : "false"); | 231 "\n is closed: ", IsClosed() ? "true" : "false"); |
| 232 // clang-format on | 232 // clang-format on |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace net | 235 } // namespace net |
| OLD | NEW |