Skip to main content

Session

Struct Session 

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

Session wraps a Transport and enforces RPC semantics.

§Responsibilities

  • Credits: Tracks per-channel send credits. Data frames require sufficient credits; control channel (0) is exempt.
  • Cancellation: Tracks cancelled channels and drops frames for them.
  • Deadlines: Checks deadline_ns before dispatch; returns DeadlineExceeded if expired.

§Thread Safety

Session is Send + Sync and can be shared via Arc<Session<T>>.

Implementations§

Source§

impl Session

Source

pub fn new(transport: Transport) -> Self

Create a new session wrapping the given transport.

Source

pub fn transport(&self) -> &Transport

Get a reference to the underlying transport.

Source

pub async fn send_frame(&self, frame: Frame) -> Result<(), RpcError>

Send a frame, enforcing credit limits and channel state for data channels.

  • Control channel (0) is exempt from credit checks.
  • Data channels require payload_len <= available_credits.
  • Tracks EOS to transition channel state.
  • Returns RpcError::Status { code: ResourceExhausted } if insufficient credits.
Source

pub async fn recv_frame(&self) -> Result<Frame, TransportError>

Receive a frame, processing control frames and filtering cancelled/closed channels.

  • Processes CANCEL control frames to mark channels as cancelled.
  • Processes CREDITS control frames to update send credits.
  • Tracks EOS to transition channel state.
  • Drops data frames for cancelled/closed channels.
  • Returns frames that should be dispatched.
Source

pub fn is_deadline_exceeded(&self, desc: &MsgDescHot) -> bool

Check if a frame’s deadline has expired.

Returns true if the frame has a deadline and it has passed.

Source

pub fn grant_credits(&self, channel_id: u32, bytes: u32)

Grant credits to a channel (called when receiving CREDITS control frame).

Source

pub fn cancel_channel(&self, channel_id: u32)

Mark a channel as cancelled.

Source

pub fn is_cancelled(&self, channel_id: u32) -> bool

Check if a channel is cancelled.

Source

pub fn get_credits(&self, channel_id: u32) -> u32

Get available send credits for a channel.

Source

pub fn get_lifecycle(&self, channel_id: u32) -> ChannelLifecycle

Get the lifecycle state of a channel.

Source

pub fn get_channel_state(&self, channel_id: u32) -> ChannelState

Get a snapshot of the channel state.

Source

pub fn is_closed(&self, channel_id: u32) -> bool

Check if a channel is fully closed.

Source

pub fn close(&self)

Close the 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> 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> TimeoutExt for T

Source§

fn timeout(self, duration: Duration) -> Timeout<Self> ⓘ

Requires a Future or Stream to complete before the specific duration has elapsed. 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