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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(missing_docs))] extern crate eventual; #[macro_use] extern crate log; extern crate mio; pub use eventual::Async; pub use tick::Tick; mod tick; mod tcp; enum Action { Wait, Register(mio::EventSet), Accept(Sender<Pair<Vec<u8>>>), Read(Option<Sender<Vec<u8>>>), Write(Option<(Vec<u8>, Stream<Vec<u8>>)>), Remove, } enum Message { Listener(tcp::Listener), Stream(tcp::Stream), Action(mio::Token, Action), Shutdown, } #[derive(Debug)] pub enum Error { TooManySockets, Io(::std::io::Error) } impl From<::std::io::Error> for Error { fn from(e: ::std::io::Error) -> Error { Error::Io(e) } } pub type Result<T> = std::result::Result<T, Error>; pub type Stream<T> = eventual::Stream<T, Error>; pub type Sender<T> = eventual::Sender<T, Error>; pub type Pair<T> = (Sender<T>, Stream<T>); pub type Future<T> = eventual::Future<T, Error>; #[derive(Clone)] struct Notify<T: Send_> { sender: T } impl<T: Send_> Notify<T> { fn send(&self, msg: Message) -> bool { self.sender.send(msg) } } trait Send_: Clone + Send + 'static { fn send(&self, msg: Message) -> bool; } impl Send_ for mio::Sender<Message> { fn send(&self, msg: Message) -> bool { self.send(msg).is_ok() } } #[cfg(test)] impl Send_ for ::std::sync::mpsc::Sender<Message> { fn send(&self, msg: Message) -> bool { self.send(msg).is_ok() } }