Skip to content

Commit

Permalink
Fix stdio try_read() behavior. Closes #473. (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinaboos authored Dec 17, 2021
1 parent 18ea998 commit 983532a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libs/stdio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,14 @@ impl<'a> StdioReadGuard<'a> {
let mut locked_ring_buf = self.guard.lock();

// Keep reading if we have empty space in the output buffer
// and available byte in the ring buffer.
while let (Some(buf_elem), Some(queue_elem)) = (buf_iter.next(), locked_ring_buf.queue.pop_front()) {
*buf_elem = queue_elem;
cnt += 1;
// and available byte(s) in the ring buffer.
while let Some(buf_entry) = buf_iter.next() {
if let Some(queue_elem) = locked_ring_buf.queue.pop_front() {
*buf_entry = queue_elem;
cnt += 1;
} else {
break;
}
}

return Ok(cnt);
Expand Down

0 comments on commit 983532a

Please sign in to comment.