flush on close

This commit is contained in:
AF 2024-03-19 12:31:17 +00:00
parent 9f138eba7e
commit 09c9c458a0

View File

@ -32,12 +32,12 @@ struct Forward {
impl Stream for Forward { impl Stream for Forward {
type Item = smol::io::Result<Vec<u8>>; type Item = smol::io::Result<Vec<u8>>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let mut this = self.project(); let mut this = self.as_mut().project();
let mut buf = [0; 65536]; let mut buf = [0; 65536];
let read = ready!(this.stream.as_mut().poll_read(cx, &mut buf))?; let read = ready!(this.stream.as_mut().poll_read(cx, &mut buf))?;
if read == 0 { if read == 0 {
ready!(this.stream.poll_close(cx))?; ready!(self.poll_close(cx))?;
Poll::Ready(None) Poll::Ready(None)
} else { } else {
Poll::Ready(Some(Ok(buf[..read].into()))) Poll::Ready(Some(Ok(buf[..read].into())))
@ -75,7 +75,8 @@ impl Sink<Vec<u8>> for Forward {
self.project().stream.poll_flush(cx) self.project().stream.poll_flush(cx)
} }
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
ready!(self.as_mut().poll_flush(cx))?;
self.project().stream.poll_close(cx) self.project().stream.poll_close(cx)
} }
} }