Struct Stack

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

Low level MCTP stack.

This is an IO-less MCTP stack, independent of any particular transport.

Implementations§

Source§

impl Stack

Source

pub fn new(own_eid: Eid, mtu: usize, now_millis: u64) -> Self

Create a new Stack.

own_eid is the EID for this stack. It may be 0 (MCTP_ADDR_NULL).

now_millis is the current timestamp, the same style as would be passed to update_clock().

mtu is the default MTU of the stack. Specific start_send() calls may use a smaller MTU if needed (for example a per-link or per-EID MTU). new() will panic if a MTU smaller than 5 is given (minimum MCTP header and type byte).

Source

pub fn update(&mut self, now_millis: u64) -> Result<(u64, bool)>

Updates timeouts and returns the next timeout in milliseconds

Must be called regularly to update the current clock value. Returns Error::InvalidInput if time goes backwards.

Returns (next_timeout, any_expired). next_timeout is a suitable interval (milliseconds) for the next call to update(), currently a maximum of 100 ms.

any_expired is set true if any message receive timeouts expired with this call.

Source

pub fn start_send( &mut self, dest: Eid, typ: MsgType, tag: Option<Tag>, tag_expires: bool, ic: MsgIC, mtu: Option<usize>, cookie: Option<AppCookie>, ) -> Result<Fragmenter>

Initiates a MCTP message send.

Returns a Fragmenter that will packetize the message.

mtu is an optional override, will be the min of the stack MTU and the argument.

The provided cookie will be returned when send_fill() completes.

When sending a with tag.is_owner() == true, the cookie will be stored with the flow, and the reply MctpMessage cookie field will be set.

Source

pub fn receive( &mut self, packet: &[u8], ) -> Result<Option<(MctpMessage<'_>, ReceiveHandle)>>

Receive a packet.

Returns Ok(Some(_)) when a full message is reassembled. Returns Ok(None) on success when the message is incomplete. Callers must call finished_receive or fetch_message_with for any returned ReceiveHandle.

Source

pub fn fetch_message_with<F>(&mut self, handle: ReceiveHandle, f: F)
where F: FnOnce(MctpMessage<'_>),

Retrieves a MCTP message for a receive handle.

The message is provided to a closure. This allows using a closure that takes ownership of non-copyable objects.

Source

pub fn fetch_message(&mut self, handle: &ReceiveHandle) -> MctpMessage<'_>

Provides a message previously returned from receive

Source

pub fn finished_receive(&mut self, handle: ReceiveHandle)

Returns a handle to the Stack and complete the message

Source

pub fn return_handle(&mut self, handle: ReceiveHandle)

Returns a handle to the Stack, the message will be kept (until timeouts)

Source

pub fn get_deferred(&mut self, source: Eid, tag: Tag) -> Option<ReceiveHandle>

Retrieves a message deferred from a previous receive callback.

Messages are selected by (source_eid, tag). If multiple match the earliest is returned.

Messages are only available for DEFERRED_TIMEOUT, after that time they will be discarded and the message slot/tag may be reused.

Source

pub fn get_deferred_bycookie( &mut self, cookies: &[AppCookie], ) -> Option<ReceiveHandle>

Retrieves a message deferred from a previous receive callback.

If multiple match the earliest is returned. Multiple cookies to match may be provided.

Messages are only available for DEFERRED_TIMEOUT, after that time they will be discarded and the message slot may be reused.

Source

pub fn set_eid(&mut self, eid: u8) -> Result<()>

Sets the local Endpoint ID.

Source

pub fn eid(&self) -> Eid

Retrieves the local Endpoint ID.

Source

pub fn is_local_dest(&self, packet: &[u8]) -> bool

Source

pub fn cancel_flow(&mut self, source: Eid, tv: TagValue) -> Result<()>

Trait Implementations§

Source§

impl Debug for Stack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnwindSafe for Stack

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.