pub struct Session { /* private fields */ }Expand description
Sans-I/O session driver.
Implementations§
Source§impl Session
impl Session
Sourcepub fn with_response_timeout(self, timeout: Duration) -> Self
pub fn with_response_timeout(self, timeout: Duration) -> Self
Set the per-attempt response timeout. Retransmits fire after this long without an ack.
Sourcepub fn with_total_timeout(self, timeout: Duration) -> Self
pub fn with_total_timeout(self, timeout: Duration) -> Self
Set the total budget for a single packet across all retransmits.
When this elapses, the packet is dropped and Event::Timeout is
emitted.
Sourcepub fn response_timeout(&self) -> Duration
pub fn response_timeout(&self) -> Duration
Current per-attempt response timeout. Adapters wrap their inbound
reads in this so Self::tick can fire even when the transport
stays idle.
Sourcepub fn total_timeout(&self) -> Duration
pub fn total_timeout(&self) -> Duration
Current total per-packet budget across all retransmits.
Sourcepub fn max_block_size(&self) -> Option<u16>
pub fn max_block_size(&self) -> Option<u16>
Device-advertised maximum payload bytes per packet, set during the SYNC handshake.
Sourcepub fn protocol_version(&self) -> Option<&str>
pub fn protocol_version(&self) -> Option<&str>
Device-advertised protocol version, set during the SYNC handshake.
Sourcepub fn current_sync(&self) -> u8
pub fn current_sync(&self) -> u8
Current sync counter value. Diagnostic accessor used in tests; not load-bearing for protocol clients.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
True if a packet is currently in flight (sent, awaiting ack).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the session to its construction baseline.
Drops any in-flight packet, queued packets, pending outbound
bytes, pending events, and inbound buffer; clears the sync
counter, sync state, and device-advertised values. Timeouts
(response_timeout / total_timeout) are preserved.
Use this after observing Event::OutOfSync before calling
connect again: the BFT protocol has no
way to resynchronise mid-stream, so the only recovery path is
to clear local state and redo the handshake from scratch.
Sourcepub fn connect(&mut self, now: Instant)
pub fn connect(&mut self, now: Instant)
Queue the SYNC control packet (protocol=0, packet_type=1).
The caller should already have written the ASCII trigger
b"M28B1\n" before calling this.
Sourcepub fn send(
&mut self,
protocol: u8,
packet_type: u8,
payload: &[u8],
now: Instant,
)
pub fn send( &mut self, protocol: u8, packet_type: u8, payload: &[u8], now: Instant, )
Queue a binary packet for transmission.
If the session is idle (no packet in flight), the bytes are pushed to the outbound queue immediately. Otherwise the packet waits until the in-flight packet is acked.
§Panics
Panics if:
- the session has not yet observed an
sshandshake reply (is_synced() == false) — without a device-confirmed sync counter, the packet would go out withsync=0and almost certainly desynchronise the protocol; protocol > 15,packet_type > 15, or the payload is longer thancodec::MAX_PAYLOAD.
All of the above are programmer errors; production callers should
drive connect to completion, observe
Event::Synced, and clamp payload size to
max_block_size.
Sourcepub fn poll_outbound(&mut self) -> Option<Vec<u8>>
pub fn poll_outbound(&mut self) -> Option<Vec<u8>>
Drain a single chunk of bytes the caller should write to the wire.
Returns None when no more bytes are pending.
Sourcepub fn feed(&mut self, bytes: &[u8], now: Instant)
pub fn feed(&mut self, bytes: &[u8], now: Instant)
Push received bytes from the wire. Bytes are accumulated until a
newline-terminated ASCII line is recognised, at which point an
Event is queued for poll_event.
now is used to timestamp any queued packet that gets dispatched
as a side effect of an inbound ack — fully sans-I/O, no internal
wall-clock reads.
Sourcepub fn poll_event(&mut self) -> Option<Event>
pub fn poll_event(&mut self) -> Option<Event>
Drain the next queued event. Returns None when the queue is empty.