Skip to content

Commit f110d56

Browse files
committed
Do not measure throughput in IDLE
1 parent aaaa6c5 commit f110d56

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/log/logging_stream.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub(crate) struct LoggingStream<S: SessionStream> {
4747
last_read_timestamp: Instant,
4848

4949
total_duration: Duration,
50+
51+
/// Whether to collect throughput statistics or not.
52+
///
53+
/// Disabled when read timeout is disabled,
54+
/// i.e. when we are in IMAP IDLE.
55+
enable_stats: bool,
5056
}
5157

5258
impl<S: SessionStream> LoggingStream<S> {
@@ -61,6 +67,7 @@ impl<S: SessionStream> LoggingStream<S> {
6167
first_read_timestamp: None,
6268
last_read_timestamp: Instant::now(),
6369
total_duration: Duration::ZERO,
70+
enable_stats: true
6471
}
6572
}
6673
}
@@ -77,7 +84,7 @@ impl<S: SessionStream> AsyncRead for LoggingStream<S> {
7784
let res = projected.inner.poll_read(cx, buf);
7885

7986
let n = old_remaining - buf.remaining();
80-
if n > 0 {
87+
if n > 0 && *projected.enable_stats {
8188
let now = Instant::now();
8289
if projected.first_read_timestamp.is_none() {
8390
*projected.first_read_timestamp = Some(now);
@@ -167,6 +174,8 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
167174

168175
impl<S: SessionStream> SessionStream for LoggingStream<S> {
169176
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
177+
self.enable_stats = timeout.is_some();
178+
170179
self.inner.set_read_timeout(timeout)
171180
}
172181
}

0 commit comments

Comments
 (0)