diff --git a/talpid-tunnel-config-client/src/lib.rs b/talpid-tunnel-config-client/src/lib.rs index 3a1b25bb4656..f13832fa609b 100644 --- a/talpid-tunnel-config-client/src/lib.rs +++ b/talpid-tunnel-config-client/src/lib.rs @@ -336,9 +336,10 @@ mod socket_sniffer { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { + 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) } @@ -351,8 +352,8 @@ mod socket_sniffer { buf: &[u8], ) -> Poll> { 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) }