tftp_client/
lib.rs

1//! An implementation of the TFTP Client as specified in [RFC 1350](https://datatracker.ietf.org/doc/html/rfc1350)
2//! This includes retries and timeouts with exponential backoff
3
4use thiserror::Error;
5
6#[cfg(feature = "async")]
7pub mod asynchronous;
8mod blocking;
9pub mod parser;
10
11/// The blocking functions are the default
12pub use blocking::*;
13
14const BLKSIZE: usize = 512;
15
16enum State {
17    Send,
18    SendAgain,
19    Recv,
20}
21
22#[derive(Debug, Error)]
23pub enum Error {
24    #[error("Bad filename (not a valid CString)")]
25    BadFilename,
26    #[error("Socket IO error - `{0}`")]
27    SocketIo(std::io::Error),
28    #[error("Timeout while trying to complete transaction")]
29    Timeout,
30    #[error("Failed to parse incoming packet - `{0}`")]
31    Parse(parser::Error),
32    #[error("The packet we got back was unexpected")]
33    UnexpectedPacket(parser::Packet),
34    #[error("The protocol itself gave us an error with code `{code:?}`and msg `{msg}`")]
35    Protocol {
36        code: parser::ErrorCode,
37        msg: String,
38    },
39}