use std::future::Future;
use compio::net::TcpListener;
use tako_rs_core::router::Router;
use tako_rs_core::types::BoxError;
use crate::ServerConfig;
mod accept;
mod connection;
#[cfg(feature = "http3")]
pub(crate) mod h3;
#[cfg(unix)]
pub(crate) mod unix;
use accept::accept_loop;
use connection::Protocol;
#[deprecated(
since = "2.1.0",
note = "use Server::builder() or CompioServer::builder() and a try_spawn_* method"
)]
pub async fn serve(listener: TcpListener, router: Router) {
if let Err(e) = run(
listener,
router,
None::<std::future::Pending<()>>,
ServerConfig::default(),
)
.await
{
tracing::error!("Server error: {e}");
}
}
#[deprecated(
since = "2.1.0",
note = "use Server::builder() or CompioServer::builder() and a try_spawn_* method"
)]
pub async fn serve_with_shutdown(
listener: TcpListener,
router: Router,
signal: impl Future<Output = ()>,
) {
if let Err(e) = run(listener, router, Some(signal), ServerConfig::default()).await {
tracing::error!("Server error: {e}");
}
}
#[deprecated(
since = "2.1.0",
note = "use Server::builder() or CompioServer::builder() and a try_spawn_* method"
)]
pub async fn serve_with_config(listener: TcpListener, router: Router, config: ServerConfig) {
if let Err(e) = run(listener, router, None::<std::future::Pending<()>>, config).await {
tracing::error!("Server error: {e}");
}
}
#[deprecated(
since = "2.1.0",
note = "use Server::builder() or CompioServer::builder() and a try_spawn_* method"
)]
pub async fn serve_with_shutdown_and_config(
listener: TcpListener,
router: Router,
signal: impl Future<Output = ()>,
config: ServerConfig,
) {
if let Err(e) = run(listener, router, Some(signal), config).await {
tracing::error!("Server error: {e}");
}
}
pub(crate) async fn run(
listener: TcpListener,
router: Router,
signal: Option<impl Future<Output = ()>>,
config: ServerConfig,
) -> Result<(), BoxError> {
accept_loop(listener, router, signal, config, Protocol::Http1).await
}
#[cfg(feature = "http2")]
pub(crate) async fn run_h2c(
listener: TcpListener,
router: Router,
signal: Option<impl Future<Output = ()>>,
config: ServerConfig,
) -> Result<(), BoxError> {
accept_loop(listener, router, signal, config, Protocol::H2c).await
}
#[cfg(feature = "proxy-protocol")]
pub(crate) async fn run_proxy_protocol(
listener: TcpListener,
router: Router,
signal: Option<impl Future<Output = ()>>,
config: ServerConfig,
) -> Result<(), BoxError> {
accept_loop(listener, router, signal, config, Protocol::ProxyHttp1).await
}
#[cfg(unix)]
pub(crate) async fn run_unix(
listener: unix::UnixSocketListener,
router: Router,
signal: Option<impl Future<Output = ()>>,
config: ServerConfig,
) -> Result<(), BoxError> {
accept_loop(listener, router, signal, config, Protocol::Http1).await
}