use std::future::Future;
use std::sync::Arc;
use tako_rs_core::router::Router;
use tokio::net::TcpListener;
use tokio_rustls::rustls::ServerConfig as RustlsServerConfig;
use super::run;
use super::run_with_config;
use crate::ServerConfig;
pub async fn serve_tls(
listener: TcpListener,
router: Router,
certs: Option<&str>,
key: Option<&str>,
) {
if let Err(e) = run(
listener,
router,
certs,
key,
None::<std::future::Pending<()>>,
ServerConfig::default(),
)
.await
{
tracing::error!("TLS server error: {e}");
}
}
pub async fn serve_tls_with_shutdown(
listener: TcpListener,
router: Router,
certs: Option<&str>,
key: Option<&str>,
signal: impl Future<Output = ()> + Send + 'static,
) {
if let Err(e) = run(
listener,
router,
certs,
key,
Some(signal),
ServerConfig::default(),
)
.await
{
tracing::error!("TLS server error: {e}");
}
}
pub async fn serve_tls_with_config(
listener: TcpListener,
router: Router,
certs: Option<&str>,
key: Option<&str>,
config: ServerConfig,
) {
if let Err(e) = run(
listener,
router,
certs,
key,
None::<std::future::Pending<()>>,
config,
)
.await
{
tracing::error!("TLS server error: {e}");
}
}
pub async fn serve_tls_with_shutdown_and_config(
listener: TcpListener,
router: Router,
certs: Option<&str>,
key: Option<&str>,
signal: impl Future<Output = ()> + Send + 'static,
config: ServerConfig,
) {
if let Err(e) = run(listener, router, certs, key, Some(signal), config).await {
tracing::error!("TLS server error: {e}");
}
}
pub async fn serve_tls_with_rustls_config(
listener: TcpListener,
router: Router,
rustls_config: Arc<RustlsServerConfig>,
config: ServerConfig,
) {
if let Err(e) = run_with_config(
listener,
router,
rustls_config,
None::<std::future::Pending<()>>,
config,
)
.await
{
tracing::error!("TLS server error: {e}");
}
}
pub async fn serve_tls_with_rustls_config_and_shutdown(
listener: TcpListener,
router: Router,
rustls_config: Arc<RustlsServerConfig>,
signal: impl Future<Output = ()> + Send + 'static,
config: ServerConfig,
) {
if let Err(e) = run_with_config(listener, router, rustls_config, Some(signal), config).await {
tracing::error!("TLS server error: {e}");
}
}