| 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.h" | 5 #include "net/quic/core/quic_stream.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/core/quic_bug_tracker.h" | 8 #include "net/quic/core/quic_bug_tracker.h" |
| 9 #include "net/quic/core/quic_flags.h" | 9 #include "net/quic/core/quic_flags.h" |
| 10 #include "net/quic/core/quic_flow_controller.h" | 10 #include "net/quic/core/quic_flow_controller.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 return session->config()->ReceivedInitialStreamFlowControlWindowBytes(); | 36 return session->config()->ReceivedInitialStreamFlowControlWindowBytes(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 return kMinimumFlowControlSendWindow; | 39 return kMinimumFlowControlSendWindow; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 QuicStream::PendingData::PendingData( | 44 QuicStream::PendingData::PendingData( |
| 45 string data_in, | 45 string data_in, |
| 46 scoped_refptr<QuicAckListenerInterface> ack_listener_in) | 46 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener_in) |
| 47 : data(std::move(data_in)), | 47 : data(std::move(data_in)), |
| 48 offset(0), | 48 offset(0), |
| 49 ack_listener(std::move(ack_listener_in)) {} | 49 ack_listener(std::move(ack_listener_in)) {} |
| 50 | 50 |
| 51 QuicStream::PendingData::~PendingData() {} | 51 QuicStream::PendingData::~PendingData() {} |
| 52 | 52 |
| 53 QuicStream::QuicStream(QuicStreamId id, QuicSession* session) | 53 QuicStream::QuicStream(QuicStreamId id, QuicSession* session) |
| 54 : queued_data_bytes_(0), | 54 : queued_data_bytes_(0), |
| 55 sequencer_(this, session->connection()->clock()), | 55 sequencer_(this, session->connection()->clock()), |
| 56 id_(id), | 56 id_(id), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 void QuicStream::CloseConnectionWithDetails(QuicErrorCode error, | 176 void QuicStream::CloseConnectionWithDetails(QuicErrorCode error, |
| 177 const string& details) { | 177 const string& details) { |
| 178 session()->connection()->CloseConnection( | 178 session()->connection()->CloseConnection( |
| 179 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 179 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void QuicStream::WriteOrBufferData( | 182 void QuicStream::WriteOrBufferData( |
| 183 StringPiece data, | 183 StringPiece data, |
| 184 bool fin, | 184 bool fin, |
| 185 scoped_refptr<QuicAckListenerInterface> ack_listener) { | 185 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 186 if (data.empty() && !fin) { | 186 if (data.empty() && !fin) { |
| 187 QUIC_BUG << "data.empty() && !fin"; | 187 QUIC_BUG << "data.empty() && !fin"; |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (fin_buffered_) { | 191 if (fin_buffered_) { |
| 192 QUIC_BUG << "Fin already buffered"; | 192 QUIC_BUG << "Fin already buffered"; |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 if (write_side_closed_) { | 195 if (write_side_closed_) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 212 StringPiece remainder(data.substr(consumed_data.bytes_consumed)); | 212 StringPiece remainder(data.substr(consumed_data.bytes_consumed)); |
| 213 queued_data_bytes_ += remainder.size(); | 213 queued_data_bytes_ += remainder.size(); |
| 214 queued_data_.emplace_back(remainder.as_string(), ack_listener); | 214 queued_data_.emplace_back(remainder.as_string(), ack_listener); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 void QuicStream::OnCanWrite() { | 218 void QuicStream::OnCanWrite() { |
| 219 bool fin = false; | 219 bool fin = false; |
| 220 while (!queued_data_.empty()) { | 220 while (!queued_data_.empty()) { |
| 221 PendingData* pending_data = &queued_data_.front(); | 221 PendingData* pending_data = &queued_data_.front(); |
| 222 scoped_refptr<QuicAckListenerInterface> ack_listener = | 222 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener = |
| 223 pending_data->ack_listener; | 223 pending_data->ack_listener; |
| 224 if (queued_data_.size() == 1 && fin_buffered_) { | 224 if (queued_data_.size() == 1 && fin_buffered_) { |
| 225 fin = true; | 225 fin = true; |
| 226 } | 226 } |
| 227 if (pending_data->offset > 0 && | 227 if (pending_data->offset > 0 && |
| 228 pending_data->offset >= pending_data->data.size()) { | 228 pending_data->offset >= pending_data->data.size()) { |
| 229 // This should be impossible because offset tracks the amount of | 229 // This should be impossible because offset tracks the amount of |
| 230 // pending_data written thus far. | 230 // pending_data written thus far. |
| 231 QUIC_BUG << "Pending offset is beyond available data. offset: " | 231 QUIC_BUG << "Pending offset is beyond available data. offset: " |
| 232 << pending_data->offset << " vs: " << pending_data->data.size(); | 232 << pending_data->offset << " vs: " << pending_data->data.size(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 263 if (connection_flow_controller_->IsBlocked() && | 263 if (connection_flow_controller_->IsBlocked() && |
| 264 !flow_controller_.IsBlocked()) { | 264 !flow_controller_.IsBlocked()) { |
| 265 session_->MarkConnectionLevelWriteBlocked(id()); | 265 session_->MarkConnectionLevelWriteBlocked(id()); |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 QuicConsumedData QuicStream::WritevData( | 269 QuicConsumedData QuicStream::WritevData( |
| 270 const struct iovec* iov, | 270 const struct iovec* iov, |
| 271 int iov_count, | 271 int iov_count, |
| 272 bool fin, | 272 bool fin, |
| 273 scoped_refptr<QuicAckListenerInterface> ack_listener) { | 273 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 274 if (write_side_closed_) { | 274 if (write_side_closed_) { |
| 275 DLOG(ERROR) << ENDPOINT << "Attempt to write when the write side is closed"; | 275 DLOG(ERROR) << ENDPOINT << "Attempt to write when the write side is closed"; |
| 276 return QuicConsumedData(0, false); | 276 return QuicConsumedData(0, false); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // How much data was provided. | 279 // How much data was provided. |
| 280 size_t write_length = 0; | 280 size_t write_length = 0; |
| 281 if (iov != nullptr) { | 281 if (iov != nullptr) { |
| 282 for (int i = 0; i < iov_count; ++i) { | 282 for (int i = 0; i < iov_count; ++i) { |
| 283 write_length += iov[i].iov_len; | 283 write_length += iov[i].iov_len; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 } else { | 344 } else { |
| 345 session_->MarkConnectionLevelWriteBlocked(id()); | 345 session_->MarkConnectionLevelWriteBlocked(id()); |
| 346 } | 346 } |
| 347 return consumed_data; | 347 return consumed_data; |
| 348 } | 348 } |
| 349 | 349 |
| 350 QuicConsumedData QuicStream::WritevDataInner( | 350 QuicConsumedData QuicStream::WritevDataInner( |
| 351 QuicIOVector iov, | 351 QuicIOVector iov, |
| 352 QuicStreamOffset offset, | 352 QuicStreamOffset offset, |
| 353 bool fin, | 353 bool fin, |
| 354 scoped_refptr<QuicAckListenerInterface> ack_notifier_delegate) { | 354 QuicReferenceCountedPointer<QuicAckListenerInterface> |
| 355 ack_notifier_delegate) { |
| 355 return session()->WritevData(this, id(), iov, offset, fin, | 356 return session()->WritevData(this, id(), iov, offset, fin, |
| 356 std::move(ack_notifier_delegate)); | 357 std::move(ack_notifier_delegate)); |
| 357 } | 358 } |
| 358 | 359 |
| 359 void QuicStream::CloseReadSide() { | 360 void QuicStream::CloseReadSide() { |
| 360 if (read_side_closed_) { | 361 if (read_side_closed_) { |
| 361 return; | 362 return; |
| 362 } | 363 } |
| 363 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); | 364 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); |
| 364 | 365 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 } | 474 } |
| 474 } | 475 } |
| 475 | 476 |
| 476 void QuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { | 477 void QuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { |
| 477 if (flow_controller_.UpdateSendWindowOffset(new_window)) { | 478 if (flow_controller_.UpdateSendWindowOffset(new_window)) { |
| 478 OnCanWrite(); | 479 OnCanWrite(); |
| 479 } | 480 } |
| 480 } | 481 } |
| 481 | 482 |
| 482 } // namespace net | 483 } // namespace net |
| OLD | NEW |