summaryrefslogtreecommitdiffstats
path: root/tokio/src/fs
diff options
context:
space:
mode:
authorZahari Dichev <zaharidichev@gmail.com>2020-10-08 11:56:01 +0300
committerGitHub <noreply@github.com>2020-10-08 10:56:01 +0200
commit43bd11bf2fa4eaee84383ddbe4c750868f1bb684 (patch)
tree29ab12a3ec77ff0dfc71c6f678a87516c5801456 /tokio/src/fs
parentd94ab62c54ac594f912a116965fecbdfb5e1d3e6 (diff)
io: remove Poll from the AsyncSeek::start_seek return value (#2885)
Diffstat (limited to 'tokio/src/fs')
-rw-r--r--tokio/src/fs/file.rs45
1 files changed, 20 insertions, 25 deletions
diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs
index 319c2c7f..9556a22f 100644
--- a/tokio/src/fs/file.rs
+++ b/tokio/src/fs/file.rs
@@ -86,6 +86,8 @@ pub struct File {
/// error is observed while performing a read, it is saved until the next
/// write / flush call.
last_write_err: Option<io::ErrorKind>,
+
+ pos: u64,
}
#[derive(Debug)]
@@ -199,6 +201,7 @@ impl File {
std: Arc::new(std),
state: State::Idle(Some(Buf::with_capacity(0))),
last_write_err: None,
+ pos: 0,
}
}
@@ -332,7 +335,9 @@ impl File {
self.state = Idle(Some(buf));
match op {
- Operation::Seek(res) => res.map(|_| ()),
+ Operation::Seek(res) => res.map(|pos| {
+ self.pos = pos;
+ }),
_ => unreachable!(),
}
}
@@ -524,9 +529,12 @@ impl AsyncRead for File {
self.last_write_err = Some(e.kind());
self.state = Idle(Some(buf));
}
- Operation::Seek(_) => {
+ Operation::Seek(result) => {
assert!(buf.is_empty());
self.state = Idle(Some(buf));
+ if let Ok(pos) = result {
+ self.pos = pos;
+ }
continue;
}
}
@@ -537,13 +545,10 @@ impl AsyncRead for File {
}
impl AsyncSeek for File {
- fn start_seek(
- mut self: Pin<&mut Self>,
- cx: &mut Context<'_>,
- mut pos: SeekFrom,
- ) -> Poll<io::Result<()>> {
+ fn start_seek(mut self: Pin<&mut Self>, mut pos: SeekFrom) -> io::Result<()> {
loop {
match self.state {
+ Busy(_) => panic!("must wait for poll_complete before calling start_seek"),
Idle(ref mut buf_cell) => {
let mut buf = buf_cell.take().unwrap();
@@ -562,22 +567,7 @@ impl AsyncSeek for File {
let res = (&*std).seek(pos);
(Operation::Seek(res), buf)
}));
-
- return Ready(Ok(()));
- }
- Busy(ref mut rx) => {
- let (op, buf) = ready!(Pin::new(rx).poll(cx))?;
- self.state = Idle(Some(buf));
-
- match op {
- Operation::Read(_) => {}
- Operation::Write(Err(e)) => {
- assert!(self.last_write_err.is_none());
- self.last_write_err = Some(e.kind());
- }
- Operation::Write(_) => {}
- Operation::Seek(_) => {}
- }
+ return Ok(());
}
}
}
@@ -586,7 +576,7 @@ impl AsyncSeek for File {
fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
loop {
match self.state {
- Idle(_) => panic!("must call start_seek before calling poll_complete"),
+ Idle(_) => return Poll::Ready(Ok(self.pos)),
Busy(ref mut rx) => {
let (op, buf) = ready!(Pin::new(rx).poll(cx))?;
self.state = Idle(Some(buf));
@@ -598,7 +588,12 @@ impl AsyncSeek for File {
self.last_write_err = Some(e.kind());
}
Operation::Write(_) => {}
- Operation::Seek(res) => return Ready(res),
+ Operation::Seek(res) => {
+ if let Ok(pos) = res {
+ self.pos = pos;
+ }
+ return Ready(res);
+ }
}
}
}