Skip to content

Commit

Permalink
Merge pull request #2 from kamalmarhubi/retry-interrupted
Browse files Browse the repository at this point in the history
mio: Retry poll if interrupted
  • Loading branch information
alexcrichton authored Jun 14, 2016
2 parents 113646f + 4bc1ec3 commit 71e40c0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions mio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate mio;
extern crate futures;

use std::collections::HashMap;
use std::io::{self, Read, Write};
use std::io::{self, ErrorKind, Read, Write};
use std::net::SocketAddr;
use std::panic;
use std::slice;
Expand Down Expand Up @@ -231,7 +231,20 @@ impl Loop {

fn _await(&mut self, done: &mut FnMut() -> bool) {
while !done() {
let amt = self.io.poll(None).unwrap();
let amt;
// On Linux, Poll::poll is epoll_wait, which may return EINTR if a
// ptracer attaches. This retry loop prevents crashing when
// attaching strace, or similar.
loop {
match self.io.poll(None) {
Ok(a) => {
amt = a;
break;
}
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
err@Err(_) => { err.unwrap(); },
}
}

for i in 0..amt {
let event = self.io.events().get(i).unwrap();
Expand Down

0 comments on commit 71e40c0

Please sign in to comment.