From 69d1aa7f99765df7adbe9c399597a35dbf5869ed Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 13 Jul 2024 13:12:15 +0900 Subject: [PATCH 1/2] chore(server): change serve_connection to take hyper service --- tonic/src/transport/server/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index 990ef3074..812626c4d 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -42,7 +42,7 @@ use crate::server::NamedService; use bytes::Bytes; use http::{Request, Response}; use http_body_util::BodyExt; -use hyper::body::Incoming; +use hyper::{body::Incoming, service::Service as HyperService}; use pin_project::pin_project; use std::{ convert::Infallible, @@ -626,11 +626,11 @@ impl Server { // https://github.com/rust-lang/rust/issues/102211 fn serve_connection( io: ServerIo, - hyper_svc: TowerToHyperService, + hyper_svc: S, builder: ConnectionBuilder, mut watcher: Option>, ) where - S: Service, Response = Response> + Clone + Send + 'static, + S: HyperService, Response = Response> + Clone + Send + 'static, S::Future: Send + 'static, S::Error: Into + Send, IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static, From b7cac22f945905b2759b1928d5d46ce63de4c88c Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 13 Jul 2024 13:21:55 +0900 Subject: [PATCH 2/2] chore(server): Change serve_connection to take hyper io --- tonic/src/transport/server/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index 812626c4d..31700ee11 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -599,9 +599,10 @@ impl Server { .map_err(super::Error::from_source)? .map_request(|req: Request| req.map(boxed)); + let hyper_io = TokioIo::new(io); let hyper_svc = TowerToHyperService::new(req_svc); - serve_connection(io, hyper_svc, server.clone(), graceful.then(|| signal_rx.clone())); + serve_connection(hyper_io, hyper_svc, server.clone(), graceful.then(|| signal_rx.clone())); } } } @@ -625,16 +626,15 @@ impl Server { // This is moved to its own function as a way to get around // https://github.com/rust-lang/rust/issues/102211 fn serve_connection( - io: ServerIo, + hyper_io: IO, hyper_svc: S, builder: ConnectionBuilder, mut watcher: Option>, ) where + IO: hyper::rt::Read + hyper::rt::Write + Unpin + Send + 'static, S: HyperService, Response = Response> + Clone + Send + 'static, S::Future: Send + 'static, S::Error: Into + Send, - IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static, - IO::ConnectInfo: Clone + Send + Sync + 'static, { tokio::spawn(async move { { @@ -642,7 +642,7 @@ fn serve_connection( inner: watcher.as_mut().map(|w| w.changed()), }); - let mut conn = pin!(builder.serve_connection(TokioIo::new(io), hyper_svc)); + let mut conn = pin!(builder.serve_connection(hyper_io, hyper_svc)); loop { tokio::select! {