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 = node::db::pool::Config::default();
let db = node::db::ConnectionPool::with_tables(&conf).unwrap();
let state = node_api::State {
conn_pool: db,
new_block: None,
};
let router = node_api::router(state);
let listener = tokio::net::TcpListener::bind("127.0.0.1:3553").await.unwrap();
let conn_limit = node_api::DEFAULT_CONNECTION_LIMIT;
let mut conn_set = tokio::task::JoinSet::new();
// Accept and serve connections.
loop {
node_api::serve_next_conn(&router, &listener, conn_limit, &mut conn_set).await;
}