summaryrefslogtreecommitdiffstats
path: root/third_party/rust/mio/test/test_broken_pipe.rs
blob: 1cd0ca7465d10912fd1fd04597323cda60cb8933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use mio::{Token, Ready, PollOpt};
use mio::deprecated::{unix, EventLoop, Handler};
use std::time::Duration;

pub struct BrokenPipeHandler;

impl Handler for BrokenPipeHandler {
    type Timeout = ();
    type Message = ();
    fn ready(&mut self, _: &mut EventLoop<Self>, token: Token, _: Ready) {
        if token == Token(1) {
            panic!("Received ready() on a closed pipe.");
        }
    }
}

#[test]
pub fn broken_pipe() {
    let mut event_loop: EventLoop<BrokenPipeHandler> = EventLoop::new().unwrap();
    let (reader, _) = unix::pipe().unwrap();

    event_loop.register(&reader, Token(1), Ready::all(), PollOpt::edge())
              .unwrap();

    let mut handler = BrokenPipeHandler;
    drop(reader);
    event_loop.run_once(&mut handler, Some(Duration::from_millis(1000))).unwrap();
}