mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
Merge pull request #965 from rkarp/fix-write-fmt-future
Fix WriteFmtFuture not taking into account already written bytes (#964)
This commit is contained in:
commit
35f7681664
1 changed files with 4 additions and 4 deletions
|
@ -11,7 +11,7 @@ pub struct WriteFmtFuture<'a, T: Unpin + ?Sized> {
|
||||||
pub(crate) writer: &'a mut T,
|
pub(crate) writer: &'a mut T,
|
||||||
pub(crate) res: Option<io::Result<Vec<u8>>>,
|
pub(crate) res: Option<io::Result<Vec<u8>>>,
|
||||||
pub(crate) buffer: Option<Vec<u8>>,
|
pub(crate) buffer: Option<Vec<u8>>,
|
||||||
pub(crate) amt: u64,
|
pub(crate) amt: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
|
impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
|
||||||
|
@ -37,15 +37,15 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
|
||||||
|
|
||||||
// Copy the data from the buffer into the writer until it's done.
|
// Copy the data from the buffer into the writer until it's done.
|
||||||
loop {
|
loop {
|
||||||
if *amt == buffer.len() as u64 {
|
if *amt == buffer.len() {
|
||||||
futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?;
|
futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?;
|
||||||
return Poll::Ready(Ok(()));
|
return Poll::Ready(Ok(()));
|
||||||
}
|
}
|
||||||
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, buffer))?;
|
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, &buffer[*amt..]))?;
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
|
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
|
||||||
}
|
}
|
||||||
*amt += i as u64;
|
*amt += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue