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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ideal_next_packet_send_time_ = QuicTime::Zero(); | 84 ideal_next_packet_send_time_ = QuicTime::Zero(); |
85 return in_flight; | 85 return in_flight; |
86 } | 86 } |
87 // The next packet should be sent as soon as the current packet has been | 87 // The next packet should be sent as soon as the current packet has been |
88 // transferred. PacingRate is based on bytes in flight including this packet. | 88 // transferred. PacingRate is based on bytes in flight including this packet. |
89 QuicTime::Delta delay = | 89 QuicTime::Delta delay = |
90 PacingRate(bytes_in_flight + bytes).TransferTime(bytes); | 90 PacingRate(bytes_in_flight + bytes).TransferTime(bytes); |
91 // If the last send was delayed, and the alarm took a long time to get | 91 // If the last send was delayed, and the alarm took a long time to get |
92 // invoked, allow the connection to make up for lost time. | 92 // invoked, allow the connection to make up for lost time. |
93 if (was_last_send_delayed_) { | 93 if (was_last_send_delayed_) { |
94 ideal_next_packet_send_time_ = ideal_next_packet_send_time_.Add(delay); | 94 ideal_next_packet_send_time_ = ideal_next_packet_send_time_ + delay; |
95 // The send was application limited if it takes longer than the | 95 // The send was application limited if it takes longer than the |
96 // pacing delay between sent packets. | 96 // pacing delay between sent packets. |
97 const bool application_limited = | 97 const bool application_limited = |
98 last_delayed_packet_sent_time_.IsInitialized() && | 98 last_delayed_packet_sent_time_.IsInitialized() && |
99 sent_time > last_delayed_packet_sent_time_.Add(delay); | 99 sent_time > last_delayed_packet_sent_time_ + delay; |
100 const bool making_up_for_lost_time = | 100 const bool making_up_for_lost_time = |
101 ideal_next_packet_send_time_ <= sent_time; | 101 ideal_next_packet_send_time_ <= sent_time; |
102 // As long as we're making up time and not application limited, | 102 // As long as we're making up time and not application limited, |
103 // continue to consider the packets delayed, allowing the packets to be | 103 // continue to consider the packets delayed, allowing the packets to be |
104 // sent immediately. | 104 // sent immediately. |
105 if (making_up_for_lost_time && !application_limited) { | 105 if (making_up_for_lost_time && !application_limited) { |
106 last_delayed_packet_sent_time_ = sent_time; | 106 last_delayed_packet_sent_time_ = sent_time; |
107 } else { | 107 } else { |
108 was_last_send_delayed_ = false; | 108 was_last_send_delayed_ = false; |
109 last_delayed_packet_sent_time_ = QuicTime::Zero(); | 109 last_delayed_packet_sent_time_ = QuicTime::Zero(); |
110 } | 110 } |
111 } else { | 111 } else { |
112 ideal_next_packet_send_time_ = QuicTime::Max( | 112 ideal_next_packet_send_time_ = |
113 ideal_next_packet_send_time_.Add(delay), sent_time.Add(delay)); | 113 QuicTime::Max(ideal_next_packet_send_time_ + delay, sent_time + delay); |
114 } | 114 } |
115 return in_flight; | 115 return in_flight; |
116 } | 116 } |
117 | 117 |
118 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) { | 118 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) { |
119 sender_->OnRetransmissionTimeout(packets_retransmitted); | 119 sender_->OnRetransmissionTimeout(packets_retransmitted); |
120 } | 120 } |
121 | 121 |
122 void PacingSender::OnConnectionMigration() { | 122 void PacingSender::OnConnectionMigration() { |
123 sender_->OnConnectionMigration(); | 123 sender_->OnConnectionMigration(); |
124 } | 124 } |
125 | 125 |
126 QuicTime::Delta PacingSender::TimeUntilSend( | 126 QuicTime::Delta PacingSender::TimeUntilSend( |
127 QuicTime now, | 127 QuicTime now, |
128 QuicByteCount bytes_in_flight) const { | 128 QuicByteCount bytes_in_flight) const { |
129 QuicTime::Delta time_until_send = | 129 QuicTime::Delta time_until_send = |
130 sender_->TimeUntilSend(now, bytes_in_flight); | 130 sender_->TimeUntilSend(now, bytes_in_flight); |
131 if (burst_tokens_ > 0 || bytes_in_flight == 0) { | 131 if (burst_tokens_ > 0 || bytes_in_flight == 0) { |
132 // Don't pace if we have burst tokens available or leaving quiescence. | 132 // Don't pace if we have burst tokens available or leaving quiescence. |
133 return time_until_send; | 133 return time_until_send; |
134 } | 134 } |
135 | 135 |
136 if (!time_until_send.IsZero()) { | 136 if (!time_until_send.IsZero()) { |
137 DCHECK(time_until_send.IsInfinite()); | 137 DCHECK(time_until_send.IsInfinite()); |
138 // The underlying sender prevents sending. | 138 // The underlying sender prevents sending. |
139 return time_until_send; | 139 return time_until_send; |
140 } | 140 } |
141 | 141 |
142 // If the next send time is within the alarm granularity, send immediately. | 142 // If the next send time is within the alarm granularity, send immediately. |
143 if (ideal_next_packet_send_time_ > now.Add(alarm_granularity_)) { | 143 if (ideal_next_packet_send_time_ > now + alarm_granularity_) { |
144 DVLOG(1) << "Delaying packet: " | 144 DVLOG(1) << "Delaying packet: " |
145 << ideal_next_packet_send_time_.Subtract(now).ToMicroseconds(); | 145 << (ideal_next_packet_send_time_ - now).ToMicroseconds(); |
146 was_last_send_delayed_ = true; | 146 was_last_send_delayed_ = true; |
147 return ideal_next_packet_send_time_.Subtract(now); | 147 return ideal_next_packet_send_time_ - now; |
148 } | 148 } |
149 | 149 |
150 DVLOG(1) << "Sending packet now"; | 150 DVLOG(1) << "Sending packet now"; |
151 return QuicTime::Delta::Zero(); | 151 return QuicTime::Delta::Zero(); |
152 } | 152 } |
153 | 153 |
154 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { | 154 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { |
155 if (!max_pacing_rate_.IsZero()) { | 155 if (!max_pacing_rate_.IsZero()) { |
156 return QuicBandwidth::FromBitsPerSecond( | 156 return QuicBandwidth::FromBitsPerSecond( |
157 min(max_pacing_rate_.ToBitsPerSecond(), | 157 min(max_pacing_rate_.ToBitsPerSecond(), |
(...skipping 24 matching lines...) Expand all Loading... |
182 | 182 |
183 QuicByteCount PacingSender::GetSlowStartThreshold() const { | 183 QuicByteCount PacingSender::GetSlowStartThreshold() const { |
184 return sender_->GetSlowStartThreshold(); | 184 return sender_->GetSlowStartThreshold(); |
185 } | 185 } |
186 | 186 |
187 CongestionControlType PacingSender::GetCongestionControlType() const { | 187 CongestionControlType PacingSender::GetCongestionControlType() const { |
188 return sender_->GetCongestionControlType(); | 188 return sender_->GetCongestionControlType(); |
189 } | 189 } |
190 | 190 |
191 } // namespace net | 191 } // namespace net |
OLD | NEW |