Skip to content

Commit

Permalink
Factor out udp_tx stats update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jan 23, 2024
1 parent 7a38428 commit 86bac4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,7 @@ impl Connection {
builder.pad_to(MIN_INITIAL_SIZE);

builder.finish(self, buf);
self.stats.udp_tx.datagrams += 1;
self.stats.udp_tx.ios += 1;
self.stats.udp_tx.bytes += buf.len() as u64;
self.stats.udp_tx.on_sent(1, buf.len());
return Some(Transmit {
destination,
size: buf.len(),
Expand Down Expand Up @@ -900,9 +898,7 @@ impl Connection {
trace!("sending {} bytes in {} datagrams", buf.len(), num_datagrams);
self.path.total_sent = self.path.total_sent.saturating_add(buf.len() as u64);

self.stats.udp_tx.datagrams += num_datagrams as u64;
self.stats.udp_tx.bytes += buf.len() as u64;
self.stats.udp_tx.ios += 1;
self.stats.udp_tx.on_sent(num_datagrams as u64, buf.len());

Some(Transmit {
destination: self.path.remote,
Expand Down
8 changes: 8 additions & 0 deletions quinn-proto/src/connection/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ pub struct UdpStats {
pub ios: u64,
}

impl UdpStats {
pub(crate) fn on_sent(&mut self, datagrams: u64, bytes: usize) {
self.datagrams += datagrams;
self.bytes += bytes as u64;
self.ios += 1;
}
}

/// Number of frames transmitted of each frame type
#[derive(Default, Copy, Clone)]
#[non_exhaustive]
Expand Down

0 comments on commit 86bac4b

Please sign in to comment.