Crate tokio_dual_stack

Source
Expand description

gitcrates-iodocs-rs

tokio_dual_stack is a library that adds a “dual-stack” TcpListener.

§Why is this useful?

Only certain platforms offer the ability for one socket to handle both IPv6 and IPv4 requests (e.g., OpenBSD does not). For the platforms that do, it is often dependent on runtime configuration (e.g., IPV6_V6ONLY). Additionally those platforms that support it often require the “wildcard” IPv6 address to be used (i.e., ::) which has the unfortunate consequence of preventing other services from using the same protocol port.

There are a few ways to work around this issue. One is to deploy the same service twice: one that uses an IPv6 socket and the other that uses an IPv4 socket. This can complicate deployments (e.g., the application may not have been written with the expectation that multiple deployments could be running at the same time) in addition to using more resources. Another is for the application to manually handle each socket (e.g., select/join each TcpListener::accept).

DualStackTcpListener chooses an implementation similar to what the equivalent select would do while also ensuring that one socket does not “starve” another by ensuring each socket is fairly given an opportunity to TcpListener::accept a connection. This has the nice benefit of having a similar API to what a single TcpListener would have as well as having similar performance to a socket that does handle both IPv6 and IPv4 requests.

Structs§

DualStackTcpListener
“Dual-stack” TCP listener.

Traits§

Tcp
TCP “listener”.