| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/congestion_control/pacing_sender.h" | 5 #include "net/quic/congestion_control/pacing_sender.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_flags.h" | 7 #include "net/quic/quic_flags.h" |
| 8 | 8 |
| 9 using std::min; | 9 using std::min; |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 initial_packet_burst_, | 81 initial_packet_burst_, |
| 82 static_cast<uint32_t>(sender_->GetCongestionWindow() / kDefaultTCPMSS)); | 82 static_cast<uint32_t>(sender_->GetCongestionWindow() / kDefaultTCPMSS)); |
| 83 } | 83 } |
| 84 if (burst_tokens_ > 0) { | 84 if (burst_tokens_ > 0) { |
| 85 --burst_tokens_; | 85 --burst_tokens_; |
| 86 was_last_send_delayed_ = false; | 86 was_last_send_delayed_ = false; |
| 87 last_delayed_packet_sent_time_ = QuicTime::Zero(); | 87 last_delayed_packet_sent_time_ = QuicTime::Zero(); |
| 88 ideal_next_packet_send_time_ = QuicTime::Zero(); | 88 ideal_next_packet_send_time_ = QuicTime::Zero(); |
| 89 return in_flight; | 89 return in_flight; |
| 90 } | 90 } |
| 91 // The next packet should be sent as soon as the current packets has been | 91 // The next packet should be sent as soon as the current packet has been |
| 92 // transferred. | 92 // transferred. PacingRate is based on bytes in flight including this packet. |
| 93 QuicTime::Delta delay = PacingRate().TransferTime(bytes); | 93 QuicTime::Delta delay = |
| 94 PacingRate(bytes_in_flight + bytes).TransferTime(bytes); |
| 94 // If the last send was delayed, and the alarm took a long time to get | 95 // If the last send was delayed, and the alarm took a long time to get |
| 95 // invoked, allow the connection to make up for lost time. | 96 // invoked, allow the connection to make up for lost time. |
| 96 if (was_last_send_delayed_) { | 97 if (was_last_send_delayed_) { |
| 97 ideal_next_packet_send_time_ = ideal_next_packet_send_time_.Add(delay); | 98 ideal_next_packet_send_time_ = ideal_next_packet_send_time_.Add(delay); |
| 98 // The send was application limited if it takes longer than the | 99 // The send was application limited if it takes longer than the |
| 99 // pacing delay between sent packets. | 100 // pacing delay between sent packets. |
| 100 const bool application_limited = | 101 const bool application_limited = |
| 101 last_delayed_packet_sent_time_.IsInitialized() && | 102 last_delayed_packet_sent_time_.IsInitialized() && |
| 102 sent_time > last_delayed_packet_sent_time_.Add(delay); | 103 sent_time > last_delayed_packet_sent_time_.Add(delay); |
| 103 const bool making_up_for_lost_time = | 104 const bool making_up_for_lost_time = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DVLOG(1) << "Delaying packet: " | 148 DVLOG(1) << "Delaying packet: " |
| 148 << ideal_next_packet_send_time_.Subtract(now).ToMicroseconds(); | 149 << ideal_next_packet_send_time_.Subtract(now).ToMicroseconds(); |
| 149 was_last_send_delayed_ = true; | 150 was_last_send_delayed_ = true; |
| 150 return ideal_next_packet_send_time_.Subtract(now); | 151 return ideal_next_packet_send_time_.Subtract(now); |
| 151 } | 152 } |
| 152 | 153 |
| 153 DVLOG(1) << "Sending packet now"; | 154 DVLOG(1) << "Sending packet now"; |
| 154 return QuicTime::Delta::Zero(); | 155 return QuicTime::Delta::Zero(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 QuicBandwidth PacingSender::PacingRate() const { | 158 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { |
| 158 if (!max_pacing_rate_.IsZero()) { | 159 if (!max_pacing_rate_.IsZero()) { |
| 159 return QuicBandwidth::FromBitsPerSecond( | 160 return QuicBandwidth::FromBitsPerSecond( |
| 160 min(max_pacing_rate_.ToBitsPerSecond(), | 161 min(max_pacing_rate_.ToBitsPerSecond(), |
| 161 sender_->PacingRate().ToBitsPerSecond())); | 162 sender_->PacingRate(bytes_in_flight).ToBitsPerSecond())); |
| 162 } | 163 } |
| 163 return sender_->PacingRate(); | 164 return sender_->PacingRate(bytes_in_flight); |
| 164 } | 165 } |
| 165 | 166 |
| 166 QuicBandwidth PacingSender::BandwidthEstimate() const { | 167 QuicBandwidth PacingSender::BandwidthEstimate() const { |
| 167 return sender_->BandwidthEstimate(); | 168 return sender_->BandwidthEstimate(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 QuicTime::Delta PacingSender::RetransmissionDelay() const { | 171 QuicTime::Delta PacingSender::RetransmissionDelay() const { |
| 171 return sender_->RetransmissionDelay(); | 172 return sender_->RetransmissionDelay(); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 185 | 186 |
| 186 QuicByteCount PacingSender::GetSlowStartThreshold() const { | 187 QuicByteCount PacingSender::GetSlowStartThreshold() const { |
| 187 return sender_->GetSlowStartThreshold(); | 188 return sender_->GetSlowStartThreshold(); |
| 188 } | 189 } |
| 189 | 190 |
| 190 CongestionControlType PacingSender::GetCongestionControlType() const { | 191 CongestionControlType PacingSender::GetCongestionControlType() const { |
| 191 return sender_->GetCongestionControlType(); | 192 return sender_->GetCongestionControlType(); |
| 192 } | 193 } |
| 193 | 194 |
| 194 } // namespace net | 195 } // namespace net |
| OLD | NEW |