SessionHandle

Struct SessionHandle 

Source
pub struct SessionHandle<C: Connection> { /* private fields */ }
Expand description

Active session handle with control stream access.

This handle is returned from Session::start and provides methods for stream operations and message processing.

For a more convenient API that supports concurrent operations, wrap this handle in a SessionClient using SessionClient::new.

Implementations§

Source§

impl<C: Connection> SessionHandle<C>

Source

pub fn state(&self) -> State

Returns the session state.

Source

pub fn negotiated_params(&self) -> Option<NegotiatedParams>

Returns the negotiated parameters.

Source

pub fn is_ready(&self) -> bool

Returns true if the session is ready for stream operations.

Source

pub fn is_disconnected(&self) -> bool

Returns true if the connection was lost.

Source

pub async fn open( &mut self, service: impl Into<ServiceId> + AsRef<str>, metadata: Metadata, ) -> Result<(C::SendStream, C::RecvStream), Error>

Opens a reverse stream to the peer.

Sends an OpenRequest for the specified service and waits for the peer to accept and bind the stream.

§Arguments
  • service - The service identifier
  • metadata - Optional metadata to send with the request
§Errors

Returns an error if:

  • The session is not ready
  • The request limit has been reached
  • The peer rejects the request
  • The request times out
Source

pub async fn process_message(&mut self) -> Result<Option<ControlEvent>, Error>

Processes the next incoming control message.

This should be called in a loop to handle incoming messages from the peer. Returns None when the control stream closes.

§Errors

Returns an error if reading from the control stream fails.

Source

pub async fn accept_open( &mut self, request_id: u64, logical_stream_id: u64, ) -> Result<(), Error>

Sends an OpenResponse accepting a stream request.

§Errors

Returns an error if sending the response fails.

Source

pub async fn reject_open( &mut self, request_id: u64, code: RejectCode, reason: Option<String>, ) -> Result<(), Error>

Sends an OpenResponse rejecting a stream request.

§Errors

Returns an error if sending the response fails.

Source

pub async fn close_stream( &mut self, logical_stream_id: u64, code: CloseCode, reason: Option<String>, ) -> Result<(), Error>

Notifies the peer that a stream has been closed.

This should be called when the application finishes with a stream to inform the peer. The peer will receive a StreamClose event.

§Errors

Returns an error if the session is closed or sending the message fails.

Source

pub async fn ping(&mut self) -> Result<Duration, Error>

Sends a ping and waits for the pong response.

This can be used to check if the peer is still responsive and to measure round-trip latency. Returns the round-trip time on success.

§Errors

Returns Error::Timeout(TimeoutKind::Ping) if no pong is received within the configured ping_timeout.

Source

pub async fn close( &mut self, code: CloseCode, reason: Option<String>, ) -> Result<(), Error>

Closes the session.

Sends a StreamClose message with logical_stream_id 0 to indicate session close, and transitions to the Closing state.

§Errors

Returns an error if the session is already closed or sending the message fails.

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