diff options
author | Jeb Rosen <jeb@jebrosen.com> | 2020-01-08 19:15:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-08 19:15:57 -0800 |
commit | f28c9f0d17a4dca2003bbee57a09f62c3795c2d2 (patch) | |
tree | c5314dc3d74ee7f8b5eb62221c3383fc49759c82 /tokio/src/fs | |
parent | 7ee554218208a9f3919d840079bd96c6ba881caf (diff) |
Fix Seek adapter and AsyncSeek error handling for File
* io: Fix the Seek adapter and add a tested example.
If the first 'AsyncRead::start_seek' call returns Ready,
'AsyncRead::poll_complete' will be called.
Previously, a start_seek that immediately returned 'Ready' would cause
the Seek adapter to return 'Pending' without registering a Waker.
* fs: Do not return write errors from methods on AsyncSeek.
Write errors should only be returned on subsequent writes or on flush.
Also copy the last_write_err assert from 'poll_read' to both
'start_seek' and 'poll_complete' for consistency.
Diffstat (limited to 'tokio/src/fs')
-rw-r--r-- | tokio/src/fs/file.rs | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index 301d2380..9110831a 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -558,10 +558,6 @@ impl AsyncSeek for File { cx: &mut Context<'_>, mut pos: SeekFrom, ) -> Poll<io::Result<()>> { - if let Some(e) = self.last_write_err.take() { - return Ready(Err(e.into())); - } - loop { match self.state { Idle(ref mut buf_cell) => { @@ -592,6 +588,7 @@ impl AsyncSeek for File { match op { Operation::Read(_) => {} Operation::Write(Err(e)) => { + assert!(self.last_write_err.is_none()); self.last_write_err = Some(e.kind()); } Operation::Write(_) => {} @@ -603,10 +600,6 @@ impl AsyncSeek for File { } fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> { - if let Some(e) = self.last_write_err.take() { - return Ready(Err(e.into())); - } - loop { match self.state { Idle(_) => panic!("must call start_seek before calling poll_complete"), @@ -617,6 +610,7 @@ impl AsyncSeek for File { match op { Operation::Read(_) => {} Operation::Write(Err(e)) => { + assert!(self.last_write_err.is_none()); self.last_write_err = Some(e.kind()); } Operation::Write(_) => {} |