Struct Session

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

A Session, able to accept/create streams and send/recv datagrams.

Can be cloned to create multiple handles to the same underlying connection.

If all references to a connection (including every clone of the Session handle, streams of incoming streams, and the various stream types) have been dropped, then the session will be automatically closed with a code of 0 and an empty reason. You can also close the session explicitly by calling Session::close().

Closing the session immediately immediately sends a CONNECTION_CLOSE frame and then abandons efforts to deliver data to the peer. Upon receiving CONNECTION_CLOSE the peer may drop any stream data not yet delivered to the application. Session::close() describes in more detail how to gracefully close a session without losing application data.

Implementations§

Source§

impl Session

Source

pub fn peer_key(&self) -> Option<&SubjectPublicKeyInfoDer<'_>>

The public key of the remote peer.

This may be unavailable if require_client_auth returned false in the Endpoint’s AllowConnection instance.

Source

pub unsafe fn as_quic(&self) -> &Connection

Get access to the underlying QUIC Connection.

Safety: you must not use any methods that alter the session state, nor any that send packets. This may corrupt the WebTransport state layered on top.

Accessing statistical and factual information (such as peer_identity(), remote_address(), stats(), close_reason(), etc) is safe.

Source

pub async fn accept_uni(&self) -> Result<RecvStream, Error>

Wait until the peer creates a new unidirectional stream.

Will error if the connection is closed.

Source

pub async fn accept_bi(&self) -> Result<(SendStream, RecvStream), Error>

Wait until the peer creates a new bidirectional stream.

Source

pub async fn open_bi(&self) -> Result<(SendStream, RecvStream), Error>

Open a new bidirectional stream.

May wait when there are too many concurrent streams.

Source

pub async fn open_uni(&self) -> Result<SendStream, Error>

Open a new unidirectional stream.

May wait when there are too many concurrent streams.

Source

pub fn send_datagram(&self, payload: Bytes) -> Result<(), Error>

Send an unreliable datagram over the network.

QUIC datagrams may be dropped for any reason, including (non-exhaustive):

  • Network congestion
  • Random packet loss
  • Payload is larger than max_datagram_size()
  • Peer is not receiving datagrams
  • Peer has too many outstanding datagrams
Source

pub async fn max_datagram_size(&self) -> usize

The maximum size of a datagram that can be sent.

Source

pub async fn recv_datagram(&self) -> Result<Bytes, Error>

Receive a datagram over the network.

Source

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

Close the session immediately.

Pending operations will fail immediately with Connection(ConnectionError::LocallyClosed). No more data is sent to the peer beyond a CONNECTION_CLOSE frame, and the peer may drop buffered data upon receiving the CONNECTION_CLOSE frame.

code and reason are not interpreted, and are provided directly to the peer.

reason will be truncated to fit in a single packet with overhead; to improve odds that it is preserved in full, it should be kept under 1KiB.

§Gracefully closing a session

Only the peer last receiving application data can be certain that all data is delivered. The only reliable action it can then take is to close the session, potentially with a custom error code. The delivery of the final CONNECTION_CLOSE frame is very likely if both endpoints stay online long enough, and Endpoint::wait_idle() can be used to provide sufficient time. Otherwise, the remote peer will time out the session after 30 seconds.

The sending side can not guarantee all stream data is delivered to the remote application. It only knows the data is delivered to the QUIC stack of the remote endpoint. Once the local side sends a CONNECTION_CLOSE frame, the remote endpoint may drop any data it received but is as yet undelivered to the application, including data that was acknowledged as received to the local endpoint.

Source

pub async fn closed(&self) -> Result<Option<ApplicationClose>, Error>

Wait until the connection is closed.

Returns Ok(None) if the connection was closed locally, Ok(Some(_)) if the connection was closed by a peer (e.g. with close()), and Err(_) for other unexpected reasons.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

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

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

impl PartialEq for Session

Source§

fn eq(&self, other: &Session) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Session

Source§

impl StructuralPartialEq for Session

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

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

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T