Skip to content

Commit

Permalink
Fix byte counting in socket sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Dec 20, 2024
1 parent 4fc8028 commit 05e01e9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions talpid-tunnel-config-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ mod socket_sniffer {
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let initial_data = buf.filled().len();
let bytes = std::task::ready!(Pin::new(&mut self.s).poll_read(cx, buf));
if bytes.is_ok() {
self.rx_bytes += buf.filled().len();
self.rx_bytes += buf.filled().len().saturating_sub(initial_data);
}
Poll::Ready(bytes)
}
Expand All @@ -351,8 +352,8 @@ mod socket_sniffer {
buf: &[u8],
) -> Poll<io::Result<usize>> {
let bytes = std::task::ready!(Pin::new(&mut self.s).poll_write(cx, buf));
if bytes.is_ok() {
self.tx_bytes += buf.len();
if let Ok(bytes) = bytes {
self.tx_bytes += bytes;
}
Poll::Ready(bytes)
}
Expand Down

0 comments on commit 05e01e9

Please sign in to comment.