Skip to main content

Session

Trait Session 

Source
pub trait Session: 'static {
    type SendStream: SendStream;
    type RecvStream: RecvStream;
    type Error: Error;

Show 26 methods // Required methods fn poll_accept_uni( &self, waiter: &Waiter, ) -> Poll<Result<Self::RecvStream, Self::Error>>; fn poll_accept_bi( &self, waiter: &Waiter, ) -> Poll<Result<BiStreams<Self>, Self::Error>>; fn poll_open_uni( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<Self::SendStream, Self::Error>>; fn poll_open_bi( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<BiStreams<Self>, Self::Error>>; fn send_group( &self, priority: i64, ) -> Option<<Self::SendStream as SendStream>::Group>; fn send_datagram( &self, payload: Bytes, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Result<(), Self::Error>; fn poll_recv_datagram( &self, waiter: &Waiter, ) -> Poll<Result<Bytes, Self::Error>>; fn max_datagram_size(&self) -> usize; fn protocol(&self) -> Option<&str>; fn address(&self) -> Address; fn close(&self, code: u32, reason: &str); fn poll_closed(&self, waiter: &Waiter) -> Poll<Self::Error>; // Provided methods fn metrics(&self) -> impl Metrics { ... } fn wire(&self) -> Option<Wire> { ... } fn probe(&self) -> Option<Probe> { ... } fn receive_window(&self) -> Option<ReceiveWindow> { ... } fn reliable_reset(&self) -> bool { ... } fn set_limits(&self, limits: Limits) -> Result<(), LimitsError> { ... } fn set_keep_alive( &self, keep_alive: KeepAlive, ) -> Result<(), KeepAliveError> { ... } fn poll_liveness(&self, waiter: &Waiter, last: Liveness) -> Poll<Liveness> { ... } fn accept_uni(&self) -> AcceptUni<'_, Self> ⓘ { ... } fn accept_bi(&self) -> AcceptBi<'_, Self> ⓘ { ... } fn open_uni<'a>( &'a self, options: SendOptions<'a, <Self::SendStream as SendStream>::Group>, ) -> OpenUni<'a, Self> ⓘ { ... } fn open_bi<'a>( &'a self, options: SendOptions<'a, <Self::SendStream as SendStream>::Group>, ) -> OpenBi<'a, Self> ⓘ { ... } fn recv_datagram(&self) -> RecvDatagram<'_, Self> ⓘ { ... } fn closed(&self) -> SessionClosed<'_, Self> ⓘ { ... }
}
Expand description

A transport session, shared by reference between the tasks that use it.

Every session operation takes &self and keeps no per-caller progress between polls: the caller owns the [kio::Waiter] it parks, so an abandoned wait leaves nothing behind. Share a session with Arc rather than cloning it. Poll operations never borrow caller buffers between calls, and shared resources must not be held across a wait. Implementations register the supplied waiter before Pending.

Required Associated Types§

Source

type SendStream: SendStream

The outgoing stream type.

Source

type RecvStream: RecvStream

The incoming stream type.

Source

type Error: Error

The error type for every operation on this session.

Required Methods§

Source

fn poll_accept_uni( &self, waiter: &Waiter, ) -> Poll<Result<Self::RecvStream, Self::Error>>

Poll for a unidirectional stream created by the peer.

Source

fn poll_accept_bi( &self, waiter: &Waiter, ) -> Poll<Result<BiStreams<Self>, Self::Error>>

Poll for a bidirectional stream created by the peer.

Source

fn poll_open_uni( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<Self::SendStream, Self::Error>>

Poll to open a unidirectional stream scheduled by options, which blocks while there are too many concurrent streams.

Source

fn poll_open_bi( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<BiStreams<Self>, Self::Error>>

Poll to open a bidirectional stream, its sending half scheduled by options, which blocks while there are too many concurrent streams.

Source

fn send_group( &self, priority: i64, ) -> Option<<Self::SendStream as SendStream>::Group>

Open a send group at priority, or None when the transport orders streams by their own priority alone.

Streams that join a group, through SendOptions or SendStream::set_group, and datagrams sent in it share bytes with the session’s other groups: a higher priority group preempts every lower one, and groups of equal priority get an equal share of bytes however many streams each has queued. Streams outside every group go before all of them. The group is released once its last handle is dropped and its streams finish.

Source

fn send_datagram( &self, payload: Bytes, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Result<(), Self::Error>

Send a datagram scheduled by options, best-effort.

The datagram is ranked among its group’s streams by its priority, like a stream’s own priority, and goes ahead of a stream of equal priority. Without a group it is ranked among the ungrouped streams. A transport that cannot rank datagrams against streams ignores options.

Never blocks: a transport with no room drops a queued datagram, the lowest priority first where it can tell, exactly as the network is allowed to.

Accepting a datagram is not delivery. QUIC datagrams may still be dropped:

  • Network congestion.
  • Random packet loss.
  • Payload is larger than max_datagram_size()
  • Peer is not receiving datagrams.
Source

fn poll_recv_datagram( &self, waiter: &Waiter, ) -> Poll<Result<Bytes, Self::Error>>

Poll for a datagram from the network.

Source

fn max_datagram_size(&self) -> usize

The maximum size of a datagram that can be sent.

Source

fn protocol(&self) -> Option<&str>

Return the application protocol negotiated for this session, if any.

For WebTransport over HTTP/3 this is the selected WebTransport subprotocol; for raw QUIC it is the negotiated ALPN. Return None if the transport does not negotiate either or the ALPN is not valid UTF-8. This is required rather than defaulted: a transport that negotiates an application protocol and forgets to report it is a silent bug, and the default hid that.

Source

fn address(&self) -> Address

Return where this transport carries the request target.

Source

fn close(&self, code: u32, reason: &str)

Close the connection immediately with a code and reason.

Idempotent, and deliberately infallible: closing an already-closed connection achieved what the caller asked for, and there is nothing they could do with an error.

Source

fn poll_closed(&self, waiter: &Waiter) -> Poll<Self::Error>

Poll until the connection is closed by either side.

Provided Methods§

Source

fn metrics(&self) -> impl Metrics

Return connection-level metrics; by default, none are tracked.

Source

fn wire(&self) -> Option<Wire>

Return the wire counters this transport updates, or None when it tracks none.

Source

fn probe(&self) -> Option<Probe>

Return the target this transport’s sender probes up to, or None when it has no sender.

The session sets the target; see super::Probe. Without a sender nothing probes, so the congestion estimate stops rising while the connection is app-limited.

Source

fn receive_window(&self) -> Option<ReceiveWindow>

Return the receive windows now in force, or None when the transport cannot say.

Read whenever the session considers pausing a stream, so a window changed on a live connection is followed. Without one, the session cannot bound the credit a paused stream holds, so it never pauses one: ingest reads every stream as it arrives and sheds what its readers fall behind on.

Source

fn reliable_reset(&self) -> bool

Whether SendStream::reset_at still delivers its prefix to the peer’s reader, such as over raw QUIC with RESET_STREAM_AT negotiated, but never over WebTransport, whose browser API may discard it anyway. A plain RESET_STREAM lets the peer discard bytes it has not read, even acknowledged ones, so the default is false.

Source

fn set_limits(&self, limits: Limits) -> Result<(), LimitsError>

Apply limits to the live session, such as to open the receive window a server held back until it admitted the peer.

Errors with LimitsError::Unsupported when the transport cannot change them, which is the default: such a transport holds nothing back to open.

Source

fn set_keep_alive(&self, keep_alive: KeepAlive) -> Result<(), KeepAliveError>

Start keep_alive: probe the peer once half of its soft passes unheard, report it Stale through poll_liveness once all of soft does, and close as an idle timeout once hard does. Any packet the peer sends counts as hearing it, so a busy session sends no probe. A peer already unheard for soft when this is called is reported stale at once.

Errors with KeepAliveError::Unsupported when the transport cannot probe its peer, which is the default, so the option never passes silently.

Source

fn poll_liveness(&self, waiter: &Waiter, last: Liveness) -> Poll<Liveness>

Poll until the peer’s liveness differs from last, returning it. Pending forever without a keep-alive.

Source

fn accept_uni(&self) -> AcceptUni<'_, Self> ⓘ

Accept the next unidirectional stream opened by the peer.

Source

fn accept_bi(&self) -> AcceptBi<'_, Self> ⓘ

Accept the next bidirectional stream opened by the peer.

Source

fn open_uni<'a>( &'a self, options: SendOptions<'a, <Self::SendStream as SendStream>::Group>, ) -> OpenUni<'a, Self> ⓘ

Open a unidirectional stream scheduled by options, waiting for stream credit if necessary.

Source

fn open_bi<'a>( &'a self, options: SendOptions<'a, <Self::SendStream as SendStream>::Group>, ) -> OpenBi<'a, Self> ⓘ

Open a bidirectional stream, its sending half scheduled by options, waiting for stream credit if necessary.

Source

fn recv_datagram(&self) -> RecvDatagram<'_, Self> ⓘ

Receive the next datagram from the peer.

Source

fn closed(&self) -> SessionClosed<'_, Self> ⓘ

Wait until the session is closed by either side, returning the reason.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S: Session + ?Sized> Session for Arc<S>

A session shared with the client or server that runs it, so the caller can still close or watch it.

Source§

type SendStream = <S as Session>::SendStream

Source§

type RecvStream = <S as Session>::RecvStream

Source§

type Error = <S as Session>::Error

Source§

fn poll_accept_uni( &self, waiter: &Waiter, ) -> Poll<Result<Self::RecvStream, Self::Error>>

Source§

fn poll_accept_bi( &self, waiter: &Waiter, ) -> Poll<Result<BiStreams<Self>, Self::Error>>

Source§

fn poll_open_uni( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<Self::SendStream, Self::Error>>

Source§

fn poll_open_bi( &self, waiter: &Waiter, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Poll<Result<BiStreams<Self>, Self::Error>>

Source§

fn send_group( &self, priority: i64, ) -> Option<<Self::SendStream as SendStream>::Group>

Source§

fn send_datagram( &self, payload: Bytes, options: SendOptions<'_, <Self::SendStream as SendStream>::Group>, ) -> Result<(), Self::Error>

Source§

fn poll_recv_datagram( &self, waiter: &Waiter, ) -> Poll<Result<Bytes, Self::Error>>

Source§

fn max_datagram_size(&self) -> usize

Source§

fn protocol(&self) -> Option<&str>

Source§

fn address(&self) -> Address

Source§

fn close(&self, code: u32, reason: &str)

Source§

fn poll_closed(&self, waiter: &Waiter) -> Poll<Self::Error>

Source§

fn metrics(&self) -> impl Metrics

Source§

fn wire(&self) -> Option<Wire>

Source§

fn probe(&self) -> Option<Probe>

Source§

fn receive_window(&self) -> Option<ReceiveWindow>

Source§

fn reliable_reset(&self) -> bool

Source§

fn set_limits(&self, limits: Limits) -> Result<(), LimitsError>

Source§

fn set_keep_alive(&self, keep_alive: KeepAlive) -> Result<(), KeepAliveError>

Source§

fn poll_liveness(&self, waiter: &Waiter, last: Liveness) -> Poll<Liveness>

Implementors§