Skip to content

Commit

Permalink
io: Forward poll_write_buf on BufReader (#2654)
Browse files Browse the repository at this point in the history
For some yet unknown reason using the default on a wrapped `Bufreader<TcpStream>`
causes the hyper server to sometimes fail to send the entire body in the
response.

This fixes that problem for us and ensures that hyper has a chance to
use vectored IO (making it a good change regardless of the mentioned
bug)
  • Loading branch information
Marwes authored Jul 20, 2020
1 parent 6dcce19 commit dd28831
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tokio/src/io/util/buf_reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::io::util::DEFAULT_BUF_SIZE;
use crate::io::{AsyncBufRead, AsyncRead, AsyncWrite};

use bytes::Buf;
use pin_project_lite::pin_project;
use std::io::{self, Read};
use std::mem::MaybeUninit;
Expand Down Expand Up @@ -162,6 +163,14 @@ impl<R: AsyncRead + AsyncWrite> AsyncWrite for BufReader<R> {
self.get_pin_mut().poll_write(cx, buf)
}

fn poll_write_buf<B: Buf>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<io::Result<usize>> {
self.get_pin_mut().poll_write_buf(cx, buf)
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
self.get_pin_mut().poll_flush(cx)
}
Expand Down

0 comments on commit dd28831

Please sign in to comment.