summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs
index f51cd67..aa13609 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,6 +14,7 @@ use crate::{
};
use anyhow::{anyhow, bail, Context, Result};
use error::ServiceError;
+use futures::future::try_join_all;
use http_body_util::{combinators::BoxBody, BodyExt};
use hyper::{
body::Incoming,
@@ -88,14 +89,24 @@ async fn serve_http(state: Arc<State>) -> Result<()> {
Some(n) => n,
None => return Ok(()),
};
- let listener = TcpListener::bind(http_config.bind).await?;
+
+ let listen_futs: Result<Vec<()>> = try_join_all(http_config.bind
+ .iter()
+ .map(|e| async {
+ let l = TcpListener::bind(e.clone()).await?;
+ loop {
+ let (stream, addr) = l.accept().await.context("accepting connection")?;
+ debug!("connection from {addr}");
+ let config = state.clone();
+ tokio::spawn(async move { serve_stream(config, stream, addr).await });
+ }
+ }))
+ .await;
+
info!("serving http");
- loop {
- let (stream, addr) = listener.accept().await.context("accepting connection")?;
- debug!("connection from {addr}");
- let config = state.clone();
- tokio::spawn(async move { serve_stream(config, stream, addr).await });
- }
+
+ listen_futs?;
+ Ok(())
}
async fn serve_https(state: Arc<State>) -> Result<()> {
@@ -116,22 +127,30 @@ async fn serve_https(state: Arc<State>) -> Result<()> {
];
Arc::new(cfg)
};
- let listener = TcpListener::bind(https_config.bind).await?;
let tls_acceptor = Arc::new(TlsAcceptor::from(tls_config));
+ let listen_futs: Result<Vec<()>> = try_join_all(https_config.bind
+ .iter()
+ .map(|e| async {
+ let l = TcpListener::bind(e.clone()).await?;
+ loop {
+ let (stream, addr) = l.accept().await.context("accepting connection")?;
+ let state = state.clone();
+ let tls_acceptor = tls_acceptor.clone();
+ tokio::task::spawn(async move {
+ debug!("connection from {addr}");
+ match tls_acceptor.accept(stream).await {
+ Ok(stream) => serve_stream(state, stream, addr).await,
+ Err(e) => warn!("error accepting tls: {e}"),
+ };
+ });
+ }
+ }))
+ .await;
+
info!("serving https");
- loop {
- let (stream, addr) = listener.accept().await.context("accepting connection")?;
- let state = state.clone();
- let tls_acceptor = tls_acceptor.clone();
- tokio::task::spawn(async move {
- debug!("connection from {addr}");
- match tls_acceptor.accept(stream).await {
- Ok(stream) => serve_stream(state, stream, addr).await,
- Err(e) => warn!("error accepting tls: {e}"),
- };
- });
- }
+ listen_futs?;
+ Ok(())
}
pub async fn serve_stream<T: AsyncRead + AsyncWrite + Unpin + Send + 'static>(