2016-12-15 08:47:31 +00:00
|
|
|
use std::io;
|
|
|
|
|
|
|
|
pub trait ReadExt: io::Read {
|
|
|
|
fn read_max(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
|
|
|
|
let start_len = buf.len();
|
|
|
|
while !buf.is_empty() {
|
|
|
|
match self.read(buf) {
|
|
|
|
Ok(0) => break,
|
|
|
|
Ok(n) => { let tmp = buf; buf = &mut tmp[n..]; }
|
|
|
|
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 17:18:30 +00:00
|
|
|
Ok(start_len - buf.len())
|
2016-12-15 08:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: io::Read> ReadExt for T { }
|