Skip to main content

Limits

Struct Limits 

Source
#[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

Source

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);
Source

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));
Source

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)));
Source

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));
Source

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));
Source

pub fn validate( &self, workers: u16, descriptor_limit: Option<u64>, ) -> Result<(), NetError>

Checks the values, with unset ones taken from the blocking driver’s defaults, against each other, the worker count, and the process’s descriptor limit. ServerBuilder::build runs the same checks with the defaults of the driver it resolved.

§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());
Source

pub fn max_connections(&self) -> Option<u32>

The global connection cap.

Source

pub fn max_per_listener(&self) -> Option<u32>

The per-listener connection cap.

Source

pub fn max_per_source(&self) -> Option<(u32, PrefixPolicy)>

The per-source concurrency cap and how sources are grouped. Each listener applies its own value to its own connections. Every open connection counts, including one finishing a graceful close, so a client at the cap that reconnects at once can be refused until its last connection is closed.

Source

pub fn backlog(&self) -> Option<u32>

The listen backlog.

Source

pub fn accept_batch(&self) -> Option<u16>

Connections accepted per wake-up.

Source

pub fn handshake_timeout(&self) -> Option<Duration>

Time for the PROXY header and TLS handshake together.

Source

pub fn idle_timeout(&self) -> Option<Duration>

Time to wait for the next exchange.

Source

pub fn read_timeout(&self) -> Option<Duration>

Time to wait for bytes during an exchange.

Source

pub fn write_timeout(&self) -> Option<Duration>

Time to wait for the peer to take bytes.

Source

pub fn park_timeout(&self) -> Option<Duration>

Time a parked connection may wait for its completion.

Source

pub fn min_rate(&self) -> Option<MinRate>

The minimum transfer rate.

Source

pub fn proxy_header_max(&self) -> Option<u16>

The PROXY v2 address-and-TLV cap.

Source

pub fn read_class(&self) -> Option<(SizeClass, SizeClass)>

The initial and maximum read buffer class.

Source

pub fn output_budget(&self) -> Option<u32>

Pool memory a connection’s output may hold.

Source

pub fn completion_queue(&self) -> Option<u32>

A worker’s completion queue length.

Source

pub fn buffer_budget(&self) -> Option<u64>

Total bytes of buffers all workers may allocate.

Each worker’s pool keeps at most the budget divided by the workers in its free lists and frees what is released above that, and a pool that needs a buffer of one size with the budget spent frees the buffers it keeps of other sizes first, so the budget comes back after a burst.

On the reactor a TLS connection takes its two buffers (the largest read class in, 64 KiB out) only when its first bytes arrive, and the connections whose handshake has not finished may hold at most a quarter of the budget, divided by the workers, on each worker (at least one handshake each). A connection whose handshake would take buffers above that is closed with Limit(BufferBudget); plaintext connections keep the rest.

Source

pub fn drain_timeout(&self) -> Option<Duration>

The drain deadline.

Source

pub fn first_request_grace(&self) -> Option<Duration>

How long a drain waits for the first request of a connection that has sent nothing yet.

Source

pub fn graceful_linger(&self) -> Option<(Duration, u32)>

The graceful-close linger: time and bytes read and discarded.

Source

pub fn denial_linger(&self) -> Option<Duration>

How long a connection that was sent a denial lingers before it closes.

Source

pub fn denial_linger_max(&self) -> Option<u32>

How many connections may close softly (linger after a denial, or close_after_flush) at once, server-wide.

Source

pub fn refusal_bytes_max(&self) -> Option<u16>

The largest refusal reply.

Source

pub fn tick(&self) -> Option<Duration>

The timer resolution.

Source

pub fn pressure(&self) -> Option<Pressure>

Adaptive deadlines under pressure.

Source

pub fn lane_reserve(&self, lane: Lane) -> Option<u32>

The connection slots reserved for lane (lanes 0 to 7).

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Limits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

§

impl Forget for Limits

§

impl Freeze for Limits

§

impl Move for Limits

§

impl RefUnwindSafe for Limits

§

impl Send for Limits

§

impl Sync for Limits

§

impl Unpin for Limits

§

impl UnsafeUnpin for Limits

§

impl UnwindSafe for Limits

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.