Awesome Open Source
Awesome Open Source

Tokio Listen Helpers

Status: Beta

Documentation | Github | Crate

A library that allows to listen network sockets with proper resource limits and error handling.

Basic challenges:

  • Some connection accept errors (like "connection reset") must be ignored, some (like "too many files open") may consume 100% CPU when ignored. You need to know what to do with them every time
  • Server must accept connections up to a certain limit to avoid DoS attacks
  • Shutting down listener and update the set of addresses listened should be obvious to implement


Here is the basic example:

let TIME_TO_WAIT_ON_ERROR = Duration::from_millis(100);

let mut lp = Core::new().unwrap();
let listener = TcpListener::bind(&addr, &lp.handle()).unwrap();
    .sleep_on_error(TIME_TO_WAIT_ON_ERROR, &h2)
    .map(move |(mut socket, _addr)| {
         // Your future is here:
         // Errors should not pass silently
         // common idea is to log them
         .map_err(|e| error!("Protocol error: {}", e))
).unwrap(); // stream doesn't end in this case

More in docs and examples


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.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Rust (61,660
Network (3,579
Tcp (1,639
Asynchronous (1,270
Futures (429
Tokio (188
Related Projects