diff options
Diffstat (limited to 'third_party/rust/mio/test/test_broken_pipe.rs')
-rw-r--r-- | third_party/rust/mio/test/test_broken_pipe.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/third_party/rust/mio/test/test_broken_pipe.rs b/third_party/rust/mio/test/test_broken_pipe.rs new file mode 100644 index 0000000000..1cd0ca7465 --- /dev/null +++ b/third_party/rust/mio/test/test_broken_pipe.rs @@ -0,0 +1,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(); +} |