@@ -31,9 +31,6 @@ pub struct ImapStream<R: Read + Write> {
31
31
decode_needs : usize ,
32
32
/// The buffer.
33
33
buffer : Buffer ,
34
- /// Whether there is any more items to return from the stream. This is set to true once
35
- /// all decodable data in the buffer is returned and the underlying stream is closed.
36
- closed : bool ,
37
34
}
38
35
39
36
impl < R : Read + Write + Unpin > ImapStream < R > {
@@ -43,7 +40,6 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
43
40
inner,
44
41
buffer : Buffer :: new ( ) ,
45
42
decode_needs : 0 ,
46
- closed : false ,
47
43
}
48
44
}
49
45
@@ -76,21 +72,6 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
76
72
pub fn as_mut ( & mut self ) -> & mut R {
77
73
& mut self . inner
78
74
}
79
-
80
- /// End-Of-File return value.
81
- ///
82
- /// Return the appropriate EOF value for the stream depending on whether there is still
83
- /// data in the buffer. It is assumed that any remaining data in the buffer can not be
84
- /// decoded.
85
- fn stream_eof_value ( & self ) -> Option < io:: Result < ResponseData > > {
86
- match self . buffer . used ( ) {
87
- 0 => None ,
88
- _ => Some ( Err ( io:: Error :: new (
89
- io:: ErrorKind :: UnexpectedEof ,
90
- "bytes remaining in stream" ,
91
- ) ) ) ,
92
- }
93
- }
94
75
}
95
76
96
77
impl < R : Read + Write + Unpin > ImapStream < R > {
@@ -281,9 +262,6 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
281
262
if let Some ( response) = this. maybe_decode ( ) ? {
282
263
return Poll :: Ready ( Some ( Ok ( response) ) ) ;
283
264
}
284
- if this. closed {
285
- return Poll :: Ready ( this. stream_eof_value ( ) ) ;
286
- }
287
265
loop {
288
266
this. buffer . ensure_capacity ( this. decode_needs ) ?;
289
267
let buf = this. buffer . free_as_mut_slice ( ) ;
@@ -300,8 +278,13 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
300
278
} ;
301
279
302
280
if num_bytes_read == 0 {
303
- this. closed = true ;
304
- return Poll :: Ready ( this. stream_eof_value ( ) ) ;
281
+ if this. buffer . used ( ) > 0 {
282
+ return Poll :: Ready ( Some ( Err ( io:: Error :: new (
283
+ io:: ErrorKind :: UnexpectedEof ,
284
+ "bytes remaining in stream" ,
285
+ ) ) ) ) ;
286
+ }
287
+ return Poll :: Ready ( None ) ;
305
288
}
306
289
this. buffer . extend_used ( num_bytes_read) ;
307
290
if let Some ( response) = this. maybe_decode ( ) ? {
0 commit comments