aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-09-13 12:08:33 +0200
committerAlex Auvolat <alex@adnab.me>2022-09-13 12:08:33 +0200
commit9362d268904de694328f20e9e3a31b569955787c (patch)
tree074bf003cf8f4efad39bfdce52eb3587236d9e66
parentdb96af2609a75284c5608cf592c3d4ce4b28ae0b (diff)
downloadnetapp-9362d268904de694328f20e9e3a31b569955787c.tar.gz
netapp-9362d268904de694328f20e9e3a31b569955787c.zip
fill_buffer do something only if buf is empty
-rw-r--r--src/stream.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/stream.rs b/src/stream.rs
index 82f7be3..88c3fed 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -101,13 +101,15 @@ impl ByteStreamReader {
}
}
- /// Tries to fill the internal read buffer from the underlying stream.
+ /// Tries to fill the internal read buffer from the underlying stream if it is empty.
/// Calling this might be necessary to ensure that `.eos()` returns a correct
/// result, otherwise the reader might not be aware that the underlying
/// stream has nothing left to return.
pub async fn fill_buffer(&mut self) {
- let packet = self.stream.next().await;
- self.add_stream_next(packet);
+ if self.buf.is_empty() {
+ let packet = self.stream.next().await;
+ self.add_stream_next(packet);
+ }
}
/// Clears the internal read buffer and returns its content