diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2019-02-27 20:38:42 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2019-02-27 20:38:42 +0100 |
| commit | 0f73e5b00cb7e395e3ca455ababdce932df8f21f (patch) | |
| tree | 5aac9b978cd0389559e63e317dab6811faa3918e | |
| parent | 82e96ffd27f0a803a4ede5d0fe2953584c09ad1b (diff) | |
Implement Timeout Interval Option (RFC 2349, part 1)
| -rw-r--r-- | src/tftp.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/tftp.rs b/src/tftp.rs index b37b1b3..f2130c6 100644 --- a/src/tftp.rs +++ b/src/tftp.rs @@ -10,9 +10,11 @@ use std::collections::HashMap; use std::path::{Path,PathBuf}; use std::io; use std::io::prelude::*; +use std::time::Duration; pub struct TftpOptions { blksize: usize, + timeout: u8, } pub struct Tftp { @@ -22,6 +24,7 @@ pub struct Tftp { fn default_options() -> TftpOptions { TftpOptions { blksize: 512, + timeout: 3, } } @@ -114,13 +117,24 @@ impl Tftp { self.options.blksize = b; true } - _ => false, + _ => false + } + } + "timeout" => { + match val.parse() { + Ok(t) if t >= 1 => { + self.options.timeout = t; + true + } + _ => false } } _ => false } }); + sock.set_read_timeout(Some(Duration::from_secs(self.options.timeout as u64)))?; + self.ack_options(&sock, &options, ackwait)?; return Ok(()); |
