Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(io): handle missing source in stdin #534

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions glommio/src/io/buffered_file_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,12 @@ impl AsyncBufRead for Stdin {
) -> Poll<io::Result<&'a [u8]>> {
match self.source.take() {
Some(source) => {
let res = source.result().unwrap();
let res = match source.result() {
Some(res) => res,
None => {
return Poll::Pending;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the correct fix, but it does fix both the test case and when using stdin in my program to read from it

}
};
match res {
Err(x) => Poll::Ready(Err(x)),
Ok(sz) => {
Expand Down Expand Up @@ -691,9 +696,9 @@ impl AsyncBufRead for Stdin {
#[cfg(test)]
mod test {
use super::*;
use crate::test_utils::make_test_directories;
use crate::{test_utils::make_test_directories, GlommioError};
use futures_lite::{AsyncBufReadExt, AsyncReadExt, AsyncSeekExt, AsyncWriteExt, StreamExt};
use std::io::ErrorKind;
use std::{io::ErrorKind, time::Duration};

macro_rules! read_test {
( $name:ident, $dir:ident, $kind:ident, $file:ident, $file_size:ident: $size:tt, $code:block) => {
Expand Down Expand Up @@ -982,4 +987,19 @@ mod test {
reader.close().await.unwrap();
writer.close().await.unwrap();
});

#[test]
fn test_stdin_fuse() {
use futures::StreamExt;

test_executor!(async move {
let mut si = StreamExt::fuse(stdin().lines());
let fut = crate::timer::timeout(Duration::from_millis(5), async move {
si.select_next_some()
.await
.map_err(|err| GlommioError::IoError(err))
});
assert!(matches!(fut.await, Err(GlommioError::TimedOut(_))));
});
}
}