diff --git a/rust/trezor-client/src/transport/udp.rs b/rust/trezor-client/src/transport/udp.rs index ae2b073e00..2631221b9c 100644 --- a/rust/trezor-client/src/transport/udp.rs +++ b/rust/trezor-client/src/transport/udp.rs @@ -19,8 +19,8 @@ use constants::{DEFAULT_DEBUG_PORT, DEFAULT_HOST, DEFAULT_PORT, LOCAL_LISTENER}; /// The chunk size for the serial protocol. const CHUNK_SIZE: usize = 64; -const READ_TIMEOUT_MS: u64 = 0; -const WRITE_TIMEOUT_MS: u64 = 1000; +const READ_TIMEOUT: Option = None; +const WRITE_TIMEOUT: Option = Some(Duration::from_secs(1)); /// An available transport for connecting with a device. #[derive(Debug)] @@ -45,8 +45,7 @@ struct UdpLink { impl Link for UdpLink { fn write_chunk(&mut self, chunk: Vec) -> Result<(), Error> { debug_assert_eq!(CHUNK_SIZE, chunk.len()); - let timeout = Duration::from_millis(WRITE_TIMEOUT_MS); - self.socket.set_write_timeout(Some(timeout))?; + self.socket.set_write_timeout(WRITE_TIMEOUT)?; if let Err(e) = self.socket.send(&chunk) { return Err(e.into()); } @@ -55,8 +54,7 @@ impl Link for UdpLink { fn read_chunk(&mut self) -> Result, Error> { let mut chunk = vec![0; CHUNK_SIZE]; - let timeout = Duration::from_millis(READ_TIMEOUT_MS); - self.socket.set_read_timeout(Some(timeout))?; + self.socket.set_read_timeout(READ_TIMEOUT)?; let n = self.socket.recv(&mut chunk)?; if n == CHUNK_SIZE { diff --git a/rust/trezor-client/src/transport/webusb.rs b/rust/trezor-client/src/transport/webusb.rs index 1fe3739fbe..36a158f8d0 100644 --- a/rust/trezor-client/src/transport/webusb.rs +++ b/rust/trezor-client/src/transport/webusb.rs @@ -26,8 +26,8 @@ mod constants { /// The chunk size for the serial protocol. const CHUNK_SIZE: usize = 64; -const READ_TIMEOUT_MS: u64 = 0; -const WRITE_TIMEOUT_MS: u64 = 1000; +const READ_TIMEOUT: Duration = Duration::from_secs(0); +const WRITE_TIMEOUT: Duration = Duration::from_secs(1); /// An available transport for connecting with a device. #[derive(Debug)] @@ -51,8 +51,7 @@ pub struct WebUsbLink { impl Link for WebUsbLink { fn write_chunk(&mut self, chunk: Vec) -> Result<(), Error> { debug_assert_eq!(CHUNK_SIZE, chunk.len()); - let timeout = Duration::from_millis(WRITE_TIMEOUT_MS); - if let Err(e) = self.handle.write_interrupt(self.endpoint, &chunk, timeout) { + if let Err(e) = self.handle.write_interrupt(self.endpoint, &chunk, WRITE_TIMEOUT) { return Err(e.into()); } Ok(()) @@ -61,9 +60,8 @@ impl Link for WebUsbLink { fn read_chunk(&mut self) -> Result, Error> { let mut chunk = vec![0; CHUNK_SIZE]; let endpoint = constants::READ_ENDPOINT_MASK | self.endpoint; - let timeout = Duration::from_millis(READ_TIMEOUT_MS); - let n = self.handle.read_interrupt(endpoint, &mut chunk, timeout)?; + let n = self.handle.read_interrupt(endpoint, &mut chunk, READ_TIMEOUT)?; if n == CHUNK_SIZE { Ok(chunk) } else {