pub async fn serve_next_conn(
router: &Router,
listener: &TcpListener,
conn_limit: usize,
conn_set: &mut JoinSet<()>,
)
Expand description
Accept and serve the next connection.
The number of simultaneous TCP stream connections will be capped at the given
conn_limit
.
If we’re at the connection limit, this first awaits for a connection task to become available.
let conf = builder_db::pool::Config::default();
let conn_pool = builder_db::ConnectionPool::with_tables(&conf).unwrap();
let state = builder_api::State { conn_pool };
let router = builder_api::router(state);
let listener = tokio::net::TcpListener::bind("127.0.0.1:3553").await.unwrap();
let conn_limit = builder_api::DEFAULT_CONNECTION_LIMIT;
let mut conn_set = tokio::task::JoinSet::new();
// Accept and serve connections.
loop {
builder_api::serve_next_conn(&router, &listener, conn_limit, &mut conn_set).await;
}