pub struct Session { /* private fields */ }Expand description
A MoQ transport session, wrapping a WebTransport connection.
Returned with a Driver by crate::Client::connect and
crate::Server::accept. The caller must poll or spawn that driver to run
the session.
Like every handle in this library, the lifecycle is reference counted: clones
share the connection, the transport closes when the last clone drops, and
abort closes it explicitly with an error. The handle and the
driver are severed in both directions: the driver holds no Session clone,
so running it never keeps the session alive, and the Session
holds no transport, so the handle is Send + Sync whatever transport the
driver uses. Everything transport-shaped (the close, the close reason,
the stats sample) is relayed through the driver.
Implementations§
Source§impl Session
impl Session
Sourcepub fn send_bandwidth(&self) -> Option<Consumer>
pub fn send_bandwidth(&self) -> Option<Consumer>
Returns a consumer for the estimated send bitrate (from the congestion controller).
Returns None if the QUIC backend doesn’t support bandwidth estimation.
Sourcepub fn recv_bandwidth(&self) -> Option<Consumer>
pub fn recv_bandwidth(&self) -> Option<Consumer>
Returns a consumer for the estimated receive bitrate (from PROBE).
Returns None if the MoQ version doesn’t support PROBE (requires moq-lite-03+).
Sourcepub fn stats(&self) -> Stats
pub fn stats(&self) -> Stats
Returns a snapshot of the current connection statistics.
Cheap and non-blocking: this reads the latest sample the session’s
driver took, and schedules a refresh, so periodic polling observes
fresh counters (100ms cadence). See Stats for which
metrics each backend reports.
Sourcepub fn abort(&self, err: Error)
pub fn abort(&self, err: Error)
Close the transport with an explicit error, instead of waiting for the last clone to drop. Idempotent: the first close wins.
The close is executed by the session’s driver, so it reaches the wire once the runtime polls it (immediately on a live runtime).
Sourcepub async fn closed(&self) -> Error
pub async fn closed(&self) -> Error
Block until the transport session is closed, returning the reason.
A close code the peer sent is decoded through the session registry (so an auth
rejection arrives as Error::Session(SessionError::Unauthorized)); every peer code is
preserved as Error::Session, and a close carrying no application code surfaces as
Error::Transport. See Error::from_transport. If the runtime drops
the driver instead of running it to completion, this resolves with
Error::Cancel.
Sourcepub fn drain(&self) -> Producer
pub fn drain(&self) -> Producer
Drain the peer gracefully: the handle for sending this session’s single GOAWAY.
The graceful counterpart to abort. Send the message with
goaway::Producer::send, then await closed to observe
the peer leaving.
Only a Goaway carrying a timeout
schedules a close of our own, so without one this waits for a peer that may
never leave. Set a deadline when the drain has to finish.
Available on every version. A version with no GOAWAY message (moq-lite-03 and earlier) simply carries no explanation to the peer; the deadline is the sender’s own timer either way, so the session still closes on schedule and the caller does not branch on the negotiated version.
Sourcepub fn draining(&self) -> Consumer
pub fn draining(&self) -> Consumer
Observe a GOAWAY from the peer, telling us to migrate elsewhere.
peek is the cheap synchronous check;
recv waits for one. Once a GOAWAY arrives, new
subscribe and announce-interest requests on this session are refused (both
drafts forbid opening new streams afterward); existing subscriptions keep
flowing until the session closes.