Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: net/quic/congestion_control/pacing_sender.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/congestion_control/pacing_sender.h"
6
7 namespace net {
8
9 PacingSender::PacingSender(SendAlgorithmInterface* sender,
10 QuicTime::Delta alarm_granularity,
11 uint32 initial_packet_burst)
12 : sender_(sender),
13 alarm_granularity_(alarm_granularity),
14 initial_packet_burst_(initial_packet_burst),
15 burst_tokens_(initial_packet_burst),
16 last_delayed_packet_sent_time_(QuicTime::Zero()),
17 ideal_next_packet_send_time_(QuicTime::Zero()),
18 was_last_send_delayed_(false) {
19 }
20
21 PacingSender::~PacingSender() {}
22
23 void PacingSender::SetFromConfig(const QuicConfig& config,
24 bool is_server,
25 bool using_pacing) {
26 DCHECK(using_pacing);
27 sender_->SetFromConfig(config, is_server, using_pacing);
28 }
29
30 bool PacingSender::ResumeConnectionState(
31 const CachedNetworkParameters& cached_network_params) {
32 return sender_->ResumeConnectionState(cached_network_params);
33 }
34
35 void PacingSender::SetNumEmulatedConnections(int num_connections) {
36 sender_->SetNumEmulatedConnections(num_connections);
37 }
38
39 void PacingSender::OnCongestionEvent(bool rtt_updated,
40 QuicByteCount bytes_in_flight,
41 const CongestionVector& acked_packets,
42 const CongestionVector& lost_packets) {
43 sender_->OnCongestionEvent(
44 rtt_updated, bytes_in_flight, acked_packets, lost_packets);
45 }
46
47 bool PacingSender::OnPacketSent(
48 QuicTime sent_time,
49 QuicByteCount bytes_in_flight,
50 QuicPacketSequenceNumber sequence_number,
51 QuicByteCount bytes,
52 HasRetransmittableData has_retransmittable_data) {
53 const bool in_flight =
54 sender_->OnPacketSent(sent_time, bytes_in_flight, sequence_number,
55 bytes, has_retransmittable_data);
56 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) {
57 return in_flight;
58 }
59 if (bytes_in_flight == 0) {
60 // Add more burst tokens anytime the connection is leaving quiescence.
61 burst_tokens_ = initial_packet_burst_;
62 }
63 if (burst_tokens_ > 0) {
64 --burst_tokens_;
65 was_last_send_delayed_ = false;
66 last_delayed_packet_sent_time_ = QuicTime::Zero();
67 ideal_next_packet_send_time_ = QuicTime::Zero();
68 return in_flight;
69 }
70 // The next packet should be sent as soon as the current packets has been
71 // transferred.
72 QuicTime::Delta delay = PacingRate().TransferTime(bytes);
73 // If the last send was delayed, and the alarm took a long time to get
74 // invoked, allow the connection to make up for lost time.
75 if (was_last_send_delayed_) {
76 ideal_next_packet_send_time_ = ideal_next_packet_send_time_.Add(delay);
77 // The send was application limited if it takes longer than the
78 // pacing delay between sent packets.
79 const bool application_limited =
80 last_delayed_packet_sent_time_.IsInitialized() &&
81 sent_time > last_delayed_packet_sent_time_.Add(delay);
82 const bool making_up_for_lost_time =
83 ideal_next_packet_send_time_ <= sent_time;
84 // As long as we're making up time and not application limited,
85 // continue to consider the packets delayed, allowing the packets to be
86 // sent immediately.
87 if (making_up_for_lost_time && !application_limited) {
88 last_delayed_packet_sent_time_ = sent_time;
89 } else {
90 was_last_send_delayed_ = false;
91 last_delayed_packet_sent_time_ = QuicTime::Zero();
92 }
93 } else {
94 ideal_next_packet_send_time_ = QuicTime::Max(
95 ideal_next_packet_send_time_.Add(delay), sent_time.Add(delay));
96 }
97 return in_flight;
98 }
99
100 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) {
101 sender_->OnRetransmissionTimeout(packets_retransmitted);
102 }
103
104 void PacingSender::RevertRetransmissionTimeout() {
105 sender_->RevertRetransmissionTimeout();
106 }
107
108 QuicTime::Delta PacingSender::TimeUntilSend(
109 QuicTime now,
110 QuicByteCount bytes_in_flight,
111 HasRetransmittableData has_retransmittable_data) const {
112 QuicTime::Delta time_until_send =
113 sender_->TimeUntilSend(now, bytes_in_flight, has_retransmittable_data);
114 if (burst_tokens_ > 0 || bytes_in_flight == 0) {
115 // Don't pace if we have burst tokens available or leaving quiescence.
116 return time_until_send;
117 }
118
119 if (!time_until_send.IsZero()) {
120 DCHECK(time_until_send.IsInfinite());
121 // The underlying sender prevents sending.
122 return time_until_send;
123 }
124
125 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) {
126 // Don't pace ACK packets, since they do not count against CWND and do not
127 // cause CWND to grow.
128 return QuicTime::Delta::Zero();
129 }
130
131 // If the next send time is within the alarm granularity, send immediately.
132 if (ideal_next_packet_send_time_ > now.Add(alarm_granularity_)) {
133 DVLOG(1) << "Delaying packet: "
134 << ideal_next_packet_send_time_.Subtract(now).ToMicroseconds();
135 was_last_send_delayed_ = true;
136 return ideal_next_packet_send_time_.Subtract(now);
137 }
138
139 DVLOG(1) << "Sending packet now";
140 return QuicTime::Delta::Zero();
141 }
142
143 QuicBandwidth PacingSender::PacingRate() const {
144 return sender_->PacingRate();
145 }
146
147 QuicBandwidth PacingSender::BandwidthEstimate() const {
148 return sender_->BandwidthEstimate();
149 }
150
151 bool PacingSender::HasReliableBandwidthEstimate() const {
152 return sender_->HasReliableBandwidthEstimate();
153 }
154
155 QuicTime::Delta PacingSender::RetransmissionDelay() const {
156 return sender_->RetransmissionDelay();
157 }
158
159 QuicByteCount PacingSender::GetCongestionWindow() const {
160 return sender_->GetCongestionWindow();
161 }
162
163 bool PacingSender::InSlowStart() const {
164 return sender_->InSlowStart();
165 }
166
167 bool PacingSender::InRecovery() const {
168 return sender_->InRecovery();
169 }
170
171 QuicByteCount PacingSender::GetSlowStartThreshold() const {
172 return sender_->GetSlowStartThreshold();
173 }
174
175 CongestionControlType PacingSender::GetCongestionControlType() const {
176 return sender_->GetCongestionControlType();
177 }
178
179 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/pacing_sender.h ('k') | net/quic/congestion_control/pacing_sender_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698