| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_flow_controller.h" | 5 #include "net/quic/core/quic_flow_controller.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_connection.h" | 9 #include "net/quic/core/quic_connection.h" |
| 10 #include "net/quic/core/quic_packets.h" | 10 #include "net/quic/core/quic_packets.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 if (available_window >= threshold) { | 197 if (available_window >= threshold) { |
| 198 QUIC_DVLOG(1) << ENDPOINT << "Not sending WindowUpdate for stream " << id_ | 198 QUIC_DVLOG(1) << ENDPOINT << "Not sending WindowUpdate for stream " << id_ |
| 199 << ", available window: " << available_window | 199 << ", available window: " << available_window |
| 200 << " >= threshold: " << threshold; | 200 << " >= threshold: " << threshold; |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 MaybeIncreaseMaxWindowSize(); | 204 MaybeIncreaseMaxWindowSize(); |
| 205 SendWindowUpdate(available_window); | 205 UpdateReceiveWindowOffsetAndSendWindowUpdate(available_window); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void QuicFlowController::SendWindowUpdate(QuicStreamOffset available_window) { | 208 void QuicFlowController::UpdateReceiveWindowOffsetAndSendWindowUpdate( |
| 209 QuicStreamOffset available_window) { |
| 209 // Update our receive window. | 210 // Update our receive window. |
| 210 receive_window_offset_ += (receive_window_size_ - available_window); | 211 receive_window_offset_ += (receive_window_size_ - available_window); |
| 211 | 212 |
| 212 QUIC_DVLOG(1) << ENDPOINT << "Sending WindowUpdate frame for stream " << id_ | 213 QUIC_DVLOG(1) << ENDPOINT << "Sending WindowUpdate frame for stream " << id_ |
| 213 << ", consumed bytes: " << bytes_consumed_ | 214 << ", consumed bytes: " << bytes_consumed_ |
| 214 << ", available window: " << available_window | 215 << ", available window: " << available_window |
| 215 << ", and threshold: " << WindowUpdateThreshold() | 216 << ", and threshold: " << WindowUpdateThreshold() |
| 216 << ", and receive window size: " << receive_window_size_ | 217 << ", and receive window size: " << receive_window_size_ |
| 217 << ". New receive window offset is: " << receive_window_offset_; | 218 << ". New receive window offset is: " << receive_window_offset_; |
| 218 | 219 |
| 219 // Inform the peer of our new receive window. | 220 SendWindowUpdate(); |
| 220 connection_->SendWindowUpdate(id_, receive_window_offset_); | |
| 221 } | 221 } |
| 222 | 222 |
| 223 void QuicFlowController::MaybeSendBlocked() { | 223 void QuicFlowController::MaybeSendBlocked() { |
| 224 if (SendWindowSize() == 0 && | 224 if (SendWindowSize() == 0 && |
| 225 last_blocked_send_window_offset_ < send_window_offset_) { | 225 last_blocked_send_window_offset_ < send_window_offset_) { |
| 226 QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id_ | 226 QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id_ |
| 227 << " is flow control blocked. " | 227 << " is flow control blocked. " |
| 228 << "Send window: " << SendWindowSize() | 228 << "Send window: " << SendWindowSize() |
| 229 << ", bytes sent: " << bytes_sent_ | 229 << ", bytes sent: " << bytes_sent_ |
| 230 << ", send limit: " << send_window_offset_; | 230 << ", send limit: " << send_window_offset_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 258 return was_previously_blocked; | 258 return was_previously_blocked; |
| 259 } | 259 } |
| 260 | 260 |
| 261 void QuicFlowController::EnsureWindowAtLeast(QuicByteCount window_size) { | 261 void QuicFlowController::EnsureWindowAtLeast(QuicByteCount window_size) { |
| 262 if (receive_window_size_limit_ >= window_size) { | 262 if (receive_window_size_limit_ >= window_size) { |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 | 265 |
| 266 QuicStreamOffset available_window = receive_window_offset_ - bytes_consumed_; | 266 QuicStreamOffset available_window = receive_window_offset_ - bytes_consumed_; |
| 267 IncreaseWindowSize(); | 267 IncreaseWindowSize(); |
| 268 SendWindowUpdate(available_window); | 268 UpdateReceiveWindowOffsetAndSendWindowUpdate(available_window); |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool QuicFlowController::IsBlocked() const { | 271 bool QuicFlowController::IsBlocked() const { |
| 272 return SendWindowSize() == 0; | 272 return SendWindowSize() == 0; |
| 273 } | 273 } |
| 274 | 274 |
| 275 uint64_t QuicFlowController::SendWindowSize() const { | 275 uint64_t QuicFlowController::SendWindowSize() const { |
| 276 if (bytes_sent_ > send_window_offset_) { | 276 if (bytes_sent_ > send_window_offset_) { |
| 277 return 0; | 277 return 0; |
| 278 } | 278 } |
| 279 return send_window_offset_ - bytes_sent_; | 279 return send_window_offset_ - bytes_sent_; |
| 280 } | 280 } |
| 281 | 281 |
| 282 void QuicFlowController::UpdateReceiveWindowSize(QuicStreamOffset size) { | 282 void QuicFlowController::UpdateReceiveWindowSize(QuicStreamOffset size) { |
| 283 DCHECK_LE(size, receive_window_size_limit_); | 283 DCHECK_LE(size, receive_window_size_limit_); |
| 284 QUIC_DVLOG(1) << ENDPOINT << "UpdateReceiveWindowSize for stream " << id_ | 284 QUIC_DVLOG(1) << ENDPOINT << "UpdateReceiveWindowSize for stream " << id_ |
| 285 << ": " << size; | 285 << ": " << size; |
| 286 if (receive_window_size_ != receive_window_offset_) { | 286 if (receive_window_size_ != receive_window_offset_) { |
| 287 QUIC_BUG << "receive_window_size_:" << receive_window_size_ | 287 QUIC_BUG << "receive_window_size_:" << receive_window_size_ |
| 288 << " != receive_window_offset:" << receive_window_offset_; | 288 << " != receive_window_offset:" << receive_window_offset_; |
| 289 return; | 289 return; |
| 290 } | 290 } |
| 291 receive_window_size_ = size; | 291 receive_window_size_ = size; |
| 292 receive_window_offset_ = size; | 292 receive_window_offset_ = size; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void QuicFlowController::SendWindowUpdate() { |
| 296 connection_->SendWindowUpdate(id_, receive_window_offset_); |
| 297 } |
| 298 |
| 295 } // namespace net | 299 } // namespace net |
| OLD | NEW |