Skip to main content

Session

Struct Session 

Source
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

Source

pub fn version(&self) -> Version

Returns the negotiated protocol version.

Source

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.

Source

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+).

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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