lower timeout

This commit is contained in:
Daniella 2023-10-04 13:20:45 +02:00
parent 637fdcae58
commit 2c61f1b9c9
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
3 changed files with 11 additions and 4 deletions

2
Cargo.lock generated
View file

@ -86,7 +86,7 @@ dependencies = [
[[package]]
name = "revpfw3"
version = "0.3.1"
version = "0.4.0"
dependencies = [
"enum-ordinalize",
"serial",

View file

@ -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(

View file

@ -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<T: SerialPort + 'static>(serial: T, print: bool) -> Self {
pub fn new_serial<T: SerialPort + 'static>(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::<T>()
.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")
})