A library that allows to listen network sockets with proper resource limits and error handling
APACHE-2.0 License
Status: Beta
Documentation | Github | Crate
A library that allows to listen network sockets with proper resource limits and error handling.
Basic challenges:
Here is the basic example:
let TIME_TO_WAIT_ON_ERROR = Duration::from_millis(100);
let MAX_SIMULTANEOUS_CONNECTIONS = 1000;
let mut lp = Core::new().unwrap();
let listener = TcpListener::bind(&addr, &lp.handle()).unwrap();
lp.run(
listener.incoming()
.sleep_on_error(TIME_TO_WAIT_ON_ERROR, &h2)
.map(move |(mut socket, _addr)| {
// Your future is here:
Proto::new(socket)
// Errors should not pass silently
// common idea is to log them
.map_err(|e| error!("Protocol error: {}", e))
})
.listen(MAX_SIMULTANEOUS_CONNECTIONS)
).unwrap(); // stream doesn't end in this case
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.