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
impl Stack
Sourcepub fn new(own_eid: Eid, mtu: usize, now_millis: u64) -> Self
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).
Sourcepub fn update(&mut self, now_millis: u64) -> Result<(u64, bool)>
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.
Sourcepub 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>
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.
Sourcepub fn receive(
&mut self,
packet: &[u8],
) -> Result<Option<(MctpMessage<'_>, ReceiveHandle)>>
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
.
Sourcepub fn fetch_message_with<F>(&mut self, handle: ReceiveHandle, f: F)where
F: FnOnce(MctpMessage<'_>),
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.
Sourcepub fn fetch_message(&mut self, handle: &ReceiveHandle) -> MctpMessage<'_>
pub fn fetch_message(&mut self, handle: &ReceiveHandle) -> MctpMessage<'_>
Provides a message previously returned from receive
Sourcepub fn finished_receive(&mut self, handle: ReceiveHandle)
pub fn finished_receive(&mut self, handle: ReceiveHandle)
Returns a handle to the Stack
and complete the message
Sourcepub fn return_handle(&mut self, handle: ReceiveHandle)
pub fn return_handle(&mut self, handle: ReceiveHandle)
Returns a handle to the Stack
, the message will be kept (until timeouts)
Sourcepub fn get_deferred(&mut self, source: Eid, tag: Tag) -> Option<ReceiveHandle>
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.
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.