Skip to content

Commit

Permalink
Try to fix BufWriter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rafibaum authored and taiki-e committed May 5, 2021
1 parent 33c6dad commit cbd6a5b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tokio/src/io/util/buf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ impl<W: AsyncWrite + AsyncSeek> AsyncSeek for BufWriter<W> {
fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
let pos = match self.seek_state {
SeekState::Init => {
// 1.x AsyncSeek recommends calling poll_complete before start_seek.
// We don't have to guarantee that the value returned by
// poll_complete called without start_seek is correct,
// so we'll return 0.
return Poll::Ready(Ok(0));
return self.project().inner.poll_complete(cx);
}
SeekState::Start(pos) => Some(pos),
SeekState::Pending => None,
Expand All @@ -184,6 +180,8 @@ impl<W: AsyncWrite + AsyncSeek> AsyncSeek for BufWriter<W> {

let mut me = self.project();
if let Some(pos) = pos {
// Ensure previous seeks have finished before starting a new one
ready!(me.inner.as_mut().poll_complete(cx))?;
if let Err(e) = me.inner.as_mut().start_seek(pos) {
*me.seek_state = SeekState::Init;
return Poll::Ready(Err(e));
Expand Down

0 comments on commit cbd6a5b

Please sign in to comment.