Retry read if interrupted

https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read
This commit is contained in:
Rodolphe Breard 2019-09-17 17:43:11 +02:00
parent 681563934a
commit c08c5c0895

View file

@ -10,7 +10,7 @@ use crate::entry::Entry;
use crate::errors::Error; use crate::errors::Error;
use crate::input::FilterInput; use crate::input::FilterInput;
use std::default::Default; use std::default::Default;
use std::io::{self, Read}; use std::io::{self, ErrorKind, Read};
use std::str; use std::str;
const BUFFER_SIZE: usize = 4096; const BUFFER_SIZE: usize = 4096;
@ -40,7 +40,17 @@ impl FilterInput for StdIn {
force_read = false; force_read = false;
// Read stdin in self.buffer // Read stdin in self.buffer
self.buffer.copy_from_slice(&[0; BUFFER_SIZE]); self.buffer.copy_from_slice(&[0; BUFFER_SIZE]);
let len = self.stdin.read(&mut self.buffer)?; let len = match self.stdin.read(&mut self.buffer) {
Ok(n) => n,
Err(e) => match e.kind() {
ErrorKind::Interrupted => {
continue;
}
_ => {
return Err(e.into());
}
},
};
if len == 0 { if len == 0 {
continue; continue;
} }