Expand description
General IO module.
Example usage for creating a network service and adding an IO handler:
extern crate vapcore_io;
use vapcore_io::*;
use std::sync::Arc;
use std::time::Duration;
struct MyHandler;
#[derive(Clone)]
struct MyMessage {
data: u32
}
impl IoHandler<MyMessage> for MyHandler {
fn initialize(&self, io: &IoContext<MyMessage>) {
io.register_timer(0, Duration::from_secs(1)).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
}
§Mio vs non-mio
This library has two modes: mio and not mio. The mio
feature can be activated or deactivated
when compiling or depending on the library.
Without mio, only timers and message-passing are available. With mio, you can also use low-level sockets provided by mio.
The non-mio mode exists because the mio
library doesn’t compile on platforms such as
emscripten.
Structs§
- Allows sending messages into the event loop. All the IO handlers will get the message in the
message
callback. - IO access point. This is passed to all IO handlers and provides an interface to the IO subsystem.
- General IO Service. Starts an event loop and dispatches IO requests. ‘Message’ is a notification message type
Enums§
- IO Error
Constants§
- Stack size Should be modified if it is changed in Rust since it is no way to know or get it
- Maximum number of tokens a handler can use
Traits§
- Generic IO handler. All the handler function are called from within IO event loop.
Message
type is used as notification data
Type Aliases§
- Timer ID