Skip to content

Commit e7d423a

Browse files
committed
Retry on EINTR in Bytes and Chars.
Since Bytes and Chars called directly into Read::read, they didn't use any of the retrying wrappers. This allows both iterator types to retry.
1 parent b522b25 commit e7d423a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/libstd/io/mod.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,18 @@ impl<T: BufRead> BufRead for Take<T> {
15221522
}
15231523
}
15241524

1525+
fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> {
1526+
let mut buf = [0];
1527+
loop {
1528+
return match reader.read(&mut buf) {
1529+
Ok(0) => None,
1530+
Ok(..) => Some(Ok(buf[0])),
1531+
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
1532+
Err(e) => Some(Err(e)),
1533+
};
1534+
}
1535+
}
1536+
15251537
/// An iterator over `u8` values of a reader.
15261538
///
15271539
/// This struct is generally created by calling [`bytes()`][bytes] on a reader.
@@ -1538,12 +1550,7 @@ impl<R: Read> Iterator for Bytes<R> {
15381550
type Item = Result<u8>;
15391551

15401552
fn next(&mut self) -> Option<Result<u8>> {
1541-
let mut buf = [0];
1542-
match self.inner.read(&mut buf) {
1543-
Ok(0) => None,
1544-
Ok(..) => Some(Ok(buf[0])),
1545-
Err(e) => Some(Err(e)),
1546-
}
1553+
read_one_byte(&mut self.inner)
15471554
}
15481555
}
15491556

@@ -1579,11 +1586,10 @@ impl<R: Read> Iterator for Chars<R> {
15791586
type Item = result::Result<char, CharsError>;
15801587

15811588
fn next(&mut self) -> Option<result::Result<char, CharsError>> {
1582-
let mut buf = [0];
1583-
let first_byte = match self.inner.read(&mut buf) {
1584-
Ok(0) => return None,
1585-
Ok(..) => buf[0],
1586-
Err(e) => return Some(Err(CharsError::Other(e))),
1589+
let first_byte = match read_one_byte(&mut self.inner) {
1590+
None => return None,
1591+
Some(Ok(b)) => b,
1592+
Some(Err(e)) => return Some(Err(CharsError::Other(e))),
15871593
};
15881594
let width = core_str::utf8_char_width(first_byte);
15891595
if width == 1 { return Some(Ok(first_byte as char)) }
@@ -1595,6 +1601,7 @@ impl<R: Read> Iterator for Chars<R> {
15951601
match self.inner.read(&mut buf[start..width]) {
15961602
Ok(0) => return Some(Err(CharsError::NotUtf8)),
15971603
Ok(n) => start += n,
1604+
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
15981605
Err(e) => return Some(Err(CharsError::Other(e))),
15991606
}
16001607
}

0 commit comments

Comments
 (0)