pub struct VCLPool { /* private fields */ }Expand description
Manages multiple VCLConnections under a single pool.
Each connection gets a unique ConnectionId assigned at bind().
The pool enforces a maximum connection limit set at construction.
Implementations§
Source§impl VCLPool
impl VCLPool
Sourcepub fn new(max_connections: usize) -> Self
pub fn new(max_connections: usize) -> Self
Create a new pool with a maximum number of concurrent connections.
§Example
use vcl_protocol::pool::VCLPool;
let pool = VCLPool::new(10);Sourcepub async fn bind(&mut self, addr: &str) -> Result<ConnectionId, VCLError>
pub async fn bind(&mut self, addr: &str) -> Result<ConnectionId, VCLError>
Bind a new connection to a local UDP address and add it to the pool.
Returns the ConnectionId assigned to this connection.
§Errors
VCLError::InvalidPacket— pool is at maximum capacityVCLError::IoError— socket bind failed
Sourcepub async fn connect(
&mut self,
id: ConnectionId,
addr: &str,
) -> Result<(), VCLError>
pub async fn connect( &mut self, id: ConnectionId, addr: &str, ) -> Result<(), VCLError>
Connect a pooled connection to a remote peer (client side handshake).
§Errors
VCLError::InvalidPacket— connection ID not foundVCLError::HandshakeFailed— handshake failed
Sourcepub async fn accept_handshake(
&mut self,
id: ConnectionId,
) -> Result<(), VCLError>
pub async fn accept_handshake( &mut self, id: ConnectionId, ) -> Result<(), VCLError>
Accept an incoming handshake on a pooled connection (server side).
§Errors
VCLError::InvalidPacket— connection ID not foundVCLError::HandshakeFailed— handshake failed
Sourcepub async fn send(
&mut self,
id: ConnectionId,
data: &[u8],
) -> Result<(), VCLError>
pub async fn send( &mut self, id: ConnectionId, data: &[u8], ) -> Result<(), VCLError>
Send data on a pooled connection.
§Errors
VCLError::InvalidPacket— connection ID not found- Any error from
VCLConnection::send
Sourcepub async fn recv(&mut self, id: ConnectionId) -> Result<VCLPacket, VCLError>
pub async fn recv(&mut self, id: ConnectionId) -> Result<VCLPacket, VCLError>
Receive the next data packet on a pooled connection.
§Errors
VCLError::InvalidPacket— connection ID not found- Any error from
VCLConnection::recv
Sourcepub async fn ping(&mut self, id: ConnectionId) -> Result<(), VCLError>
pub async fn ping(&mut self, id: ConnectionId) -> Result<(), VCLError>
Send a ping on a pooled connection.
§Errors
VCLError::InvalidPacket— connection ID not found- Any error from
VCLConnection::ping
Sourcepub async fn rotate_keys(&mut self, id: ConnectionId) -> Result<(), VCLError>
pub async fn rotate_keys(&mut self, id: ConnectionId) -> Result<(), VCLError>
Rotate keys on a pooled connection.
§Errors
VCLError::InvalidPacket— connection ID not found- Any error from
VCLConnection::rotate_keys
Sourcepub fn close(&mut self, id: ConnectionId) -> Result<(), VCLError>
pub fn close(&mut self, id: ConnectionId) -> Result<(), VCLError>
Close a specific connection and remove it from the pool.
§Errors
VCLError::InvalidPacket— connection ID not foundVCLError::ConnectionClosed— already closed
Sourcepub fn connection_ids(&self) -> Vec<ConnectionId> ⓘ
pub fn connection_ids(&self) -> Vec<ConnectionId> ⓘ
Returns a list of all active ConnectionIds in the pool.
Sourcepub fn contains(&self, id: ConnectionId) -> bool
pub fn contains(&self, id: ConnectionId) -> bool
Returns true if a connection with the given ID exists in the pool.
Sourcepub fn get(&self, id: ConnectionId) -> Result<&VCLConnection, VCLError>
pub fn get(&self, id: ConnectionId) -> Result<&VCLConnection, VCLError>
Get a reference to a connection by ID.
§Errors
Returns VCLError::InvalidPacket if the ID is not found.