Trait ConnectionAdmissionPolicy
pub trait ConnectionAdmissionPolicy:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn try_acquire(
&self,
input: &Extensions,
) -> Result<Option<ConnectionAdmissionLease>, Box<dyn Error + Sync + Send>>;
fn subscribe(&self, listener: Weak<dyn ChangeListener>);
fn in_use(&self) -> bool;
}net only.Expand description
Transport resources required before a pooled connection can be handed out.
Unlike a concurrency limit, this reserves actual availability. A protocol can
consume its typed reservation when it starts the request. Implementations
must be nonblocking and must not reenter the pool. The pool calls
Self::try_acquire outside its storage and admission locks;
Self::subscribe and Self::in_use may run under them, so they only
read state and subscribe.
Required Methods§
fn try_acquire(
&self,
input: &Extensions,
) -> Result<Option<ConnectionAdmissionLease>, Box<dyn Error + Sync + Send>>
fn try_acquire( &self, input: &Extensions, ) -> Result<Option<ConnectionAdmissionLease>, Box<dyn Error + Sync + Send>>
Reserve one request’s resources, or return None when currently exhausted.
An error permanently rejects this connection: cached connections are
retired and selection continues; failure on a new connection is returned
to the caller. Request compatibility belongs in ConnectionReusePolicy,
not in this resource provider.
Inspect input without mutating it. Return the typed request binding in
the lease; the handout publishes it in an isolated child store when
serving the request.
fn subscribe(&self, listener: Weak<dyn ChangeListener>)
fn subscribe(&self, listener: Weak<dyn ChangeListener>)
Wake listener after every later availability change, until it is dropped.
Takes effect before it returns. Wake for returned reservations, peer
credit, the end of work Self::in_use reports, and the end of the
connection; after that, never again. Spurious wakes are permitted. Report
one returned stream as Freed, so
one waiter wakes for it, and anything else as
Other, which wakes them all. Keep
listeners in a ChangeSignal or
subscribe them to the sources: a change then wakes them without a task
or an allocation. A source that only has an async change future
forwards it from a task that notifies such a signal.
fn in_use(&self) -> bool
fn in_use(&self) -> bool
Whether the connection still carries work no handout accounts for, such as an upgraded tunnel or a request body still being sent.
The pool never treats such a connection as idle, so it is neither evicted nor expired; subscribers must also wake once this work ends, as the pool asks again only after a change. It never asks from a listener or with a lock other connections need, so this may take the source’s own locks, but must not call into the pool.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".