From e5505a400a6b4412cdbcae728f03c2d5719d015e Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 13 Jul 2024 14:51:12 +0900 Subject: [PATCH] chore(server): Change serve_connection to take hyper trait (#1793) * chore(server): change serve_connection to take hyper service * chore(server): Change serve_connection to take hyper io --- tonic/src/transport/server/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index 990ef3074..31700ee11 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, @@ -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_svc: TowerToHyperService, + hyper_io: IO, + hyper_svc: S, builder: ConnectionBuilder, mut watcher: Option>, ) where - S: Service, Response = Response> + Clone + Send + 'static, + 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! {