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>
impl<C: Connection> SessionHandle<C>
Sourcepub fn negotiated_params(&self) -> Option<NegotiatedParams>
pub fn negotiated_params(&self) -> Option<NegotiatedParams>
Returns the negotiated parameters.
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Returns true if the connection was lost.
Sourcepub async fn open(
&mut self,
service: impl Into<ServiceId> + AsRef<str>,
metadata: Metadata,
) -> Result<(C::SendStream, C::RecvStream), Error>
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 identifiermetadata- 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
Sourcepub async fn process_message(&mut self) -> Result<Option<ControlEvent>, Error>
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.
Sourcepub async fn accept_open(
&mut self,
request_id: u64,
logical_stream_id: u64,
) -> Result<(), Error>
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.
Sourcepub async fn reject_open(
&mut self,
request_id: u64,
code: RejectCode,
reason: Option<String>,
) -> Result<(), Error>
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.
Sourcepub async fn close_stream(
&mut self,
logical_stream_id: u64,
code: CloseCode,
reason: Option<String>,
) -> Result<(), Error>
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.
Sourcepub async fn ping(&mut self) -> Result<Duration, Error>
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.
Sourcepub async fn close(
&mut self,
code: CloseCode,
reason: Option<String>,
) -> Result<(), Error>
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.