Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tailhook/tk-listen
A library that allows to listen network sockets with proper resource limits and error handling
https://github.com/tailhook/tk-listen
asynchronous futures listen network rust tcp tokio
Last synced: 18 days ago
JSON representation
A library that allows to listen network sockets with proper resource limits and error handling
- Host: GitHub
- URL: https://github.com/tailhook/tk-listen
- Owner: tailhook
- License: apache-2.0
- Created: 2017-03-09T17:21:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-29T19:11:18.000Z (almost 6 years ago)
- Last Synced: 2024-10-13T22:50:50.021Z (about 1 month ago)
- Topics: asynchronous, futures, listen, network, rust, tcp, tokio
- Language: Rust
- Size: 36.1 KB
- Stars: 30
- Watchers: 6
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Tokio Listen Helpers
====================**Status: Beta**
[Documentation](https://docs.rs/tk-listen) |
[Github](https://github.com/tailhook/tk-listen) |
[Crate](https://crates.io/crates/tk-listen)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 implementExample
=======Here is the basic example:
```rust
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
```More in [docs] and [examples]
[docs]: http://docs.rs/tk-listen/
[examples]: https://github.com/tailhook/tk-listen/tree/master/examplesLicense
=======Licensed under either of
* Apache License, Version 2.0,
(./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.Contribution
------------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.