Skip to main content

Pool

Struct Pool 

Source
pub struct Pool { /* private fields */ }
Expand description

A pool of stream connections.

Implementations§

Source§

impl Pool

Source

pub fn new(config: PoolConfig, limits: Limits, events: Sender<Event>) -> Self

A pool that reports what it receives to events.

Source

pub fn len(&self) -> usize

How many connections are held.

Source

pub fn is_empty(&self) -> bool

Whether the pool is empty.

Source

pub fn accept(&mut self, stream: TcpStream, peer: SocketAddr)

Adopt a connection a peer opened.

Source

pub async fn send(&mut self, key: &ConnectionKey, bytes: Bytes) -> Result<()>

Send to a peer, connecting if there is no usable connection.

The dial never blocks the caller. A peer that black-holes SYN takes the OS connect timeout to fail — around two minutes — and the endpoint loop that calls this also owns every transaction timer. Waiting here would stop retransmissions for calls that have nothing to do with this peer, so the connection is established inside its own task and the bytes wait in the channel until it is up.

Source

pub fn accept_tls(&mut self, stream: TlsStream<TcpStream>, peer: SocketAddr)

Adopt a TLS connection a peer opened, once the handshake has completed.

Source

pub fn accept_quic(&mut self, connection: Connection, peer: SocketAddr)

Adopt an authenticated QUIC connection opened by a peer.

Source

pub async fn send_tls( &mut self, key: &ConnectionKey, verification_name: &str, client: &ClientTls, bytes: Bytes, ) -> Result<()>

Send to a peer over TLS, connecting and verifying if there is no usable connection.

The verification name is the host from the URI, not the address — see docs/specs/sip-tls.md §3.3 — and it is part of the pool key, so a connection verified as one name is never handed to traffic for another.

Source

pub fn accept_ws<S>( &mut self, ws: Socket<S>, key: ConnectionKey, keepalive: Duration, )
where S: AsyncRead + AsyncWrite + Unpin + Send + 'static,

Adopt a WebSocket connection a peer opened, once the handshake has completed.

Source

pub async fn send_ws( &mut self, key: &ConnectionKey, authority: &str, keepalive: Duration, client: Option<&ClientTls>, bytes: Bytes, ) -> Result<()>

Send to a peer over WebSocket, doing the handshake if there is no usable connection.

authority is what goes in the Host header of the upgrade request and, under WSS, the name the certificate must be valid for. Both are the host from the URI.

Source

pub fn remove(&mut self, key: &ConnectionKey, id: u64) -> bool

Forget a connection that has closed.

Source

pub fn holds(&self, key: &ConnectionKey) -> bool

Whether this connection is held.

Source

pub async fn send_on_existing( &mut self, key: &ConnectionKey, bytes: Bytes, ) -> bool

Answer on the connection a request arrived over, if it is still open.

Always tried before anything the Via says: opening a new connection to a NAT-ed client’s advertised address cannot work, which is what RFC 5923 exists to say.

Source

pub fn evict_idle(&mut self) -> Vec<ConnectionKey>

Close connections idle for longer than the configured timeout.

Source

pub async fn shutdown(&mut self)

Cancel every connection and wait until every tracked task has released its socket.

Trait Implementations§

Source§

impl Debug for Pool

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Pool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Pool

§

impl !RefUnwindSafe for Pool

§

impl Send for Pool

§

impl !Sync for Pool

§

impl Unpin for Pool

§

impl UnsafeUnpin for Pool

§

impl !UnwindSafe for Pool

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,