Skip to main content

MasterSession

Struct MasterSession 

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

Owns the “awaiting response” slot(s) for a master. The master calls MasterSession::start when it sends a request, and MasterSession::stop when the response arrives or times out. MasterSession::handle_frame / MasterSession::handle_error are called by the master’s framing / framing_error subscription tasks.

Implementations§

Source§

impl MasterSession

Source

pub fn new() -> Self

Source

pub fn start( &self, key: WaiterKey, pre_check: Vec<PreCheck>, ) -> Receiver<Result<Framing, ModbusError>>

Arm a waiter under key. Returns a receiver that resolves with either the first matching Framing or a rejection reason.

If key already has a waiter (e.g. TID wrap collision), the previous waiter’s receiver is dropped — equivalent to the caller calling MasterSession::stop first.

Source

pub fn stop(&self, key: WaiterKey)

Drop the waiter under key without notifying it. Used on timeout, where the caller has already given up on the receiver.

Source

pub fn stop_all(&self, err: ModbusError)

Reject every armed waiter with err. Used by handle_error (framing errors lose transaction context) and on master close/destroy.

Source

pub fn has(&self, key: WaiterKey) -> bool

True if a waiter is currently armed under key.

Source

pub fn handle_frame(&self, frame: Framing)

Push a successfully framed PDU at the session. Looks up the waiter keyed by frame.adu.transaction (TCP) or WaiterKey::Fifo (RTU/ASCII). If found, removes it and runs the pre-checks; on the first failing check, rejects with the corresponding error. On all checks passing, resolves with the frame. No-op if no waiter matches.

Source

pub fn handle_error(&self, err: ModbusError)

Push a framing error at the session. Framing errors arrive without transaction context (CRC/LRC failure, bogus MBAP header, etc.), so every in-flight waiter is rejected.

Trait Implementations§

Source§

impl Default for MasterSession

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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