pub struct ConnectionPool { /* private fields */ }Expand description
Connection pool for reusing HTTP/1.1, HTTP/2, and HTTP/3 connections
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn with_config(
max_idle: Duration,
max_per_host: usize,
max_streams: u32,
) -> Self
pub fn with_config( max_idle: Duration, max_per_host: usize, max_streams: u32, ) -> Self
Create a connection pool with custom configuration
Sourcepub async fn get_h1(&self, key: &PoolKey) -> Option<MaybeHttpsStream>
pub async fn get_h1(&self, key: &PoolKey) -> Option<MaybeHttpsStream>
Get an idle HTTP/1.1 connection from the pool
Sourcepub async fn put_h1(&self, key: PoolKey, stream: MaybeHttpsStream)
pub async fn put_h1(&self, key: PoolKey, stream: MaybeHttpsStream)
Return an HTTP/1.1 connection to the pool
Sourcepub fn try_put_h1(&self, key: PoolKey, stream: MaybeHttpsStream) -> bool
pub fn try_put_h1(&self, key: PoolKey, stream: MaybeHttpsStream) -> bool
Try to return an HTTP/1.1 connection to the pool without awaiting.
This is used by poll-based response bodies, where parking the caller on an async pool lock would couple body EOF to an unrelated task wake. If the pool lock is temporarily unavailable, the connection is safely discarded instead of being returned late or through a spawned shim.
Sourcepub async fn get_or_create(
&self,
key: &PoolKey,
version: HttpVersion,
) -> Result<Option<PoolEntry>>
pub async fn get_or_create( &self, key: &PoolKey, version: HttpVersion, ) -> Result<Option<PoolEntry>>
Get an existing connection or signal that a new one should be created
Returns:
Ok(Some(entry)): Reusable connection found (HTTP/2 or HTTP/3)Ok(None): No reusable connection, create new one
Sourcepub async fn invalidate(&self, key: &PoolKey)
pub async fn invalidate(&self, key: &PoolKey)
Invalidate a connection (due to error, GOAWAY, etc.)
Sourcepub fn spawn_cleanup_task(self: Arc<Self>, interval: Duration) -> JoinHandle<()>
pub fn spawn_cleanup_task(self: Arc<Self>, interval: Duration) -> JoinHandle<()>
Spawn a background cleanup task that runs periodically
Returns a handle to the spawned task