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_nsbefore dispatch; returnsDeadlineExceededif expired.
§Thread Safety
Session is Send + Sync and can be shared via Arc<Session<T>>.
Implementations§
Source§impl Session
impl Session
Sourcepub async fn send_frame(&self, frame: Frame) -> Result<(), RpcError>
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.
Sourcepub async fn recv_frame(&self) -> Result<Frame, TransportError>
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.
Sourcepub fn is_deadline_exceeded(&self, desc: &MsgDescHot) -> bool
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.
Sourcepub fn grant_credits(&self, channel_id: u32, bytes: u32)
pub fn grant_credits(&self, channel_id: u32, bytes: u32)
Grant credits to a channel (called when receiving CREDITS control frame).
Sourcepub fn cancel_channel(&self, channel_id: u32)
pub fn cancel_channel(&self, channel_id: u32)
Mark a channel as cancelled.
Sourcepub fn is_cancelled(&self, channel_id: u32) -> bool
pub fn is_cancelled(&self, channel_id: u32) -> bool
Check if a channel is cancelled.
Sourcepub fn get_credits(&self, channel_id: u32) -> u32
pub fn get_credits(&self, channel_id: u32) -> u32
Get available send credits for a channel.
Sourcepub fn get_lifecycle(&self, channel_id: u32) -> ChannelLifecycle
pub fn get_lifecycle(&self, channel_id: u32) -> ChannelLifecycle
Get the lifecycle state of a channel.
Sourcepub fn get_channel_state(&self, channel_id: u32) -> ChannelState
pub fn get_channel_state(&self, channel_id: u32) -> ChannelState
Get a snapshot of the channel state.
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more