| 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/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/iovector.h" | 8 #include "net/quic/iovector.h" |
| 9 #include "net/quic/quic_flow_controller.h" | 9 #include "net/quic/quic_flow_controller.h" |
| 10 #include "net/quic/quic_session.h" | 10 #include "net/quic/quic_session.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 stream_bytes_written_(0), | 117 stream_bytes_written_(0), |
| 118 stream_error_(QUIC_STREAM_NO_ERROR), | 118 stream_error_(QUIC_STREAM_NO_ERROR), |
| 119 connection_error_(QUIC_NO_ERROR), | 119 connection_error_(QUIC_NO_ERROR), |
| 120 read_side_closed_(false), | 120 read_side_closed_(false), |
| 121 write_side_closed_(false), | 121 write_side_closed_(false), |
| 122 fin_buffered_(false), | 122 fin_buffered_(false), |
| 123 fin_sent_(false), | 123 fin_sent_(false), |
| 124 fin_received_(false), | 124 fin_received_(false), |
| 125 rst_sent_(false), | 125 rst_sent_(false), |
| 126 rst_received_(false), | 126 rst_received_(false), |
| 127 fec_policy_(PROTECT_OPTIONAL), |
| 127 is_server_(session_->is_server()), | 128 is_server_(session_->is_server()), |
| 128 flow_controller_( | 129 flow_controller_( |
| 129 session_->connection(), | 130 session_->connection(), |
| 130 id_, | 131 id_, |
| 131 is_server_, | 132 is_server_, |
| 132 session_->config()->HasReceivedInitialFlowControlWindowBytes() ? | 133 session_->config()->HasReceivedInitialFlowControlWindowBytes() ? |
| 133 session_->config()->ReceivedInitialFlowControlWindowBytes() : | 134 session_->config()->ReceivedInitialFlowControlWindowBytes() : |
| 134 kDefaultFlowControlSendWindow, | 135 kDefaultFlowControlSendWindow, |
| 135 session_->config()->GetInitialFlowControlWindowToSend(), | 136 session_->config()->GetInitialFlowControlWindowToSend(), |
| 136 session_->config()->GetInitialFlowControlWindowToSend()), | 137 session_->config()->GetInitialFlowControlWindowToSend()), |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 354 |
| 354 // Writing more data would be a violation of flow control. | 355 // Writing more data would be a violation of flow control. |
| 355 write_length = send_window; | 356 write_length = send_window; |
| 356 } | 357 } |
| 357 } | 358 } |
| 358 | 359 |
| 359 // Fill an IOVector with bytes from the iovec. | 360 // Fill an IOVector with bytes from the iovec. |
| 360 IOVector data; | 361 IOVector data; |
| 361 data.AppendIovecAtMostBytes(iov, iov_count, write_length); | 362 data.AppendIovecAtMostBytes(iov, iov_count, write_length); |
| 362 | 363 |
| 363 // TODO(jri): Use the correct FecProtection based on FecPolicy on stream. | |
| 364 QuicConsumedData consumed_data = session()->WritevData( | 364 QuicConsumedData consumed_data = session()->WritevData( |
| 365 id(), data, stream_bytes_written_, fin, MAY_FEC_PROTECT, | 365 id(), data, stream_bytes_written_, fin, GetFecProtection(), |
| 366 ack_notifier_delegate); | 366 ack_notifier_delegate); |
| 367 stream_bytes_written_ += consumed_data.bytes_consumed; | 367 stream_bytes_written_ += consumed_data.bytes_consumed; |
| 368 | 368 |
| 369 AddBytesSent(consumed_data.bytes_consumed); | 369 AddBytesSent(consumed_data.bytes_consumed); |
| 370 | 370 |
| 371 if (consumed_data.bytes_consumed == write_length) { | 371 if (consumed_data.bytes_consumed == write_length) { |
| 372 if (!fin_with_zero_data) { | 372 if (!fin_with_zero_data) { |
| 373 MaybeSendBlocked(); | 373 MaybeSendBlocked(); |
| 374 } | 374 } |
| 375 if (fin && consumed_data.fin_consumed) { | 375 if (fin && consumed_data.fin_consumed) { |
| 376 fin_sent_ = true; | 376 fin_sent_ = true; |
| 377 CloseWriteSide(); | 377 CloseWriteSide(); |
| 378 } else if (fin && !consumed_data.fin_consumed) { | 378 } else if (fin && !consumed_data.fin_consumed) { |
| 379 session_->MarkWriteBlocked(id(), EffectivePriority()); | 379 session_->MarkWriteBlocked(id(), EffectivePriority()); |
| 380 } | 380 } |
| 381 } else { | 381 } else { |
| 382 session_->MarkWriteBlocked(id(), EffectivePriority()); | 382 session_->MarkWriteBlocked(id(), EffectivePriority()); |
| 383 } | 383 } |
| 384 return consumed_data; | 384 return consumed_data; |
| 385 } | 385 } |
| 386 | 386 |
| 387 FecProtection ReliableQuicStream::GetFecProtection() { |
| 388 return fec_policy_ == PROTECT_ALWAYS ? MUST_FEC_PROTECT : MAY_FEC_PROTECT; |
| 389 } |
| 390 |
| 387 void ReliableQuicStream::CloseReadSide() { | 391 void ReliableQuicStream::CloseReadSide() { |
| 388 if (read_side_closed_) { | 392 if (read_side_closed_) { |
| 389 return; | 393 return; |
| 390 } | 394 } |
| 391 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); | 395 DVLOG(1) << ENDPOINT << "Done reading from stream " << id(); |
| 392 | 396 |
| 393 read_side_closed_ = true; | 397 read_side_closed_ = true; |
| 394 if (write_side_closed_) { | 398 if (write_side_closed_) { |
| 395 DVLOG(1) << ENDPOINT << "Closing stream: " << id(); | 399 DVLOG(1) << ENDPOINT << "Closing stream: " << id(); |
| 396 session_->CloseStream(id()); | 400 session_->CloseStream(id()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 connection_flow_controller_->AddBytesConsumed(bytes); | 492 connection_flow_controller_->AddBytesConsumed(bytes); |
| 489 } | 493 } |
| 490 } | 494 } |
| 491 | 495 |
| 492 bool ReliableQuicStream::IsFlowControlBlocked() { | 496 bool ReliableQuicStream::IsFlowControlBlocked() { |
| 493 return flow_controller_.IsBlocked() || | 497 return flow_controller_.IsBlocked() || |
| 494 connection_flow_controller_->IsBlocked(); | 498 connection_flow_controller_->IsBlocked(); |
| 495 } | 499 } |
| 496 | 500 |
| 497 } // namespace net | 501 } // namespace net |
| OLD | NEW |