Skip to main content

FileTransfer

Struct FileTransfer 

Source
pub struct FileTransfer<'a> { /* private fields */ }
Expand description

File-transfer state machine driving a Session.

Implementations§

Source§

impl<'a> FileTransfer<'a>

Source

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

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn negotiated_compression(&self) -> Option<&Compression>

Compression mode negotiated during QUERY, if any.

Source

pub fn poll_outbound(&mut self) -> Option<Vec<u8>>

Drain bytes the caller should write to the wire (delegates to the underlying session).

Source

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.

Source

pub fn tick(&mut self, now: Instant)

Drive retransmit/timeout logic in the underlying session.

Source

pub fn response_timeout(&self) -> Duration

Per-attempt response timeout of the underlying session — used by adapters to bound inbound reads.

Source

pub fn poll(&mut self) -> Option<FileEvent>

Pull the next file-level event, processing whatever session events have accumulated. Returns None when there is nothing pending.

Trait Implementations§

Source§

impl<'a> Debug for FileTransfer<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for FileTransfer<'a>

§

impl<'a> RefUnwindSafe for FileTransfer<'a>

§

impl<'a> Send for FileTransfer<'a>

§

impl<'a> Sync for FileTransfer<'a>

§

impl<'a> Unpin for FileTransfer<'a>

§

impl<'a> UnsafeUnpin for FileTransfer<'a>

§

impl<'a> !UnwindSafe for FileTransfer<'a>

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.