Fix stdio `try_read()` behavior. Closes
@@ -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;
+ // 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);
