pub struct FileTransfer<'a> { /* private fields */ }Expand description
File-transfer state machine driving a Session.
Implementations§
Source§impl<'a> FileTransfer<'a>
impl<'a> FileTransfer<'a>
Sourcepub fn new(session: &'a mut Session) -> Self
pub fn new(session: &'a mut Session) -> Self
Build a new file-transfer driver borrowing the given session.
The session must already have completed the SYNC handshake
(session.is_synced() == true).
Sourcepub fn query(&mut self, compression: Compression, now: Instant)
pub fn query(&mut self, compression: Compression, now: Instant)
Issue the QUERY control packet. Caller must specify what
compression mode they want — the actual negotiated mode is
reported back via FileEvent::Negotiated.
§Panics
Panics unless the state is Idle (i.e. this is a fresh
transfer). Programmer error; callers must construct a new
FileTransfer for retries after a Failed / Closed /
Aborted outcome.
Sourcepub fn open(&mut self, name: &str, dummy: bool, now: Instant)
pub fn open(&mut self, name: &str, dummy: bool, now: Instant)
Send the OPEN packet. name is the destination filename on the
SD card. dummy requests the device pretend to receive a file
without actually writing it (used for protocol smoke tests).
§Panics
Panics unless QUERY has completed (Negotiated state). Without
QUERY, the compression byte in the OPEN payload would be a
guess.
Sourcepub fn write(&mut self, chunk: &[u8], now: Instant)
pub fn write(&mut self, chunk: &[u8], now: Instant)
Send a WRITE packet with the given chunk. The caller is
responsible for splitting the source data so each chunk fits
inside the device’s max_block_size (and, if compression is in
use, for compressing each chunk before passing it here).
§Panics
Panics unless the file is open and no WRITE is in flight (state
Opened). Callers must pump until FileEvent::WriteAcked
before issuing the next write. This mirrors
the Python reference’s one-packet-in-flight policy and keeps
the state machine unambiguous — pipelining is out of scope for
0.1.
Sourcepub fn close(&mut self, now: Instant)
pub fn close(&mut self, now: Instant)
Send the CLOSE packet, finalising the transfer.
§Panics
Panics unless the file is open and no WRITE is in flight
(state Opened).
Sourcepub fn abort(&mut self, now: Instant)
pub fn abort(&mut self, now: Instant)
Send the ABORT packet, cancelling the transfer.
§Panics
Panics unless the file is open and no WRITE is in flight
(state Opened). Aborting before OPEN completes makes no
protocol sense — there’s nothing for the device to abort.
Sourcepub fn negotiated_compression(&self) -> Option<&Compression>
pub fn negotiated_compression(&self) -> Option<&Compression>
Compression mode negotiated during QUERY, if any.
Sourcepub fn poll_outbound(&mut self) -> Option<Vec<u8>>
pub fn poll_outbound(&mut self) -> Option<Vec<u8>>
Drain bytes the caller should write to the wire (delegates to the underlying session).
Sourcepub fn feed(&mut self, bytes: &[u8], now: Instant)
pub fn feed(&mut self, bytes: &[u8], now: Instant)
Push received bytes into the underlying session.
now is forwarded into Session::feed
so any packet dispatched as a side effect of an inbound ack gets
a real timestamp.
Sourcepub fn response_timeout(&self) -> Duration
pub fn response_timeout(&self) -> Duration
Per-attempt response timeout of the underlying session — used by adapters to bound inbound reads.