Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/tokio/write/generic/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
#[derive(Debug)]
enum State {
Encoding,
Flushing,
Finishing,
Done,
}
Expand Down Expand Up @@ -80,6 +81,12 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
State::Encoding
}

// Once a flush has been started, it must be completed.
State::Flushing => match this.encoder.flush(&mut output)? {
true => State::Encoding,
false => State::Flushing,
},

State::Finishing | State::Done => {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
Expand All @@ -105,7 +112,7 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
let mut output = PartialBuffer::new(output);

let done = match this.state {
State::Encoding => this.encoder.flush(&mut output)?,
State::Encoding | State::Flushing => this.encoder.flush(&mut output)?,

State::Finishing | State::Done => {
return Poll::Ready(Err(io::Error::new(
Expand All @@ -114,11 +121,13 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
)))
}
};
*this.state = State::Flushing;

let produced = output.written().len();
this.writer.as_mut().produce(produced);

if done {
*this.state = State::Encoding;
return Poll::Ready(Ok(()));
}
}
Expand All @@ -140,6 +149,12 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
}
}

// Once a flush has been started, it must be completed.
State::Flushing => match this.encoder.flush(&mut output)? {
true => State::Finishing,
false => State::Flushing,
},

State::Done => State::Done,
};

Expand Down
Loading