#io #reconnect #retry #tcp-stream #tokio #stubborn #stubborn-tcp-stream

sdre-stubborn-io

Forked from https://github.com/craftytrickster/stubborn-io. io traits/structs that automatically recover from potential disconnections/interruptions.

8 releases

new 0.5.5 May 13, 2024
0.5.4 Mar 18, 2024
0.5.3 Feb 3, 2024
0.5.2 Jan 19, 2024
0.4.4 Nov 23, 2023

#783 in Network programming

Download history 18/week @ 2024-01-28 17/week @ 2024-02-04 16/week @ 2024-02-11 87/week @ 2024-02-18 80/week @ 2024-02-25 31/week @ 2024-03-03 100/week @ 2024-03-10 231/week @ 2024-03-17 32/week @ 2024-03-24 52/week @ 2024-03-31 105/week @ 2024-04-07 111/week @ 2024-04-14 38/week @ 2024-04-21 57/week @ 2024-04-28 4/week @ 2024-05-05 188/week @ 2024-05-12

288 downloads per month

MIT license

37KB
662 lines

sdre-stubborn-io

This crate provides io traits/structs that automatically recover from potential disconnections/interruptions.

To use with your project, add the following to your Cargo.toml:

stubborn-io = { git = "https://github.com/sdr-enthusiasts/sdre-stubborn-io.git" }

Thanks and purpose

This project has been forked from stubborn-io and modified to add the ability to name connections. Much thanks to craftytrickster for the original project.

Documentation

API Documentation, examples and motivations can be found here - (Rust Docs)https://docs.rs/sdre-stubborn-io .

Only change to the documentation in this fork will be the addition of the ReconnectionOptions struct, which adds with_connection_name(name: &str) as a method to the StubbornTcpStream struct. This allows for the naming of the connection, which is useful for logging purposes.

If you generate the struct manually, the field name is connection_name.

Usage Example

In this example, we will see a drop in replacement for tokio's TcpStream, with the distinction that it will automatically attempt to reconnect in the face of connectivity failures.

use sdre_stubborn_io::StubbornTcpStream;
use tokio::io::AsyncWriteExt;

let addr = "localhost:8080";

// we are connecting to the TcpStream using the default built in options.
// these can also be customized (for example, the amount of reconnect attempts,
// wait duration, etc) using the connect_with_options method.
let mut tcp_stream = StubbornTcpStream::connect(addr).await?;
// once we acquire the wrapped IO, in this case, a TcpStream, we can
// call all of the regular methods on it, as seen below
tcp_stream.write_all(b"hello world!").await?;

Dependencies

~3–11MB
~103K SLoC