Simplify DiskWriter poll_flush

This commit is contained in:
Edward Shen 2021-07-14 14:20:31 -04:00
parent 5338ff81a5
commit 9209b822a9
Signed by: edward
GPG key ID: 19182661E818369F

30
src/cache/fs.rs vendored
View file

@ -331,26 +331,20 @@ impl AsyncWrite for EncryptedDiskWriter {
} }
#[inline] #[inline]
fn poll_flush( fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
mut self: Pin<&mut Self>, let pinned = Pin::into_inner(self);
cx: &mut Context<'_>,
) -> Poll<Result<(), std::io::Error>> {
if self.buffer.is_empty() {
self.as_mut().file.as_mut().poll_flush(cx)
} else {
let pinned = Pin::into_inner(self);
while !pinned.buffer.is_empty() {
match pinned.file.as_mut().poll_write(cx, &pinned.buffer) {
Poll::Ready(Ok(n)) => {
pinned.buffer.drain(..n);
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
}
}
Poll::Ready(Ok(())) while !pinned.buffer.is_empty() {
match pinned.file.as_mut().poll_write(cx, &pinned.buffer) {
Poll::Ready(Ok(n)) => {
pinned.buffer.drain(..n);
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
}
} }
pinned.file.as_mut().poll_flush(cx)
} }
#[inline] #[inline]