I am a Rust beginner struggling with a problem of async IO. I've decided to use mio.
I've read some source code + tutorials but there is still some fundamental part that I do not understand. I am setting up a server with netcat -k -l 127.0.0.1 9999
. Then I am running simple test with cargo
(code below). I was expecting to see panic with "ready" or "tick". But it never happens and test is running forever.
extern crate mio;
use mio::*;
#[allow(unused_imports)]
use mio::tcp::TcpStream;
#[allow(dead_code)]
struct MyHandler;
impl Handler for MyHandler {
type Timeout = ();
type Message = ();
fn ready(&mut self, _event_loop: &mut EventLoop<Self>, _token: Token, _event_set: EventSet) {
panic!("ready");
}
fn tick(&mut self, _event_loop: &mut EventLoop<Self>) {
panic!("tick");
}
}
#[test]
fn mio_test1() {
let addr = "127.0.0.1:9999".parse().unwrap();
let mut event_loop = EventLoop::<MyHandler>::new().unwrap();
event_loop.register(&TcpStream::connect(&addr).unwrap(), Token(0), EventSet::readable(), PollOpt::level()).unwrap();
event_loop.run(&mut MyHandler).unwrap();
}