Mtcp - TcpListener/TcpStream *with* timeout/cancellation support

mtcp provides a "blocking" TcpListener and TcpStream with timeout and cancellation support.

This is pretty much a drop-in replacement for std::net::{TcpListener, TcpStream}, but with an additional timeout parameter in the "blocking" functions. Also, a Canceller can be used to abort the "pending" operation immediately, e.g. from another thread or from the Ctrl+C handler.

The "blocking" operations are emulated via mio, but you won't have to deal with mio directly at all.

@crates.io:
https://crates.io/crates/mtcp-rs

API Documentation:

Examples:

Repository:

License:
The Unlicense / Public Domain

I'd suggest you to host this on a GitHub repository and maybe publish it on crates.io to help users reuse your crate.

One concern about code is that you should let users instantiate Rc<TcpManager> instead of forcing one instance by threads. In current implementation, once you call cancel() you can't use the TcpManager from this thread anymore.

Cancelling doesn't always mean you want to exit the process, maybe the network communication is only part of the whole process and we want to be able to abort it before timeout expires but this network communication could happen again later.

Why not let user create their Rc<TcpManager> ?

Thanks for response!

I'd suggest you to host this on a GitHub repository and maybe publish it on crates.io to help users reuse your crate.

Okay, I will look into this soon.

One concern about code is that you should let users instantiate Rc<TcpManager> instead of forcing one instance by threads. In current implementation, once you call cancel() you can't use the TcpManager from this thread anymore.

Cancelling doesn't always mean you want to exit the process, maybe the network communication is only part of the whole process and we want to be able to abort it before timeout expires but this network communication could happen again later.

Why not let user create their Rc<TcpManager> ?

You are right. In the latest version I have made it possible to create TcpManager separately.

Also, I have added functions to "restart" the TcpManager.

1 Like

I'd suggest you to host this on a GitHub repository and maybe publish it on crates.io to help users reuse your crate.

Okay, I have finally uploaded my project to crates.io today :sunglasses:
https://crates.io/crates/mtcp-rs

Version 0.1.3 has been released.

This release uses lazy_rc and contains various fixes and improvements.