Skip to content

Commit 983532a

Browse files
authored
Fix stdio try_read() behavior. Closes #473. (#475)
1 parent 18ea998 commit 983532a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libs/stdio/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,14 @@ impl<'a> StdioReadGuard<'a> {
251251
let mut locked_ring_buf = self.guard.lock();
252252

253253
// Keep reading if we have empty space in the output buffer
254-
// and available byte in the ring buffer.
255-
while let (Some(buf_elem), Some(queue_elem)) = (buf_iter.next(), locked_ring_buf.queue.pop_front()) {
256-
*buf_elem = queue_elem;
257-
cnt += 1;
254+
// and available byte(s) in the ring buffer.
255+
while let Some(buf_entry) = buf_iter.next() {
256+
if let Some(queue_elem) = locked_ring_buf.queue.pop_front() {
257+
*buf_entry = queue_elem;
258+
cnt += 1;
259+
} else {
260+
break;
261+
}
258262
}
259263

260264
return Ok(cnt);

0 commit comments

Comments
 (0)