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§
Sourcetype SendStream: SendStream
type SendStream: SendStream
The outgoing stream type.
Sourcetype RecvStream: RecvStream
type RecvStream: RecvStream
The incoming stream type.
Required Methods§
Sourcefn poll_accept_uni(
&self,
waiter: &Waiter,
) -> Poll<Result<Self::RecvStream, Self::Error>>
fn poll_accept_uni( &self, waiter: &Waiter, ) -> Poll<Result<Self::RecvStream, Self::Error>>
Poll for a unidirectional stream created by the peer.
Sourcefn poll_accept_bi(
&self,
waiter: &Waiter,
) -> Poll<Result<BiStreams<Self>, Self::Error>>
fn poll_accept_bi( &self, waiter: &Waiter, ) -> Poll<Result<BiStreams<Self>, Self::Error>>
Poll for a bidirectional stream created by the peer.
Sourcefn poll_open_uni(
&self,
waiter: &Waiter,
options: SendOptions<'_, <Self::SendStream as SendStream>::Group>,
) -> Poll<Result<Self::SendStream, Self::Error>>
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.
Sourcefn poll_open_bi(
&self,
waiter: &Waiter,
options: SendOptions<'_, <Self::SendStream as SendStream>::Group>,
) -> Poll<Result<BiStreams<Self>, Self::Error>>
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.
Sourcefn send_group(
&self,
priority: i64,
) -> Option<<Self::SendStream as SendStream>::Group>
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.
Sourcefn send_datagram(
&self,
payload: Bytes,
options: SendOptions<'_, <Self::SendStream as SendStream>::Group>,
) -> Result<(), Self::Error>
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.
Sourcefn poll_recv_datagram(
&self,
waiter: &Waiter,
) -> Poll<Result<Bytes, Self::Error>>
fn poll_recv_datagram( &self, waiter: &Waiter, ) -> Poll<Result<Bytes, Self::Error>>
Poll for a datagram from the network.
Sourcefn max_datagram_size(&self) -> usize
fn max_datagram_size(&self) -> usize
The maximum size of a datagram that can be sent.
Sourcefn protocol(&self) -> Option<&str>
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.
Sourcefn close(&self, code: u32, reason: &str)
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.
Sourcefn poll_closed(&self, waiter: &Waiter) -> Poll<Self::Error>
fn poll_closed(&self, waiter: &Waiter) -> Poll<Self::Error>
Poll until the connection is closed by either side.
Provided Methods§
Sourcefn metrics(&self) -> impl Metrics
fn metrics(&self) -> impl Metrics
Return connection-level metrics; by default, none are tracked.
Sourcefn wire(&self) -> Option<Wire>
fn wire(&self) -> Option<Wire>
Return the wire counters this transport updates, or None when it tracks none.
Sourcefn probe(&self) -> Option<Probe>
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.
Sourcefn receive_window(&self) -> Option<ReceiveWindow>
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.
Sourcefn reliable_reset(&self) -> bool
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.
Sourcefn set_limits(&self, limits: Limits) -> Result<(), LimitsError>
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.
Sourcefn set_keep_alive(&self, keep_alive: KeepAlive) -> Result<(), KeepAliveError>
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.
Sourcefn poll_liveness(&self, waiter: &Waiter, last: Liveness) -> Poll<Liveness>
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.
Sourcefn accept_uni(&self) -> AcceptUni<'_, Self> ⓘ
fn accept_uni(&self) -> AcceptUni<'_, Self> ⓘ
Accept the next unidirectional stream opened by the peer.
Sourcefn accept_bi(&self) -> AcceptBi<'_, Self> ⓘ
fn accept_bi(&self) -> AcceptBi<'_, Self> ⓘ
Accept the next bidirectional stream opened by the peer.
Sourcefn open_uni<'a>(
&'a self,
options: SendOptions<'a, <Self::SendStream as SendStream>::Group>,
) -> OpenUni<'a, Self> ⓘ
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.
Sourcefn open_bi<'a>(
&'a self,
options: SendOptions<'a, <Self::SendStream as SendStream>::Group>,
) -> OpenBi<'a, Self> ⓘ
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.
Sourcefn recv_datagram(&self) -> RecvDatagram<'_, Self> ⓘ
fn recv_datagram(&self) -> RecvDatagram<'_, Self> ⓘ
Receive the next datagram from the peer.
Sourcefn closed(&self) -> SessionClosed<'_, Self> ⓘ
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.
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.