@@ -47,6 +47,12 @@ pub(crate) struct LoggingStream<S: SessionStream> {
47
47
last_read_timestamp : Instant ,
48
48
49
49
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 ,
50
56
}
51
57
52
58
impl < S : SessionStream > LoggingStream < S > {
@@ -61,6 +67,7 @@ impl<S: SessionStream> LoggingStream<S> {
61
67
first_read_timestamp : None ,
62
68
last_read_timestamp : Instant :: now ( ) ,
63
69
total_duration : Duration :: ZERO ,
70
+ enable_stats : true
64
71
}
65
72
}
66
73
}
@@ -77,7 +84,7 @@ impl<S: SessionStream> AsyncRead for LoggingStream<S> {
77
84
let res = projected. inner . poll_read ( cx, buf) ;
78
85
79
86
let n = old_remaining - buf. remaining ( ) ;
80
- if n > 0 {
87
+ if n > 0 && * projected . enable_stats {
81
88
let now = Instant :: now ( ) ;
82
89
if projected. first_read_timestamp . is_none ( ) {
83
90
* projected. first_read_timestamp = Some ( now) ;
@@ -167,6 +174,8 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
167
174
168
175
impl < S : SessionStream > SessionStream for LoggingStream < S > {
169
176
fn set_read_timeout ( & mut self , timeout : Option < Duration > ) {
177
+ self . enable_stats = timeout. is_some ( ) ;
178
+
170
179
self . inner . set_read_timeout ( timeout)
171
180
}
172
181
}
0 commit comments