Skip to content

Commit

Permalink
core: ByteStream::read_buf should be a best-effort read.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeljanov committed Apr 19, 2020
1 parent 2d8ba46 commit c6bad6a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sonata-core/src/io/media_source_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,27 @@ impl ByteStream for MediaSourceStream {

#[inline(always)]
fn read_buf(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.read(buf)
let mut rem = buf;
let mut read = 0;

while !rem.is_empty() {
match self.read(rem) {
Ok(0) => break,
Ok(n) => {
rem = &mut rem[n..];
read += n;
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}

if read == 0 {
Err(io::Error::new(io::ErrorKind::UnexpectedEof, "Reached end of stream."))
}
else {
Ok(read)
}
}

#[inline(always)]
Expand Down

0 comments on commit c6bad6a

Please sign in to comment.