From 2c61f1b9c9bcc627e3c859843ec97ac74168eaeb Mon Sep 17 00:00:00 2001 From: TudbuT Date: Wed, 4 Oct 2023 13:20:45 +0200 Subject: [PATCH] lower timeout --- Cargo.lock | 2 +- src/client.rs | 2 +- src/connection.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ff9e09..0d68c6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,7 +86,7 @@ dependencies = [ [[package]] name = "revpfw3" -version = "0.3.1" +version = "0.4.0" dependencies = [ "enum-ordinalize", "serial", diff --git a/src/client.rs b/src/client.rs index 6637dfc..6e29870 100644 --- a/src/client.rs +++ b/src/client.rs @@ -67,7 +67,7 @@ fn connect(params: &ClientParams) -> Connection { ); } } - serial.set_timeout(Duration::from_millis(600000)).unwrap(); + serial.set_timeout(Duration::from_millis(20000)).unwrap(); return Connection::new_serial(serial, true); } Connection::new_tcp( diff --git a/src/connection.rs b/src/connection.rs index 84b007e..775a21c 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -75,6 +75,12 @@ impl Read for Connection { impl Connection { pub fn new_tcp(stream: TcpStream, print: bool) -> Self { + stream + .set_read_timeout(Some(Duration::from_secs(20))) + .unwrap(); + stream + .set_write_timeout(Some(Duration::from_secs(20))) + .unwrap(); let mut stream = Box::new(stream); Connection { data: NonNull::from(stream.as_mut()).cast(), @@ -99,7 +105,8 @@ impl Connection { }, } } - pub fn new_serial(serial: T, print: bool) -> Self { + pub fn new_serial(mut serial: T, print: bool) -> Self { + serial.set_timeout(Duration::from_secs(20)).unwrap(); let mut serial = Box::new(serial); Connection { data: NonNull::from(serial.as_mut()).cast(), @@ -107,7 +114,7 @@ impl Connection { set_nonblocking_thunk: |data, nb| unsafe { data.cast::() .as_mut() - .set_timeout(Duration::from_millis(if nb { 0 } else { 600000 })) + .set_timeout(Duration::from_secs(if nb { 0 } else { 20 })) .map_err(|_| { io::Error::new(io::ErrorKind::ConnectionAborted, "serial port went down") })