Repository navigation
gen_tcp: match OTP reuseaddr option - #2498
UncleGrumpy wants to merge 4 commits into
Conversation
1143472 to
18efda3
Compare
|
|
||
| start_server(Port, Router) -> | ||
| case gen_tcp:listen(Port, []) of | ||
| case gen_tcp:listen(Port, [{reuseaddr, true}]) of |
There was a problem hiding this comment.
This is a temporary change needed for tests to pass. I have another PR coming that will make gen_tcp options passed here configurable to users, like inet_backend and reuseaddr options.
18efda3 to
a9f991d
Compare
|
AMP code, believe 1 and 2 should be ignored: PR #2498 review:
|
a9f991d to
3ff73f5
Compare
Map EADDRINUSE in posix_errno_to_term, so the socket NIFs return
{error, eaddrinuse} instead of {error, 98}, and have the generic_unix
inet backend do_bind return {error, eaddrinuse} instead of
{error, {bind, 98}}, matching OTP. The esp32 inet backend already
reported eaddrinuse (ERR_USE).
Signed-off-by: Winford <winford@object.stream>
The generic_unix inet backend set SO_REUSEADDR unconditionally on
listening sockets; make it opt-in with the {reuseaddr, true} option,
matching OTP where it defaults to off. The esp32 inet backend, which
never set it, gains the same opt-in support on builds with ESP-IDF 5.4
or newer: SOF_REUSEADDR is set on the listener pcb before bind, from
the TCP/IP thread, as lwIP checks it in tcp_bind. Older ESP-IDF ships
lwIP without the synchronous tcp/ip callback needed to safely set the
flag before bind, so there the option is rejected with
{error, badarg}.
Signed-off-by: Winford <winford@object.stream>
Apply the option to the listening socket before bind, mirroring OTP's gen_tcp_socket, which sets the listen options before binding. The option is opt-in and defaults to off, as on OTP. Signed-off-by: Winford <winford@object.stream>
Make http_server reuse addresses, this allows http_server to use ports that are in free, but in TIME_WAIT (after being released). Update test to return a connection error on failure, rather than crash with an ambiguous function clause error. Signed-off-by: Winford <winford@object.stream>
3ff73f5 to
5c45393
Compare
2 was valid, we want to be consistent with OTP, but I did not address P1. I will be opening a draft of the follow-on PR in the next day or so. |
Make support for the gen_tcp reuseaddr option consistent with OTP on both backends and across platforms. Previously the option was not settable on any platform and was inconsistently enabled across platforms. Now matches OTP disabled by default.
Closes #2497
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later