Crate ethcore_io [−] [src]
General IO module.
Example usage for creating a network service and adding an IO handler:
extern crate ethcore_io; use ethcore_io::*; use std::sync::Arc; struct MyHandler; #[derive(Clone)] struct MyMessage { data: u32 } impl IoHandler<MyMessage> for MyHandler { fn initialize(&self, io: &IoContext<MyMessage>) { io.register_timer(0, 1000).unwrap(); } fn timeout(&self, _io: &IoContext<MyMessage>, timer: TimerToken) { println!("Timeout {}", timer); } fn message(&self, _io: &IoContext<MyMessage>, message: &MyMessage) { println!("Message {}", message.data); } } fn main () { let mut service = IoService::<MyMessage>::start().expect("Error creating network service"); service.register_handler(Arc::new(MyHandler)).unwrap(); // Wait for quit condition // ... // Drop the service }
Structs
IoChannel |
Allows sending messages into the event loop. All the IO handlers will get the message
in the |
IoContext |
IO access point. This is passed to all IO handlers and provides an interface to the IO subsystem. |
IoManager |
Root IO handler. Manages user handlers, messages and IO timers. |
IoService |
General IO Service. Starts an event loop and dispatches IO requests. 'Message' is a notification message type |
PanicHandler |
Structure that allows to catch panics and notify listeners |
Enums
IoError |
IO Error |
Constants
TOKENS_PER_HANDLER |
Maximum number of tokens a handler can use |
Statics
LOCAL_STACK_SIZE |
Stack size Should be modified if it is changed in Rust since it is no way to know or get it |
Traits
ForwardPanic |
Forwards panics from child |
IoHandler |
Generic IO handler.
All the handler function are called from within IO event loop.
|
MayPanic |
Trait indicating that the structure catches some of the panics (most probably from spawned threads) and it's possbile to be notified when one of the threads panics. |
OnPanicListener |
Thread-safe closure for handling possible panics |
Type Definitions
StreamToken |
Timer ID |
TimerToken |
Timer ID |