Improve performance in low-level-rustls example (#1254)

This commit is contained in:
kkocdko 2022-08-12 19:57:59 +08:00 committed by GitHub
parent 90a2e04e9d
commit a8e80bcb97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,6 +50,8 @@ async fn main() {
let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap();
let mut listener = AddrIncoming::from_listener(listener).unwrap();
let protocol = Arc::new(Http::new());
let mut app = Router::new()
.route("/", get(handler))
.into_make_service_with_connect_info::<SocketAddr>();
@ -62,11 +64,13 @@ async fn main() {
let acceptor = acceptor.clone();
let app = app.make_service(&stream).await.unwrap();
let protocol = protocol.clone();
let svc = app.make_service(&stream);
tokio::spawn(async move {
if let Ok(stream) = acceptor.accept(stream).await {
let _ = Http::new().serve_connection(stream, app).await;
let _ = protocol.serve_connection(stream, svc.await.unwrap()).await;
}
});
}