diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-12-07 14:08:20 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-12-07 14:47:20 +0100 |
commit | 7731320e2d99a9e1793018e45f0300e55323a238 (patch) | |
tree | 2d3bcc1f46959bd4f109ef75567212064fd579d6 | |
parent | 19a13f9bfbd601374b93a61d508d24fc19a462bf (diff) |
buffered-reader: Once EOF is hit, don't poll reader again.
- In the Generic buffered reader, which wraps io::Readers, do not
poll the wrapped reader again once we hit EOF.
- This fixes the problem where parsing OpenPGP data from stdin was
misbehaving with respect to signaling EOF by pressing CTRL-d.
Depending on the readers on the reader stack the user had to press
CTRL-d multiple times, which was annoying and confusing.
- Fixes #679.
-rw-r--r-- | buffered-reader/NEWS | 5 | ||||
-rw-r--r-- | buffered-reader/src/generic.rs | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/buffered-reader/NEWS b/buffered-reader/NEWS index 1f5a5072..327bf83a 100644 --- a/buffered-reader/NEWS +++ b/buffered-reader/NEWS @@ -2,6 +2,11 @@ #+TITLE: buffered-reader NEWS – history of user-visible changes #+STARTUP: content hidestars +* Changes in 1.1.2 +** Notable changes + - The generic buffered reader now correctly handles end-of-file + situations. + * Changes in 1.1.1 ** Notable changes - The generic buffered reader now recycles buffers reducing diff --git a/buffered-reader/src/generic.rs b/buffered-reader/src/generic.rs index 7dec14e1..117a1301 100644 --- a/buffered-reader/src/generic.rs +++ b/buffered-reader/src/generic.rs @@ -26,6 +26,8 @@ pub struct Generic<T: io::Read + Send + Sync, C: fmt::Debug + Sync + Send> { reader: T, // Stashed error, if any. error: Option<Error>, + /// Whether we hit EOF on the underlying reader. + eof: bool, // The user settable cookie. cookie: C, @@ -82,6 +84,7 @@ impl<T: io::Read + Send + Sync, C: fmt::Debug + Sync + Send> Generic<T, C> { else { DEFAULT_BUF_SIZE }, reader, error: None, + eof: false, cookie, } } @@ -151,11 +154,18 @@ impl<T: io::Read + Send + Sync, C: fmt::Debug + Sync + Send> Generic<T, C> { while amount_buffered + amount_read < amount { t!("Have {} bytes, need {} bytes", amount_buffered + amount_read, amount); + + if self.eof { + t!("Hit EOF on the underlying reader, don't poll again."); + break; + } + match self.reader.read(&mut buffer_new [amount_buffered + amount_read..]) { Ok(read) => { t!("Read {} bytes", read); if read == 0 { + self.eof = true; break; } else { amount_read += read; |