3 releases
new 0.1.2 | Feb 22, 2025 |
---|---|
0.1.1 | Feb 20, 2025 |
0.1.0 | Feb 15, 2025 |
#1823 in Network programming
100 downloads per month
28KB
262 lines
tokio_dual_stack
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.
Minimum Supported Rust Version (MSRV)
This will frequently be updated to be the same as stable. Specifically, any time stable is updated and that update has "useful" features or compilation no longer succeeds (e.g., due to new compiler lints), then MSRV will be updated.
MSRV changes will correspond to a SemVer patch version bump pre-1.0.0
; otherwise a minor version bump.
SemVer Policy
- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Before any PR is sent, cargo clippy
and cargo t
should be run. Additionally
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features
should be run to ensure documentation can be built.
Status
This package is actively maintained and will conform to the latest version of
tokio
.
The crate is only tested on x86_64-unknown-linux-gnu
and x86_64-unknown-openbsd
targets, but it should work
on most platforms.
Dependencies
~2–10MB
~94K SLoC