summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2019-03-24 16:43:22 +0100
committerReiner Herrmann <reiner@reiner-h.de>2019-03-24 16:43:22 +0100
commit37a011424d9f19e1801b25460d7a2db95220948e (patch)
tree2ed5a901412c6c56b6ebdb36fc403557c15d381c
parentb35a7b90949e19afca22c8cf5699bdc112ae2f6a (diff)
Support utimeout option (non-standard)
-rw-r--r--README1
-rw-r--r--src/lib.rs15
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(())
}