Skip to content

Commit

Permalink
Merge pull request #87 from badeend/reuseaddr
Browse files Browse the repository at this point in the history
Document SO_REUSEADDR to be the default for TCP `bind`
  • Loading branch information
badeend authored Jan 3, 2024
2 parents 333b8a8 + 6907592 commit 7b7b7da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Posix-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Legend:
|| TCP_KEEPIDLE <br/><sub>TCP_KEEPALIVE on MacOS</sub> | [`tcp-socket::(set-)keep-alive-idle-time`][tcp] | linux, windows, macos, freebsd, jvm, .net, libuv, go, nginx, curl |
|| TCP_KEEPINTVL | [`tcp-socket::(set-)keep-alive-interval`][tcp] | linux, windows, macos, freebsd, jvm, .net, libuv, go, nginx, curl |
|| TCP_KEEPCNT | [`tcp-socket::(set-)keep-alive-count`][tcp] | linux, windows, macos, freebsd, jvm, .net, libuv, nginx |
|| SO_REUSEADDR for TCP | Enabled by default. See [`tcp-socket::bind`][tcp] | posix, linux, windows, macos, freebsd, jvm, .net, libuv, go, openssl, nginx, curl, exim |
|| SO_ERROR | Not necessary. WIT has (or will have) native support for asynchronous results. | posix, linux, windows, macos, freebsd, jvm, .net, rust, libuv, go, openssl, nginx, curl, msquic |
|| SO_TYPE | Can be inferred from the socket resource type. | posix, linux, windows, macos, freebsd, jvm, .net, go, openssl, nginx, curl, exim |
|| SO_PROTOCOL <br/><sub>SO_PROTOCOL_INFO on Windows</sub> | Can be inferred from the socket resource type. | linux, windows, freebsd, .net, exim |
Expand All @@ -182,7 +183,7 @@ Legend:
|| IPV6_MTU_DISCOVER | [#79][79] | linux, windows, openssl, nginx, curl, msquic |
|| TCP_NODELAY | [#75][75] | posix, linux, windows, macos, freebsd, jvm, .net, rust, libuv, go, openssl, nginx, curl, exim |
|| TCP_CORK <br/><sub>TCP_NOPUSH on MacOS & FreeBSD</sub> | [#75][75] | linux, macos, freebsd, nginx, exim |
|| SO_REUSEADDR | [#74][74] | posix, linux, windows, macos, freebsd, jvm, .net, libuv, go, openssl, nginx, curl, exim |
|| SO_REUSEADDR for UDP | [#74][74] | posix, linux, windows, macos, freebsd, jvm, .net, libuv, go, openssl, nginx, curl, exim |
|| SO_EXCLUSIVEADDRUSE | [#74][74] | windows |
|| SO_RANDOMIZE_PORT | [#74][74] | windows |
|| SO_RANDOMPORT | [#74][74] | macos |
Expand Down
5 changes: 5 additions & 0 deletions imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,11 @@ implicitly bind the socket.</p>
<li><code>not-in-progress</code>: A <code>bind</code> operation is not in progress.</li>
<li><code>would-block</code>: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)</li>
</ul>
<h1>Implementors note</h1>
<p>When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT
state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR
socket option should be set implicitly on all platforms, except on Windows where this is the default behavior
and SO_REUSEADDR performs something different entirely.</p>
<h1>References</h1>
<ul>
<li><a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html</a></li>
Expand Down
6 changes: 6 additions & 0 deletions wit/tcp.wit
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ interface tcp {
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
/// - `not-in-progress`: A `bind` operation is not in progress.
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
///
/// # Implementors note
/// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT
/// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR
/// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior
/// and SO_REUSEADDR performs something different entirely.
///
/// # References
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
Expand Down

0 comments on commit 7b7b7da

Please sign in to comment.