Skip to main content

ConnectionPool

Struct ConnectionPool 

Source
pub struct ConnectionPool { /* private fields */ }
Expand description

Connection pool for managing active connections

Implementations§

Source§

impl ConnectionPool

Source

pub fn new(max_connections: Option<usize>) -> Self

Create a pool bounded to max_connections, or unbounded on None.

Source

pub fn try_reserve(&self) -> bool

Reserve one connection slot ahead of an accept.

Returns false when the pool (active plus reserved) is at capacity.

Source

pub fn cancel_reservation(&self)

Release a slot taken by Self::try_reserve without admitting a connection.

Source

pub fn add_connection(&self, addr: SocketAddr) -> ConnectionId

Register a connection and return its unique id. The id is what the owning stream stores and later passes to Self::remove_connection.

Source

pub fn add_connection_reserved(&self, addr: SocketAddr) -> ConnectionId

Convert a successful reservation into a tracked connection, returning the new connection id. Releases exactly the one reservation taken by Self::try_reserve.

Source

pub fn record_io(&self, id: ConnectionId, bytes_received: u64, bytes_sent: u64)

Record I/O activity on a tracked connection, updating its byte counters and last_activity timestamp. No-op when the connection is no longer tracked (already removed or never pool-tracked).

Source

pub fn remove_connection(&self, id: ConnectionId) -> bool

Remove a tracked connection; returns whether it was present.

Source

pub fn has_capacity(&self) -> bool

Return whether the pool can admit another connection.

Source

pub fn get_active_connections(&self) -> HashMap<ConnectionId, ConnectionInfo>

Snapshot the tracked connections.

Source

pub fn connection_count(&self) -> usize

Count of connections currently tracked as open.

Trait Implementations§

Source§

impl Debug for ConnectionPool

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, 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.