From 37a011424d9f19e1801b25460d7a2db95220948e Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 24 Mar 2019 16:43:22 +0100 Subject: Support utimeout option (non-standard) --- README | 1 + src/lib.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README b/README index 44d584b..3045fcd 100644 --- a/README +++ b/README @@ -12,6 +12,7 @@ Currently supported: Non-standard options: - blksize2: block size as a power of 2 +- utimeout: timeout in microseconds Use cargo to build the binaries (output dir is target/release/): diff --git a/src/lib.rs b/src/lib.rs index ec092a4..61e7059 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub enum Mode { #[derive(Clone, Copy)] pub struct TftpOptions { blksize: usize, - timeout: u8, + timeout: Duration, tsize: u64, } @@ -53,7 +53,7 @@ pub struct Tftp { fn default_options() -> TftpOptions { TftpOptions { blksize: 512, - timeout: 3, + timeout: Duration::from_secs(3), tsize: 0, } } @@ -333,7 +333,14 @@ impl Tftp { }, "timeout" => match val.parse() { Ok(t) if t >= 1 => { - self.options.timeout = t; + self.options.timeout = Duration::from_secs(t); + true + } + _ => false, + }, + "utimeout" => match val.parse() { + Ok(t) if t >= 1 => { + self.options.timeout = Duration::from_micros(t); true } _ => false, @@ -349,7 +356,7 @@ impl Tftp { } }); - sock.set_read_timeout(Some(Duration::from_secs(u64::from(self.options.timeout))))?; + sock.set_read_timeout(Some(self.options.timeout))?; Ok(()) } -- cgit v1.2.3