Skip to content

Commit

Permalink
win: Perform zero read size check only when timeout zero
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Jun 28, 2022
1 parent 656ed51 commit 69529a7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/windows/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,17 @@ impl io::Read for COMPort {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
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
//Note that zero timeout will make read operation to wait until at least
//1 byte becomes available.
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()?;
Expand Down

0 comments on commit 69529a7

Please sign in to comment.