#io #reconnect #retry #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.

19 releases

new 0.6.0 Jan 27, 2025
0.5.12 Dec 1, 2024
0.5.11 Nov 10, 2024
0.5.8 Jul 28, 2024
0.4.4 Nov 23, 2023

#796 in Network programming

Download history 46/week @ 2024-10-08 15/week @ 2024-10-15 172/week @ 2024-10-22 14/week @ 2024-10-29 130/week @ 2024-11-05 43/week @ 2024-11-12 25/week @ 2024-11-19 135/week @ 2024-11-26 96/week @ 2024-12-03 56/week @ 2024-12-10 21/week @ 2024-12-17 2/week @ 2024-12-24 130/week @ 2024-12-31 165/week @ 2025-01-07 232/week @ 2025-01-14 16/week @ 2025-01-21

543 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

~4–12MB
~116K SLoC