pub struct ConnPool<C> { /* private fields */ }Expand description
Outbound connection pool.
The pool keeps an AutoEject tracker and a small idle list;
callers acquire a connection through ConnPool::get and
return it through ConnHandle::release (or by dropping the
handle, which routes to the same path).
Implementations§
Source§impl<C: Send + 'static> ConnPool<C>
impl<C: Send + 'static> ConnPool<C>
Sourcepub fn new(cfg: ConnPoolConfig) -> Self
pub fn new(cfg: ConnPoolConfig) -> Self
Build a pool with no factory installed. Build a pool with no factory installed.
Callers must install a factory through
ConnPool::set_factory before invoking
ConnPool::get. The factory-less constructor exists so
callers can build the pool eagerly during configuration and
wire the factory once the resolver has populated the target
address.
§Examples
use dynomite::io::reactor::TcpTransport;
use dynomite::net::pool::{ConnPool, ConnPoolConfig};
let _: ConnPool<TcpTransport> = ConnPool::new(ConnPoolConfig::default());Sourcepub fn with_factory<F>(cfg: ConnPoolConfig, factory: F) -> Selfwhere
F: ConnFactory<C>,
pub fn with_factory<F>(cfg: ConnPoolConfig, factory: F) -> Selfwhere
F: ConnFactory<C>,
Build a pool with a factory installed up front.
§Examples
use dynomite::net::pool::{ConnPool, ConnPoolConfig};
use dynomite::net::NetError;
let pool = ConnPool::with_factory(ConnPoolConfig::default(), || async {
Ok::<u32, NetError>(0)
});
assert_eq!(pool.config().max_connections, 1);Sourcepub fn set_factory<F: ConnFactory<C>>(&mut self, factory: F)
pub fn set_factory<F: ConnFactory<C>>(&mut self, factory: F)
Install a connection factory.
Sourcepub fn config(&self) -> ConnPoolConfig
pub fn config(&self) -> ConnPoolConfig
Borrow the pool config.
Sourcepub fn idle_count(&self) -> usize
pub fn idle_count(&self) -> usize
Number of idle connections currently in the pool.
Sourcepub fn is_ejected(&self, now: Instant) -> bool
pub fn is_ejected(&self, now: Instant) -> bool
True when the host has been auto-ejected at this instant.
Sourcepub fn auto_eject(&self) -> AutoEject
pub fn auto_eject(&self) -> AutoEject
Snapshot of the auto-eject tracker.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shut the pool down.
Wakes every waiter blocked in ConnPool::get. Subsequent
get calls return NetError::PoolShutdown.
Sourcepub async fn get(&self) -> Result<ConnHandle<C>, NetError>
pub async fn get(&self) -> Result<ConnHandle<C>, NetError>
Acquire a connection.
Reuses an idle connection when one is available; otherwise invokes the factory until it succeeds or the auto-eject tracker reports the target as unreachable.
§Errors
Returns NetError::Ejected when the host is in its eject
window, NetError::PoolShutdown when the pool was shut
down, or the underlying factory error otherwise.