From e05c174a4b83a72b6284b77ba98aa6a6110fe182 Mon Sep 17 00:00:00 2001 From: Douman Date: Wed, 29 Jun 2022 02:05:06 +0900 Subject: [PATCH] win: Perform zero read size check only when timeout zero --- src/windows/com.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/windows/com.rs b/src/windows/com.rs index 616de47e..79273556 100644 --- a/src/windows/com.rs +++ b/src/windows/com.rs @@ -223,13 +223,15 @@ impl io::Read for COMPort { fn read(&mut self, buf: &mut [u8]) -> io::Result { let mut read_size = buf.len(); - let bytes_to_read = self.bytes_to_read()? as usize; - - if self.timeout.as_millis() == 0 && bytes_to_read < read_size { - read_size = bytes_to_read; - } - if read_size == 0 { - return Ok(0); + if self.timeout.as_secs() == 0 && self.timeout.subsec_nanos() == 0 { + //If zero timeout then make sure we can read, before proceeding + let bytes_to_read = self.bytes_to_read()? as usize; + if bytes_to_read < read_size { + read_size = bytes_to_read; + } + if read_size == 0 { + return Ok(0); + } } let evt_handle = OverlappedHandle::new()?;