use std::net::ToSocketAddrs;
use std::time::Duration;
#[derive(Clone, Copy, Debug)]
pub struct Config {
pub(crate) max_concurrent_connections: usize,
pub(crate) max_concurrent_streams: usize,
pub(crate) max_frame_size: usize,
pub(crate) max_flush_requests: usize,
pub(crate) max_flush_size: usize,
pub(crate) idle_timeout: Duration,
pub(crate) write_timeout: Duration,
}
impl Config {
pub fn new() -> Self {
Self {
max_concurrent_connections: 100,
max_concurrent_streams: 1000,
max_frame_size: 16 * 1024,
max_flush_requests: 50,
max_flush_size: 15000,
idle_timeout: Duration::from_secs(60),
write_timeout: Duration::from_secs(10),
}
}
pub fn max_concurrent_connections(self, n: usize) -> Self {
Self {
max_concurrent_connections: n,
..self
}
}
pub fn max_concurrent_streams(self, n: usize) -> Self {
Self {
max_concurrent_streams: n,
..self
}
}
pub fn max_frame_size(self, n: usize) -> Self {
Self {
max_frame_size: n,
..self
}
}
pub fn max_flush_requests(self, n: usize) -> Self {
Self {
max_flush_requests: n,
..self
}
}
pub fn max_flush_size(self, n: usize) -> Self {
Self {
max_frame_size: n,
..self
}
}
pub fn idle_timeout(self, d: Duration) -> Self {
Self {
idle_timeout: d,
..self
}
}
pub fn write_timeout(self, d: Duration) -> Self {
Self {
write_timeout: d,
..self
}
}
pub fn serve_local<S, A>(self, srv: S, addr: A) -> std::io::Result<()>
where
S: crate::PajamaxService + Clone + Send + Sync + 'static,
A: ToSocketAddrs,
{
crate::do_serve(
|s, cnter, cfg| crate::LocalConnection::new(srv.clone(), s, cnter, cfg),
addr,
self,
)
}
pub fn serve_dispatch<S, A>(self, srv: S, addr: A) -> std::io::Result<()>
where
S: crate::PajamaxDispatchService + Clone + Send + Sync + 'static,
A: ToSocketAddrs,
{
crate::do_serve(
|s, cnter, cfg| crate::DispatchConnection::new(srv.clone(), s, cnter, cfg),
addr,
self,
)
}
}