pub struct ConnectionPool { /* private fields */ }Expand description
Connection pool for managing active connections
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn new(max_connections: Option<usize>) -> Self
pub fn new(max_connections: Option<usize>) -> Self
Create a pool bounded to max_connections, or unbounded on None.
Sourcepub fn try_reserve(&self) -> bool
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.
Sourcepub fn cancel_reservation(&self)
pub fn cancel_reservation(&self)
Release a slot taken by Self::try_reserve without admitting a
connection.
Sourcepub fn add_connection(&self, addr: SocketAddr) -> ConnectionId
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.
Sourcepub fn add_connection_reserved(&self, addr: SocketAddr) -> ConnectionId
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.
Sourcepub fn record_io(&self, id: ConnectionId, bytes_received: u64, bytes_sent: u64)
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).
Sourcepub fn remove_connection(&self, id: ConnectionId) -> bool
pub fn remove_connection(&self, id: ConnectionId) -> bool
Remove a tracked connection; returns whether it was present.
Sourcepub fn has_capacity(&self) -> bool
pub fn has_capacity(&self) -> bool
Return whether the pool can admit another connection.
Sourcepub fn get_active_connections(&self) -> HashMap<ConnectionId, ConnectionInfo>
pub fn get_active_connections(&self) -> HashMap<ConnectionId, ConnectionInfo>
Snapshot the tracked connections.
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Count of connections currently tracked as open.