Session

Struct Session 

Source
pub struct Session<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> { /* private fields */ }
Expand description

Network multiplexing session

Session is the core component of network multiplexing, managing multiple independent streams over a single underlying connection. Each session can handle multiple streams simultaneously, with each stream having its own unique stream ID and lifecycle.

Implementations§

Source§

impl<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> Session<T>

Source

pub fn server(conn: T, config: Config) -> Self

Create a server session.

Source

pub fn client(conn: T, config: Config) -> Self

Create a client session.

Source

pub async fn open(&self) -> Result<Stream, Error>

Open a new stream

This method allocates a new stream ID, creates the corresponding stream object, and sends a SYN frame to establish the connection. The returned stream can be used for data transmission.

Source

pub async fn accept(&self) -> Result<Stream, Error>

Accept a new stream connection

This method waits for stream creation requests from the remote end, then creates the corresponding stream object. Typically used by servers to accept connection requests from clients.

Source

pub fn close(self)

Close the session

This method gracefully closes the session, including:

  • Setting the shutdown flag
  • Notifying all background tasks to stop
  • Closing the underlying connection

Note: After calling this method, the session can no longer be used to send data.

Auto Trait Implementations§

§

impl<T> !Freeze for Session<T>

§

impl<T> !RefUnwindSafe for Session<T>

§

impl<T> Send for Session<T>

§

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

§

impl<T> Unpin for Session<T>

§

impl<T> !UnwindSafe for Session<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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