Skip to content

Commit

Permalink
support vectored IO (#1502)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucio Franco <[email protected]>
  • Loading branch information
xiaoyawei and LucioFranco authored Nov 13, 2023
1 parent e1fa95e commit ff71e89
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod pb {

pub mod mock {
use std::{
io::IoSlice,
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -51,6 +52,18 @@ pub mod mock {
) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}

fn poll_write_vectored(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, std::io::Error>> {
Pin::new(&mut self.0).poll_write_vectored(cx, bufs)
}

fn is_write_vectored(&self) -> bool {
self.0.is_write_vectored()
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions tonic/src/transport/service/io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::transport::server::Connected;
use hyper::client::connect::{Connected as HyperConnected, Connection};
use std::io;
use std::io::IoSlice;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
Expand Down Expand Up @@ -65,6 +66,18 @@ impl AsyncWrite for BoxedIo {
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}

fn poll_write_vectored(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, io::Error>> {
Pin::new(&mut self.0).poll_write_vectored(cx, bufs)
}

fn is_write_vectored(&self) -> bool {
self.0.is_write_vectored()
}
}

pub(crate) enum ServerIo<IO> {
Expand Down Expand Up @@ -163,4 +176,24 @@ where
Self::TlsIo(io) => Pin::new(io).poll_shutdown(cx),
}
}

fn poll_write_vectored(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, io::Error>> {
match &mut *self {
Self::Io(io) => Pin::new(io).poll_write_vectored(cx, bufs),
#[cfg(feature = "tls")]
Self::TlsIo(io) => Pin::new(io).poll_write_vectored(cx, bufs),
}
}

fn is_write_vectored(&self) -> bool {
match self {
Self::Io(io) => io.is_write_vectored(),
#[cfg(feature = "tls")]
Self::TlsIo(io) => io.is_write_vectored(),
}
}
}

0 comments on commit ff71e89

Please sign in to comment.