#[non_exhaustive]pub struct Limits { /* private fields */ }Expand description
Every bound net-io enforces. Unset values take the defaults of the driver that runs the connection.
§Examples
use net_io::{DriverKind, Limits, MinRate};
use std::time::Duration;
let limits = Limits::builder()
.max_connections(20_000)
.idle_timeout(Duration::from_secs(15))
.min_rate(MinRate::new(512, Duration::from_secs(10)))
.build()?;
assert_eq!(limits.max_connections(), Some(20_000));
assert_eq!(limits.read_timeout(), None);
assert_eq!(limits.resolve(DriverKind::Blocking).read_timeout(), Some(Duration::from_secs(30)));Implementations§
Source§impl Limits
impl Limits
Sourcepub fn builder() -> LimitsBuilder
pub fn builder() -> LimitsBuilder
A builder with every value unset.
let limits = net_io::Limits::builder().max_connections(100).build()?;
assert_eq!(limits.max_per_source(), None);Sourcepub fn reactor_defaults() -> Limits
pub fn reactor_defaults() -> Limits
Every value set to the reactor’s defaults.
assert_eq!(net_io::Limits::reactor_defaults().max_connections(), Some(10_000));Sourcepub fn blocking_defaults() -> Limits
pub fn blocking_defaults() -> Limits
Every value set to the blocking driver’s defaults.
assert_eq!(net_io::Limits::blocking_defaults().idle_timeout(), Some(std::time::Duration::from_secs(5)));Sourcepub fn to_builder(&self) -> LimitsBuilder
pub fn to_builder(&self) -> LimitsBuilder
A builder starting from these values.
Every value carried over counts as set, so lowering max_connections
below a carried-over max_per_listener fails validation. Start from
Limits::builder to let dependent values follow max_connections.
let limits = net_io::Limits::blocking_defaults().to_builder().max_connections(256).build()?;
assert_eq!(limits.max_connections(), Some(256));Sourcepub fn resolve(&self, driver: DriverKind) -> Limits
pub fn resolve(&self, driver: DriverKind) -> Limits
These limits with unset values filled from driver’s defaults.
let limits = net_io::Limits::builder().max_connections(10).build()?;
let resolved = limits.resolve(net_io::DriverKind::Blocking);
assert_eq!(resolved.max_per_source().map(|(n, _)| n), Some(10));Sourcepub fn validate(
&self,
workers: u16,
descriptor_limit: Option<u64>,
) -> Result<(), NetError>
pub fn validate( &self, workers: u16, descriptor_limit: Option<u64>, ) -> Result<(), NetError>
Checks the resolved values against each other, the worker count, and the process’s descriptor limit.
§Errors
InvalidConfig { field, reason } for the first rule broken.
let limits = net_io::Limits::builder().max_connections(1_000_000).build()?;
assert!(limits.validate(4, Some(1024)).is_err());Sourcepub fn max_connections(&self) -> Option<u32>
pub fn max_connections(&self) -> Option<u32>
The global connection cap.
Sourcepub fn max_per_listener(&self) -> Option<u32>
pub fn max_per_listener(&self) -> Option<u32>
The per-listener connection cap.
Sourcepub fn max_per_source(&self) -> Option<(u32, PrefixPolicy)>
pub fn max_per_source(&self) -> Option<(u32, PrefixPolicy)>
The per-source concurrency cap and how sources are grouped.
Sourcepub fn accept_batch(&self) -> Option<u16>
pub fn accept_batch(&self) -> Option<u16>
Connections accepted per wake-up.
Sourcepub fn handshake_timeout(&self) -> Option<Duration>
pub fn handshake_timeout(&self) -> Option<Duration>
Time for the PROXY header and TLS handshake together.
Sourcepub fn idle_timeout(&self) -> Option<Duration>
pub fn idle_timeout(&self) -> Option<Duration>
Time to wait for the next exchange.
Sourcepub fn read_timeout(&self) -> Option<Duration>
pub fn read_timeout(&self) -> Option<Duration>
Time to wait for bytes during an exchange.
Sourcepub fn write_timeout(&self) -> Option<Duration>
pub fn write_timeout(&self) -> Option<Duration>
Time to wait for the peer to take bytes.
Sourcepub fn park_timeout(&self) -> Option<Duration>
pub fn park_timeout(&self) -> Option<Duration>
Time a parked connection may wait for its completion.
Sourcepub fn proxy_header_max(&self) -> Option<u16>
pub fn proxy_header_max(&self) -> Option<u16>
The PROXY v2 address-and-TLV cap.
Sourcepub fn read_class(&self) -> Option<(SizeClass, SizeClass)>
pub fn read_class(&self) -> Option<(SizeClass, SizeClass)>
The initial and maximum read buffer class.
Sourcepub fn output_budget(&self) -> Option<u32>
pub fn output_budget(&self) -> Option<u32>
Pool memory a connection’s output may hold.
Sourcepub fn completion_queue(&self) -> Option<u32>
pub fn completion_queue(&self) -> Option<u32>
A worker’s completion queue length.
Sourcepub fn buffer_budget(&self) -> Option<u64>
pub fn buffer_budget(&self) -> Option<u64>
Total bytes of buffers all workers may allocate.
Sourcepub fn drain_timeout(&self) -> Option<Duration>
pub fn drain_timeout(&self) -> Option<Duration>
The drain deadline.
Sourcepub fn graceful_linger(&self) -> Option<(Duration, u32)>
pub fn graceful_linger(&self) -> Option<(Duration, u32)>
The graceful-close linger: time and bytes read and discarded.
Sourcepub fn refusal_bytes_max(&self) -> Option<u16>
pub fn refusal_bytes_max(&self) -> Option<u16>
The largest refusal reply.
Sourcepub fn lane_reserve(&self, lane: Lane) -> Option<u32>
pub fn lane_reserve(&self, lane: Lane) -> Option<u32>
The connection slots reserved for lane (lanes 0 to 7).