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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // We don't want to be reading: blackhole the data. | 144 // We don't want to be reading: blackhole the data. |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 if (frame.stream_id != id_) { | 148 if (frame.stream_id != id_) { |
149 LOG(ERROR) << "Error!"; | 149 LOG(ERROR) << "Error!"; |
150 return false; | 150 return false; |
151 } | 151 } |
152 | 152 |
153 // This count include duplicate data received. | 153 // This count include duplicate data received. |
154 stream_bytes_read_ += frame.data.TotalBufferSize(); | 154 size_t frame_payload_size = frame.data.TotalBufferSize(); |
| 155 stream_bytes_read_ += frame_payload_size; |
| 156 |
| 157 // Flow control is interested in tracking highest received offset. |
| 158 MaybeIncreaseHighestReceivedOffset(frame.offset + frame_payload_size); |
155 | 159 |
156 bool accepted = sequencer_.OnStreamFrame(frame); | 160 bool accepted = sequencer_.OnStreamFrame(frame); |
157 | 161 |
158 if (flow_controller_.FlowControlViolation() || | 162 if (flow_controller_.FlowControlViolation() || |
159 connection_flow_controller_->FlowControlViolation()) { | 163 connection_flow_controller_->FlowControlViolation()) { |
160 session_->connection()->SendConnectionClose(QUIC_FLOW_CONTROL_ERROR); | 164 session_->connection()->SendConnectionClose(QUIC_FLOW_CONTROL_ERROR); |
161 return false; | 165 return false; |
162 } | 166 } |
163 MaybeSendWindowUpdate(); | |
164 | 167 |
165 return accepted; | 168 return accepted; |
166 } | 169 } |
167 | 170 |
168 void ReliableQuicStream::MaybeSendWindowUpdate() { | |
169 flow_controller_.MaybeSendWindowUpdate(session()->connection()); | |
170 connection_flow_controller_->MaybeSendWindowUpdate(session()->connection()); | |
171 } | |
172 | |
173 int ReliableQuicStream::num_frames_received() const { | 171 int ReliableQuicStream::num_frames_received() const { |
174 return sequencer_.num_frames_received(); | 172 return sequencer_.num_frames_received(); |
175 } | 173 } |
176 | 174 |
177 int ReliableQuicStream::num_duplicate_frames_received() const { | 175 int ReliableQuicStream::num_duplicate_frames_received() const { |
178 return sequencer_.num_duplicate_frames_received(); | 176 return sequencer_.num_duplicate_frames_received(); |
179 } | 177 } |
180 | 178 |
181 void ReliableQuicStream::OnStreamReset(const QuicRstStreamFrame& frame) { | 179 void ReliableQuicStream::OnStreamReset(const QuicRstStreamFrame& frame) { |
| 180 MaybeIncreaseHighestReceivedOffset(frame.byte_offset); |
| 181 |
182 stream_error_ = frame.error_code; | 182 stream_error_ = frame.error_code; |
183 CloseWriteSide(); | 183 CloseWriteSide(); |
184 CloseReadSide(); | 184 CloseReadSide(); |
185 } | 185 } |
186 | 186 |
187 void ReliableQuicStream::OnConnectionClosed(QuicErrorCode error, | 187 void ReliableQuicStream::OnConnectionClosed(QuicErrorCode error, |
188 bool from_peer) { | 188 bool from_peer) { |
189 if (read_side_closed_ && write_side_closed_) { | 189 if (read_side_closed_ && write_side_closed_) { |
190 return; | 190 return; |
191 } | 191 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 if (flow_controller_.UpdateSendWindowOffset(frame.byte_offset)) { | 429 if (flow_controller_.UpdateSendWindowOffset(frame.byte_offset)) { |
430 // We can write again! | 430 // We can write again! |
431 // TODO(rjshade): This does not respect priorities (e.g. multiple | 431 // TODO(rjshade): This does not respect priorities (e.g. multiple |
432 // outstanding POSTs are unblocked on arrival of | 432 // outstanding POSTs are unblocked on arrival of |
433 // SHLO with initial window). | 433 // SHLO with initial window). |
434 // As long as the connection is not flow control blocked, we can write! | 434 // As long as the connection is not flow control blocked, we can write! |
435 OnCanWrite(); | 435 OnCanWrite(); |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 void ReliableQuicStream::AddBytesBuffered(uint64 bytes) { | 439 void ReliableQuicStream::MaybeIncreaseHighestReceivedOffset(uint64 new_offset) { |
440 if (flow_controller_.IsEnabled()) { | 440 if (flow_controller_.IsEnabled()) { |
441 flow_controller_.AddBytesBuffered(bytes); | 441 uint64 increment = |
442 connection_flow_controller_->AddBytesBuffered(bytes); | 442 new_offset - flow_controller_.highest_received_byte_offset(); |
| 443 if (flow_controller_.UpdateHighestReceivedOffset(new_offset)) { |
| 444 // If |new_offset| increased the stream flow controller's highest received |
| 445 // offset, then we need to increase the connection flow controller's value |
| 446 // by the incremental difference. |
| 447 connection_flow_controller_->UpdateHighestReceivedOffset( |
| 448 connection_flow_controller_->highest_received_byte_offset() + |
| 449 increment); |
| 450 } |
443 } | 451 } |
444 } | 452 } |
445 | 453 |
446 void ReliableQuicStream::RemoveBytesBuffered(uint64 bytes) { | |
447 if (flow_controller_.IsEnabled()) { | |
448 flow_controller_.RemoveBytesBuffered(bytes); | |
449 connection_flow_controller_->RemoveBytesBuffered(bytes); | |
450 } | |
451 } | |
452 | |
453 void ReliableQuicStream::AddBytesSent(uint64 bytes) { | 454 void ReliableQuicStream::AddBytesSent(uint64 bytes) { |
454 if (flow_controller_.IsEnabled()) { | 455 if (flow_controller_.IsEnabled()) { |
455 flow_controller_.AddBytesSent(bytes); | 456 flow_controller_.AddBytesSent(bytes); |
456 connection_flow_controller_->AddBytesSent(bytes); | 457 connection_flow_controller_->AddBytesSent(bytes); |
457 } | 458 } |
458 } | 459 } |
459 | 460 |
460 void ReliableQuicStream::AddBytesConsumed(uint64 bytes) { | 461 void ReliableQuicStream::AddBytesConsumed(uint64 bytes) { |
461 if (flow_controller_.IsEnabled()) { | 462 if (flow_controller_.IsEnabled()) { |
462 flow_controller_.AddBytesConsumed(bytes); | 463 flow_controller_.AddBytesConsumed(bytes); |
| 464 flow_controller_.MaybeSendWindowUpdate(session()->connection()); |
| 465 |
463 connection_flow_controller_->AddBytesConsumed(bytes); | 466 connection_flow_controller_->AddBytesConsumed(bytes); |
| 467 connection_flow_controller_->MaybeSendWindowUpdate(session()->connection()); |
464 } | 468 } |
465 } | 469 } |
466 | 470 |
467 bool ReliableQuicStream::IsFlowControlBlocked() { | 471 bool ReliableQuicStream::IsFlowControlBlocked() { |
468 return flow_controller_.IsBlocked() || | 472 return flow_controller_.IsBlocked() || |
469 connection_flow_controller_->IsBlocked(); | 473 connection_flow_controller_->IsBlocked(); |
470 } | 474 } |
471 | 475 |
472 } // namespace net | 476 } // namespace net |
OLD | NEW |