Extract handle_connection out of do_serve

This commit is contained in:
Jonas Platte
2025-04-26 21:37:14 +02:00
parent 4d4750e68e
commit 1c5b7dfc94
+27 -10
View File
@@ -304,6 +304,33 @@ where
} }
}; };
handle_connection(&mut make_service, &signal_tx, &close_rx, io, remote_addr).await;
}
drop(close_rx);
drop(listener);
trace!(
"waiting for {} task(s) to finish",
close_tx.receiver_count()
);
close_tx.closed().await;
}
async fn handle_connection<L, M, S>(
make_service: &mut M,
signal_tx: &watch::Sender<()>,
close_rx: &watch::Receiver<()>,
io: <L as Listener>::Io,
remote_addr: <L as Listener>::Addr,
) where
L: Listener,
L::Addr: Debug,
M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a, L>>>::Future: Send,
S: Service<Request, Response = Response, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
{
let io = TokioIo::new(io); let io = TokioIo::new(io);
trace!("connection {remote_addr:?} accepted"); trace!("connection {remote_addr:?} accepted");
@@ -353,16 +380,6 @@ where
drop(close_rx); drop(close_rx);
}); });
}
drop(close_rx);
drop(listener);
trace!(
"waiting for {} task(s) to finish",
close_tx.receiver_count()
);
close_tx.closed().await;
} }
/// An incoming stream. /// An incoming stream.