| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // buffering if the stream is unable to process it. | 112 // buffering if the stream is unable to process it. |
| 113 if (!blocked_ && byte_offset == num_bytes_consumed_) { | 113 if (!blocked_ && byte_offset == num_bytes_consumed_) { |
| 114 DVLOG(1) << "Processing byte offset " << byte_offset; | 114 DVLOG(1) << "Processing byte offset " << byte_offset; |
| 115 size_t bytes_consumed = 0; | 115 size_t bytes_consumed = 0; |
| 116 for (size_t i = 0; i < data.Size(); ++i) { | 116 for (size_t i = 0; i < data.Size(); ++i) { |
| 117 bytes_consumed += stream_->ProcessRawData( | 117 bytes_consumed += stream_->ProcessRawData( |
| 118 static_cast<char*>(data.iovec()[i].iov_base), | 118 static_cast<char*>(data.iovec()[i].iov_base), |
| 119 data.iovec()[i].iov_len); | 119 data.iovec()[i].iov_len); |
| 120 } | 120 } |
| 121 num_bytes_consumed_ += bytes_consumed; | 121 num_bytes_consumed_ += bytes_consumed; |
| 122 stream_->flow_controller()->AddBytesConsumed(bytes_consumed); |
| 122 stream_->MaybeSendWindowUpdate(); | 123 stream_->MaybeSendWindowUpdate(); |
| 123 | 124 |
| 124 if (MaybeCloseStream()) { | 125 if (MaybeCloseStream()) { |
| 125 return true; | 126 return true; |
| 126 } | 127 } |
| 127 if (bytes_consumed > data_len) { | 128 if (bytes_consumed > data_len) { |
| 128 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); | 129 stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); |
| 129 return false; | 130 return false; |
| 130 } else if (bytes_consumed == data_len) { | 131 } else if (bytes_consumed == data_len) { |
| 131 FlushBufferedFrames(); | 132 FlushBufferedFrames(); |
| 132 return true; // it's safe to ack this frame. | 133 return true; // it's safe to ack this frame. |
| 133 } else { | 134 } else { |
| 134 // Set ourselves up to buffer what's left. | 135 // Set ourselves up to buffer what's left. |
| 135 data_len -= bytes_consumed; | 136 data_len -= bytes_consumed; |
| 136 data.Consume(bytes_consumed); | 137 data.Consume(bytes_consumed); |
| 137 byte_offset += bytes_consumed; | 138 byte_offset += bytes_consumed; |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Buffer any remaining data to be consumed by the stream when ready. | 142 // Buffer any remaining data to be consumed by the stream when ready. |
| 142 for (size_t i = 0; i < data.Size(); ++i) { | 143 for (size_t i = 0; i < data.Size(); ++i) { |
| 143 DVLOG(1) << "Buffering stream data at offset " << byte_offset; | 144 DVLOG(1) << "Buffering stream data at offset " << byte_offset; |
| 144 const iovec& iov = data.iovec()[i]; | 145 const iovec& iov = data.iovec()[i]; |
| 145 frames_.insert(make_pair( | 146 frames_.insert(make_pair( |
| 146 byte_offset, string(static_cast<char*>(iov.iov_base), iov.iov_len))); | 147 byte_offset, string(static_cast<char*>(iov.iov_base), iov.iov_len))); |
| 147 byte_offset += iov.iov_len; | 148 byte_offset += iov.iov_len; |
| 148 num_bytes_buffered_ += iov.iov_len; | 149 num_bytes_buffered_ += iov.iov_len; |
| 150 stream_->flow_controller()->AddBytesBuffered(iov.iov_len); |
| 149 } | 151 } |
| 150 return true; | 152 return true; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset) { | 155 void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset) { |
| 154 const QuicStreamOffset kMaxOffset = numeric_limits<QuicStreamOffset>::max(); | 156 const QuicStreamOffset kMaxOffset = numeric_limits<QuicStreamOffset>::max(); |
| 155 | 157 |
| 156 // If we have a scheduled termination or close, any new offset should match | 158 // If we have a scheduled termination or close, any new offset should match |
| 157 // it. | 159 // it. |
| 158 if (close_offset_ != kMaxOffset && offset != close_offset_) { | 160 if (close_offset_ != kMaxOffset && offset != close_offset_) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return; | 292 return; |
| 291 } | 293 } |
| 292 } | 294 } |
| 293 MaybeCloseStream(); | 295 MaybeCloseStream(); |
| 294 } | 296 } |
| 295 | 297 |
| 296 void QuicStreamSequencer::RecordBytesConsumed(size_t bytes_consumed) { | 298 void QuicStreamSequencer::RecordBytesConsumed(size_t bytes_consumed) { |
| 297 num_bytes_consumed_ += bytes_consumed; | 299 num_bytes_consumed_ += bytes_consumed; |
| 298 num_bytes_buffered_ -= bytes_consumed; | 300 num_bytes_buffered_ -= bytes_consumed; |
| 299 | 301 |
| 302 stream_->flow_controller()->AddBytesConsumed(bytes_consumed); |
| 303 stream_->flow_controller()->RemoveBytesBuffered(bytes_consumed); |
| 300 stream_->MaybeSendWindowUpdate(); | 304 stream_->MaybeSendWindowUpdate(); |
| 301 } | 305 } |
| 302 | 306 |
| 303 } // namespace net | 307 } // namespace net |
| OLD | NEW |