| 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 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 if (!blocked_ && byte_offset == num_bytes_consumed_) { | 61 if (!blocked_ && byte_offset == num_bytes_consumed_) { |
| 62 DVLOG(1) << "Processing byte offset " << byte_offset; | 62 DVLOG(1) << "Processing byte offset " << byte_offset; |
| 63 size_t bytes_consumed = 0; | 63 size_t bytes_consumed = 0; |
| 64 for (size_t i = 0; i < data.Size(); ++i) { | 64 for (size_t i = 0; i < data.Size(); ++i) { |
| 65 bytes_consumed += stream_->ProcessRawData( | 65 bytes_consumed += stream_->ProcessRawData( |
| 66 static_cast<char*>(data.iovec()[i].iov_base), | 66 static_cast<char*>(data.iovec()[i].iov_base), |
| 67 data.iovec()[i].iov_len); | 67 data.iovec()[i].iov_len); |
| 68 } | 68 } |
| 69 num_bytes_consumed_ += bytes_consumed; | 69 num_bytes_consumed_ += bytes_consumed; |
| 70 stream_->AddBytesConsumed(bytes_consumed); | 70 stream_->AddBytesConsumed(bytes_consumed); |
| 71 stream_->MaybeSendWindowUpdate(); | |
| 72 | 71 |
| 73 if (MaybeCloseStream()) { | 72 if (MaybeCloseStream()) { |
| 74 return true; | 73 return true; |
| 75 } | 74 } |
| 76 if (bytes_consumed > data_len) { | 75 if (bytes_consumed > data_len) { |
| 77 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); | 76 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); |
| 78 return false; | 77 return false; |
| 79 } else if (bytes_consumed == data_len) { | 78 } else if (bytes_consumed == data_len) { |
| 80 FlushBufferedFrames(); | 79 FlushBufferedFrames(); |
| 81 return true; // it's safe to ack this frame. | 80 return true; // it's safe to ack this frame. |
| 82 } else { | 81 } else { |
| 83 // Set ourselves up to buffer what's left. | 82 // Set ourselves up to buffer what's left. |
| 84 data_len -= bytes_consumed; | 83 data_len -= bytes_consumed; |
| 85 data.Consume(bytes_consumed); | 84 data.Consume(bytes_consumed); |
| 86 byte_offset += bytes_consumed; | 85 byte_offset += bytes_consumed; |
| 87 } | 86 } |
| 88 } | 87 } |
| 89 | 88 |
| 90 // Buffer any remaining data to be consumed by the stream when ready. | 89 // Buffer any remaining data to be consumed by the stream when ready. |
| 91 for (size_t i = 0; i < data.Size(); ++i) { | 90 for (size_t i = 0; i < data.Size(); ++i) { |
| 92 DVLOG(1) << "Buffering stream data at offset " << byte_offset; | 91 DVLOG(1) << "Buffering stream data at offset " << byte_offset; |
| 93 const iovec& iov = data.iovec()[i]; | 92 const iovec& iov = data.iovec()[i]; |
| 94 frames_.insert(make_pair( | 93 frames_.insert(make_pair( |
| 95 byte_offset, string(static_cast<char*>(iov.iov_base), iov.iov_len))); | 94 byte_offset, string(static_cast<char*>(iov.iov_base), iov.iov_len))); |
| 96 byte_offset += iov.iov_len; | 95 byte_offset += iov.iov_len; |
| 97 num_bytes_buffered_ += iov.iov_len; | 96 num_bytes_buffered_ += iov.iov_len; |
| 98 stream_->AddBytesBuffered(iov.iov_len); | |
| 99 } | 97 } |
| 100 return true; | 98 return true; |
| 101 } | 99 } |
| 102 | 100 |
| 103 void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset) { | 101 void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset) { |
| 104 const QuicStreamOffset kMaxOffset = numeric_limits<QuicStreamOffset>::max(); | 102 const QuicStreamOffset kMaxOffset = numeric_limits<QuicStreamOffset>::max(); |
| 105 | 103 |
| 106 // If we have a scheduled termination or close, any new offset should match | 104 // If we have a scheduled termination or close, any new offset should match |
| 107 // it. | 105 // it. |
| 108 if (close_offset_ != kMaxOffset && offset != close_offset_) { | 106 if (close_offset_ != kMaxOffset && offset != close_offset_) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 239 } |
| 242 } | 240 } |
| 243 MaybeCloseStream(); | 241 MaybeCloseStream(); |
| 244 } | 242 } |
| 245 | 243 |
| 246 void QuicStreamSequencer::RecordBytesConsumed(size_t bytes_consumed) { | 244 void QuicStreamSequencer::RecordBytesConsumed(size_t bytes_consumed) { |
| 247 num_bytes_consumed_ += bytes_consumed; | 245 num_bytes_consumed_ += bytes_consumed; |
| 248 num_bytes_buffered_ -= bytes_consumed; | 246 num_bytes_buffered_ -= bytes_consumed; |
| 249 | 247 |
| 250 stream_->AddBytesConsumed(bytes_consumed); | 248 stream_->AddBytesConsumed(bytes_consumed); |
| 251 stream_->RemoveBytesBuffered(bytes_consumed); | |
| 252 stream_->MaybeSendWindowUpdate(); | |
| 253 } | 249 } |
| 254 | 250 |
| 255 } // namespace net | 251 } // namespace net |
| OLD | NEW |