Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created September 13, 2018 16:59
Show Gist options
  • Select an option

  • Save ryochack/2d7e56200c8454dcf3723986c8dd22e6 to your computer and use it in GitHub Desktop.

Select an option

Save ryochack/2d7e56200c8454dcf3723986c8dd22e6 to your computer and use it in GitHub Desktop.
extern crate mio;
use mio::unix::EventedFd;
use mio::{Token, PollOpt, Ready, Poll, Events};
use std::io::ErrorKind;
use std::time::Duration;
fn main() {
const IN: Token = Token(0);
let fd0_e = EventedFd(&0);
let poll = Poll::new().unwrap();
poll.register(&fd0_e, IN, Ready::readable(),
PollOpt::edge()).unwrap();
let mut events = Events::with_capacity(1024);
'outer: loop {
let ret = poll.poll(&mut events, Some(Duration::from_secs(5)));
if let Err(x) = ret {
eprintln!("Boo");
if x.kind() == ErrorKind::Interrupted { continue; }
break;
}
if events.is_empty() {
println!("_____TMO_____");
}
for event in events.iter() {
match event.token() {
IN => println!("_____IN_____"),
_ => unreachable!(),
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment