Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created April 2, 2017 18:01
Show Gist options
  • Save alexcrichton/aad9eeace869c1b04daafc734ff624b8 to your computer and use it in GitHub Desktop.
Save alexcrichton/aad9eeace869c1b04daafc734ff624b8 to your computer and use it in GitHub Desktop.
extern crate libc;
extern crate mio;
use std::os::unix::prelude::*;
use std::io;
use mio::*;
use mio::event::*;
use mio::unix::*;
fn main() {
let p = Poll::new().unwrap();
let mut a = [6, 7];
let n = unsafe {
libc::pipe(a.as_mut_ptr())
};
println!("pipe([{}, {}]) = {}", a[0], a[1], n);
unsafe {
println!("close({}) = {}", a[0], libc::close(a[0]));
println!("write({}, ...) = {} {}",
a[1],
libc::write(a[1],
b"foo".as_ptr() as *const _,
3),
io::Error::last_os_error());
}
// p.register(&EventedFd(&a[0]), mio::Token(1),
// Ready::readable() | Ready::writable(),
// PollOpt::edge()).unwrap();
// unsafe {
// libc::close(a[0]);
// }
std::thread::sleep(std::time::Duration::from_millis(50));
p.register(&EventedFd(&a[1]),
mio::Token(2),
Ready::writable() |
Ready::readable() |
UnixReady::hup(),
PollOpt::edge()).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment