From 34bc8d411a2b1e377a2a76987f4c07a5e567f32e Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 3 Jun 2022 07:15:41 +0800 Subject: [PATCH] fix: panic when bind already used port --- src/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server.rs b/src/server.rs index 3c7bdcc..de53d37 100644 --- a/src/server.rs +++ b/src/server.rs @@ -63,7 +63,7 @@ pub async fn serve(args: Args) -> BoxResult<()> { .with_single_cert(certs.clone(), key.clone())?; let tls_acceptor = TlsAcceptor::from(Arc::new(config)); let arc_acceptor = Arc::new(tls_acceptor); - let listener = TcpListener::bind(&socket_addr).await.unwrap(); + let listener = TcpListener::bind(&socket_addr).await?; let incoming = tokio_stream::wrappers::TcpListenerStream::new(listener); let incoming = hyper::server::accept::from_stream(incoming.filter_map(|socket| async { match socket { @@ -86,7 +86,7 @@ pub async fn serve(args: Args) -> BoxResult<()> { print_listening(args.address.as_str(), args.port, true); server.await?; } else { - let server = hyper::Server::bind(&socket_addr).serve(make_service_fn(move |_| { + let server = hyper::Server::try_bind(&socket_addr)?.serve(make_service_fn(move |_| { let inner = inner.clone(); async move { Ok::<_, Infallible>(service_fn(move |req| {