mio-pool
A worker pool collectively handling a set of connections.
This crate is written for the use-case where a server is listening for connections, and wants
to spread the load of handling accepted connections across multiple threads. Specifically, this
crate implements a worker pool that shares a single mio::Poll
instance, and collectively
accept new connections and handle events for existing ones.
Users will want to start with the PoolBuilder
struct, which allows creating a new pool from
anything that can act as a Listener
(basically, anything that can be polled and accept new
connections that can themselves be polled; e.g., mio::net::TcpListener
).
Examples
use *;
let addr = "127.0.0.1:0".parse.unwrap;
let server = bind.unwrap;
let addr = server.local_addr.unwrap;
let pool = from.unwrap;
let h = pool.run;
// new clients can now connect on `addr`
use TcpStream;
let mut c = connect.unwrap;
c.write_all.unwrap;
let mut buf = ;
let n = c.read.unwrap;
assert_eq!;
// we can terminate the pool at any time
let results = h.terminate;
// results here contains the final state of each worker in the pool.
// that is, the final value in each `s` passed to the closure in `run`.
let result = results.into_iter.next.unwrap;
assert_eq!;