docs.rs failed to build mio-0.2.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
mio-0.8.4
A fast, low-level IO library for Rust focusing on non-blocking APIs, event notification, and other useful utilities for building high performance IO apps.
Goals
- Fast - minimal overhead over the equivalent OS facilities (epoll, kqueue, etc...)
- Zero allocations
- A scalable readiness-based API, similar to epoll on Linux
- Design to allow for stack allocated buffers when possible (avoid double buffering).
- Provide utilities such as a timers, a notification channel, buffer abstractions, and a slab.
Usage
Using mio starts by creating an EventLoop, which handles receiving events from the OS and dispatching them to a supplied Handler.
Example
use mio::*;
use mio::net::{SockAddr};
use mio::net::tcp::{TcpSocket, TcpAcceptor};
// Setup some tokens to allow us to identify which event is
// for which socket.
const SERVER: Token = Token(0);
const CLIENT: Token = Token(1);
let addr = SockAddr::parse("127.0.0.1:13265").unwrap();
// Setup the server socket
let server = TcpSocket::v4().unwrap()
.bind(&addr).unwrap()
.listen(256).unwrap();
// Create an event loop
let mut event_loop = EventLoop::<(), ()>::new().unwrap();
// Start listening for incoming connections
event_loop.register(&server, SERVER).unwrap();
// Setup the client socket
let sock = TcpSocket::v4().unwrap();
// Connect to the server
sock.connect(&addr).unwrap();
// Register the socket
event_loop.register(&sock, CLIENT).unwrap();
// Define a handler to process the events
struct MyHandler(TcpAcceptor);
impl Handler<(), ()> for MyHandler {
fn readable(&mut self, event_loop: &mut EventLoop<(), ()>, token: Token, _: ReadHint) {
match token {
SERVER => {
let MyHandler(ref mut server) = *self;
// Accept and drop the socket immediately, this will close
// the socket and notify the client of the EOF.
let _ = server.accept();
}
CLIENT => {
// The server just shuts down the socket, let's just
// shutdown the event loop
event_loop.shutdown();
}
_ => panic!("unexpected token"),
}
}
}
// Start handling events
let _ = event_loop.run(MyHandler(server));