Skip to content

Commit d1f64e6

Browse files
vasilvvcopybara-github
authored andcommitted
Clean up bandwidth_sampler.h
Use newer inline constructor syntax for member variables, also remove a hand-rolled copy constructor in favor of the default one. Also clean up headers. PiperOrigin-RevId: 867361385
1 parent 08061dc commit d1f64e6

File tree

2 files changed

+38
-79
lines changed

2 files changed

+38
-79
lines changed

quiche/quic/core/congestion_control/bandwidth_sampler.cc

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
#include <cstddef>
99
#include <ostream>
1010

11+
#include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
12+
#include "quiche/quic/core/quic_bandwidth.h"
13+
#include "quiche/quic/core/quic_packet_number.h"
14+
#include "quiche/quic/core/quic_time.h"
1115
#include "quiche/quic/core/quic_types.h"
16+
#include "quiche/quic/core/quic_unacked_packet_map.h"
1217
#include "quiche/quic/platform/api/quic_bug_tracker.h"
1318
#include "quiche/quic/platform/api/quic_flag_utils.h"
1419
#include "quiche/quic/platform/api/quic_flags.h"
1520
#include "quiche/quic/platform/api/quic_logging.h"
21+
#include "quiche/common/platform/api/quiche_logging.h"
1622

1723
namespace quic {
1824

@@ -135,52 +141,17 @@ QuicByteCount MaxAckHeightTracker::Update(
135141
BandwidthSampler::BandwidthSampler(
136142
const QuicUnackedPacketMap* unacked_packet_map,
137143
QuicRoundTripCount max_height_tracker_window_length)
138-
: total_bytes_sent_(0),
139-
total_bytes_acked_(0),
140-
total_bytes_lost_(0),
141-
total_bytes_neutered_(0),
142-
total_bytes_sent_at_last_acked_packet_(0),
143-
last_acked_packet_sent_time_(QuicTime::Zero()),
144-
last_acked_packet_ack_time_(QuicTime::Zero()),
145-
is_app_limited_(true),
146-
connection_state_map_(),
147-
max_tracked_packets_(GetQuicFlag(quic_max_tracked_packet_count)),
144+
: max_tracked_packets_(GetQuicFlag(quic_max_tracked_packet_count)),
148145
unacked_packet_map_(unacked_packet_map),
149-
max_ack_height_tracker_(max_height_tracker_window_length),
150-
total_bytes_acked_after_last_ack_event_(0),
151-
overestimate_avoidance_(false),
152-
limit_max_ack_height_tracker_by_send_rate_(false) {
146+
max_ack_height_tracker_(max_height_tracker_window_length) {
153147
const size_t preallocate_count =
154148
GetQuicFlag(quic_preallocate_unacked_packets);
155149
if (preallocate_count > 0) {
156150
connection_state_map_.Reserve(preallocate_count);
157151
}
158152
}
159153

160-
BandwidthSampler::BandwidthSampler(const BandwidthSampler& other)
161-
: total_bytes_sent_(other.total_bytes_sent_),
162-
total_bytes_acked_(other.total_bytes_acked_),
163-
total_bytes_lost_(other.total_bytes_lost_),
164-
total_bytes_neutered_(other.total_bytes_neutered_),
165-
total_bytes_sent_at_last_acked_packet_(
166-
other.total_bytes_sent_at_last_acked_packet_),
167-
last_acked_packet_sent_time_(other.last_acked_packet_sent_time_),
168-
last_acked_packet_ack_time_(other.last_acked_packet_ack_time_),
169-
last_sent_packet_(other.last_sent_packet_),
170-
last_acked_packet_(other.last_acked_packet_),
171-
is_app_limited_(other.is_app_limited_),
172-
end_of_app_limited_phase_(other.end_of_app_limited_phase_),
173-
connection_state_map_(other.connection_state_map_),
174-
recent_ack_points_(other.recent_ack_points_),
175-
a0_candidates_(other.a0_candidates_),
176-
max_tracked_packets_(other.max_tracked_packets_),
177-
unacked_packet_map_(other.unacked_packet_map_),
178-
max_ack_height_tracker_(other.max_ack_height_tracker_),
179-
total_bytes_acked_after_last_ack_event_(
180-
other.total_bytes_acked_after_last_ack_event_),
181-
overestimate_avoidance_(other.overestimate_avoidance_),
182-
limit_max_ack_height_tracker_by_send_rate_(
183-
other.limit_max_ack_height_tracker_by_send_rate_) {}
154+
BandwidthSampler::BandwidthSampler(const BandwidthSampler& other) = default;
184155

185156
void BandwidthSampler::EnableOverestimateAvoidance() {
186157
if (overestimate_avoidance_) {
@@ -193,8 +164,6 @@ void BandwidthSampler::EnableOverestimateAvoidance() {
193164
max_ack_height_tracker_.SetAckAggregationBandwidthThreshold(2.0);
194165
}
195166

196-
BandwidthSampler::~BandwidthSampler() {}
197-
198167
void BandwidthSampler::OnPacketSent(
199168
QuicTime sent_time, QuicPacketNumber packet_number, QuicByteCount bytes,
200169
QuicByteCount bytes_in_flight,

quiche/quic/core/congestion_control/bandwidth_sampler.h

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
#ifndef QUICHE_QUIC_CORE_CONGESTION_CONTROL_BANDWIDTH_SAMPLER_H_
66
#define QUICHE_QUIC_CORE_CONGESTION_CONTROL_BANDWIDTH_SAMPLER_H_
77

8+
#include <cstdint>
9+
#include <ostream>
10+
811
#include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
912
#include "quiche/quic/core/congestion_control/windowed_filter.h"
1013
#include "quiche/quic/core/packet_number_indexed_queue.h"
1114
#include "quiche/quic/core/quic_bandwidth.h"
1215
#include "quiche/quic/core/quic_packet_number.h"
13-
#include "quiche/quic/core/quic_packets.h"
1416
#include "quiche/quic/core/quic_time.h"
1517
#include "quiche/quic/core/quic_types.h"
1618
#include "quiche/quic/core/quic_unacked_packet_map.h"
17-
#include "quiche/quic/platform/api/quic_export.h"
1819
#include "quiche/quic/platform/api/quic_flags.h"
20+
#include "quiche/common/platform/api/quiche_export.h"
21+
#include "quiche/common/platform/api/quiche_logging.h"
1922
#include "quiche/common/quiche_circular_deque.h"
2023

2124
namespace quic {
@@ -27,14 +30,7 @@ class BandwidthSamplerPeer;
2730
// A subset of BandwidthSampler::ConnectionStateOnSentPacket which is returned
2831
// to the caller when the packet is acked or lost.
2932
struct QUICHE_EXPORT SendTimeState {
30-
SendTimeState()
31-
: is_valid(false),
32-
is_app_limited(false),
33-
total_bytes_sent(0),
34-
total_bytes_acked(0),
35-
total_bytes_lost(0),
36-
bytes_in_flight(0) {}
37-
33+
SendTimeState() = default;
3834
SendTimeState(bool is_app_limited, QuicByteCount total_bytes_sent,
3935
QuicByteCount total_bytes_acked, QuicByteCount total_bytes_lost,
4036
QuicByteCount bytes_in_flight)
@@ -52,28 +48,28 @@ struct QUICHE_EXPORT SendTimeState {
5248
const SendTimeState& s);
5349

5450
// Whether other states in this object is valid.
55-
bool is_valid;
51+
bool is_valid = false;
5652

5753
// Whether the sender is app limited at the time the packet was sent.
5854
// App limited bandwidth sample might be artificially low because the sender
5955
// did not have enough data to send in order to saturate the link.
60-
bool is_app_limited;
56+
bool is_app_limited = false;
6157

6258
// Total number of sent bytes at the time the packet was sent.
6359
// Includes the packet itself.
64-
QuicByteCount total_bytes_sent;
60+
QuicByteCount total_bytes_sent = 0;
6561

6662
// Total number of acked bytes at the time the packet was sent.
67-
QuicByteCount total_bytes_acked;
63+
QuicByteCount total_bytes_acked = 0;
6864

6965
// Total number of lost bytes at the time the packet was sent.
70-
QuicByteCount total_bytes_lost;
66+
QuicByteCount total_bytes_lost = 0;
7167

7268
// Total number of inflight bytes at the time the packet was sent.
7369
// Includes the packet itself.
7470
// It should be equal to |total_bytes_sent| minus the sum of
7571
// |total_bytes_acked|, |total_bytes_lost| and total neutered bytes.
76-
QuicByteCount bytes_in_flight;
72+
QuicByteCount bytes_in_flight = 0;
7773
};
7874

7975
struct QUICHE_EXPORT ExtraAckedEvent {
@@ -340,7 +336,6 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
340336
// Copy states from |other|. This is useful when changing send algorithms in
341337
// the middle of a connection.
342338
BandwidthSampler(const BandwidthSampler& other);
343-
~BandwidthSampler() override;
344339

345340
void OnPacketSent(QuicTime sent_time, QuicPacketNumber packet_number,
346341
QuicByteCount bytes, QuicByteCount bytes_in_flight,
@@ -502,12 +497,7 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
502497

503498
// Default constructor. Required to put this structure into
504499
// PacketNumberIndexedQueue.
505-
ConnectionStateOnSentPacket()
506-
: sent_time_(QuicTime::Zero()),
507-
size_(0),
508-
total_bytes_sent_at_last_acked_packet_(0),
509-
last_acked_packet_sent_time_(QuicTime::Zero()),
510-
last_acked_packet_ack_time_(QuicTime::Zero()) {}
500+
ConnectionStateOnSentPacket() = default;
511501

512502
friend QUICHE_EXPORT std::ostream& operator<<(
513503
std::ostream& os, const ConnectionStateOnSentPacket& p) {
@@ -521,11 +511,11 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
521511
}
522512

523513
private:
524-
QuicTime sent_time_;
525-
QuicByteCount size_;
526-
QuicByteCount total_bytes_sent_at_last_acked_packet_;
527-
QuicTime last_acked_packet_sent_time_;
528-
QuicTime last_acked_packet_ack_time_;
514+
QuicTime sent_time_ = QuicTime::Zero();
515+
QuicByteCount size_ = 0;
516+
QuicByteCount total_bytes_sent_at_last_acked_packet_ = 0;
517+
QuicTime last_acked_packet_sent_time_ = QuicTime::Zero();
518+
QuicTime last_acked_packet_ack_time_ = QuicTime::Zero();
529519
SendTimeState send_time_state_;
530520
};
531521

@@ -555,27 +545,27 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
555545
bool ChooseA0Point(QuicByteCount total_bytes_acked, AckPoint* a0);
556546

557547
// The total number of congestion controlled bytes sent during the connection.
558-
QuicByteCount total_bytes_sent_;
548+
QuicByteCount total_bytes_sent_ = 0;
559549

560550
// The total number of congestion controlled bytes which were acknowledged.
561-
QuicByteCount total_bytes_acked_;
551+
QuicByteCount total_bytes_acked_ = 0;
562552

563553
// The total number of congestion controlled bytes which were lost.
564-
QuicByteCount total_bytes_lost_;
554+
QuicByteCount total_bytes_lost_ = 0;
565555

566556
// The total number of congestion controlled bytes which have been neutered.
567-
QuicByteCount total_bytes_neutered_;
557+
QuicByteCount total_bytes_neutered_ = 0;
568558

569559
// The value of |total_bytes_sent_| at the time the last acknowledged packet
570560
// was sent. Valid only when |last_acked_packet_sent_time_| is valid.
571-
QuicByteCount total_bytes_sent_at_last_acked_packet_;
561+
QuicByteCount total_bytes_sent_at_last_acked_packet_ = 0;
572562

573563
// The time at which the last acknowledged packet was sent. Set to
574564
// QuicTime::Zero() if no valid timestamp is available.
575-
QuicTime last_acked_packet_sent_time_;
565+
QuicTime last_acked_packet_sent_time_ = QuicTime::Zero();
576566

577567
// The time at which the most recent packet was acknowledged.
578-
QuicTime last_acked_packet_ack_time_;
568+
QuicTime last_acked_packet_ack_time_ = QuicTime::Zero();
579569

580570
// The most recently sent packet.
581571
QuicPacketNumber last_sent_packet_;
@@ -585,7 +575,7 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
585575

586576
// Indicates whether the bandwidth sampler is currently in an app-limited
587577
// phase.
588-
bool is_app_limited_;
578+
bool is_app_limited_ = true;
589579

590580
// The packet that will be acknowledged after this one will cause the sampler
591581
// to exit the app-limited phase.
@@ -613,13 +603,13 @@ class QUICHE_EXPORT BandwidthSampler : public BandwidthSamplerInterface {
613603
const ConnectionStateOnSentPacket& sent_packet);
614604

615605
MaxAckHeightTracker max_ack_height_tracker_;
616-
QuicByteCount total_bytes_acked_after_last_ack_event_;
606+
QuicByteCount total_bytes_acked_after_last_ack_event_ = 0;
617607

618608
// True if connection option 'BSAO' is set.
619-
bool overestimate_avoidance_;
609+
bool overestimate_avoidance_ = false;
620610

621611
// True if connection option 'BBRB' is set.
622-
bool limit_max_ack_height_tracker_by_send_rate_;
612+
bool limit_max_ack_height_tracker_by_send_rate_ = false;
623613
};
624614

625615
} // namespace quic

0 commit comments

Comments
 (0)