This source file includes following definitions.
- max_segment_size_
- UpdateBandwidthEstimate
- OnPacketSent
- TimeUntilSend
#include "net/quic/congestion_control/paced_sender.h"
#include <algorithm>
#include "net/quic/quic_protocol.h"
using std::max;
namespace net {
const int64 kMinPacketBurstSize = 2;
const int64 kMaxSchedulingDelayUs = 2000;
PacedSender::PacedSender(QuicBandwidth estimate, QuicByteCount max_segment_size)
: leaky_bucket_(estimate),
pace_(estimate),
max_segment_size_(kDefaultMaxPacketSize) {
}
void PacedSender::UpdateBandwidthEstimate(QuicTime now,
QuicBandwidth estimate) {
leaky_bucket_.SetDrainingRate(now, estimate);
pace_ = estimate;
}
void PacedSender::OnPacketSent(QuicTime now, QuicByteCount bytes) {
leaky_bucket_.Add(now, bytes);
}
QuicTime::Delta PacedSender::TimeUntilSend(QuicTime now,
QuicTime::Delta time_until_send) {
if (time_until_send.ToMicroseconds() >= kMaxSchedulingDelayUs) {
return time_until_send;
}
QuicByteCount pacing_window = pace_.ToBytesPerPeriod(
QuicTime::Delta::FromMicroseconds(kMaxSchedulingDelayUs));
QuicByteCount min_window_size = kMinPacketBurstSize * max_segment_size_;
pacing_window = max(pacing_window, min_window_size);
if (pacing_window > leaky_bucket_.BytesPending(now)) {
return time_until_send;
}
return leaky_bucket_.TimeRemaining(now);
}
}