From 0f73e5b00cb7e395e3ca455ababdce932df8f21f Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Wed, 27 Feb 2019 20:38:42 +0100 Subject: Implement Timeout Interval Option (RFC 2349, part 1) --- src/tftp.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') 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(()); -- cgit v1.2.3