#tcp-connection #connector #tokio #networking #async #abstraction #async-networking

schmoozer

A simple abstraction over a retryable async operation, such as establishing a connection

6 releases (3 breaking)

new 0.4.1 Oct 18, 2024
0.4.0 Oct 3, 2024
0.3.0 Oct 3, 2024
0.2.0 Sep 16, 2024
0.1.1 Feb 29, 2024

#2108 in Network programming

Download history 208/week @ 2024-09-16 24/week @ 2024-09-23 342/week @ 2024-09-30 31/week @ 2024-10-07

605 downloads per month

0BSD license

17KB
162 lines

schmoozer

A simple abstraction over a retryable async operation, such as establishing a TCP connection.


lib.rs:

schmoozer is intended to be used as an async (re)connector. It consists of two primary parts:

  • The Connector trait is implemented by applications/libraries that need to run retryable connection loops.
  • [run()] is a function that takes in a Connector implementation, and attempts to establish a connection, delaying and retrying on failures that the callback reports as retriable, and calls the [Connector::run()] trait method once a connection has been successfully been established.

Perhaps paradoxically the [run()] function does not itself actually attempt to establish any connections -- it relies on the [Connector::connect()] trait method implementation to establish connections.

The "good path" overall flow of the connector loop is to call the connect() trait method. If it is successful, call the trait's run() method, passing along the newly allocated connection. The main application logic relating to the connection should implemented in this method.

The primary purpose of the connector concerns the "retryable failure path": If the connect() method encounters a failure it can choose to signal to back to the connector loop that the error is "retryable", in which case the retry_delay() method is called to determine if the connector loop should retry (and implement a delay before returning instructions to do so).

Likewise, the [Connector::run()] trait method returns its RunResult to indicate whether the connector should reconnect or exit, either successfully or with an error.

Features

Feature Function
tcpconn Enable support for a simple TCP (re)connector.
tracing Make the connector loop generator tracing logs.

Dependencies

~0.2–9MB
~78K SLoC