Catch IPv4-only failure case

A eafnosupport error is returned if IPv4 is not supported at all,
but eaddrnotavail can also be returned if the system is not configured
to allow listening at 0::1.
This commit is contained in:
Craig Everett 2024-03-21 10:54:24 +09:00
parent 36c4838245
commit 5069ebe3b8
58 changed files with 51 additions and 50 deletions

View File

@ -1 +1 @@
0.13.4
0.13.5

View File

@ -1,6 +1,6 @@
{application,zx,
[{description,"An Erlang development tool and Zomp user client"},
{vsn,"0.13.4"},
{vsn,"0.13.5"},
{applications,[stdlib,kernel]},
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man,

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -24,7 +24,7 @@
%%% @end
-module(zx).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(application).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_auth).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_conn).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_conn_sup).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -138,7 +138,7 @@
%%% @end
-module(zx_daemon).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_key).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_lib).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_local).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_net).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_peer).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_peer_man).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
@ -223,28 +223,11 @@ terminate(_, _) ->
%% The "doer" procedure called when a "listen" message is received.
do_listen(State = #s{listener = none}) ->
Options =
[inet6,
{ip, {0,0,0,0,0,0,0,1}},
{active, true},
{mode, binary},
{keepalive, true},
{reuseaddr, true},
{packet, 4}],
{ok, Listener} =
case gen_tcp:listen(0, Options) of
{ok, L} ->
{ok, L};
{error, eafnosupport} ->
AncientOptions =
[inet,
{ip, {127,0,0,1}},
{active, true},
{mode, binary},
{keepalive, true},
{reuseaddr, true},
{packet, 4}],
gen_tcp:listen(0, AncientOptions)
case gen_tcp:listen(0, ipv6_options()) of
{ok, L} -> {ok, L};
{error, eafnosupport} -> gen_tcp:listen(0, ipv4_options());
{error, eaddrnotavail} -> gen_tcp:listen(0, ipv4_options())
end,
{ok, Port} = inet:port(Listener),
{ok, _} = zx_peer:start(Listener),
@ -253,6 +236,24 @@ do_listen(State) ->
ok = log(warning, "Already listening."),
{error, State}.
ipv6_options() ->
[inet6,
{ip, {0,0,0,0,0,0,0,1}},
{active, true},
{mode, binary},
{keepalive, true},
{reuseaddr, true},
{packet, 4}].
ipv4_options() ->
[inet,
{ip, {127,0,0,1}},
{active, true},
{mode, binary},
{keepalive, true},
{reuseaddr, true},
{packet, 4}].
-spec do_enroll(Pid, State) -> NewState
when Pid :: pid(),

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_peer_sup).
-vsn("0.13.4").
-vsn("0.13.5").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_peers).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_proxy).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_sup).
-vsn("0.13.4").
-vsn("0.13.5").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_tty).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_userconf).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_zsp).
-vsn("0.13.4").
-vsn("0.13.5").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -1,17 +1,17 @@
{a_email,"zxq9@zxq9.com"}.
{name,"zx"}.
{type,app}.
{modules,[]}.
{prefix,"zx_"}.
{author,"Craig Everett"}.
{desc,"An Erlang development tool and Zomp user client"}.
{package_id,{"otpr","zx",{0,13,5}}}.
{deps,[]}.
{key_name,none}.
{a_email,"zxq9@zxq9.com"}.
{c_email,"zxq9@zxq9.com"}.
{copyright,"Craig Everett"}.
{deps,[]}.
{desc,"An Erlang development tool and Zomp user client"}.
{file_exts,[]}.
{key_name,none}.
{license,"MIT"}.
{modules,[]}.
{name,"zx"}.
{package_id,{"otpr","zx",{0,13,4}}}.
{prefix,"zx_"}.
{repo_url,"https://gitlab.com/zxq9/zx"}.
{tags,["tools","package manager","erlang"]}.
{type,app}.
{ws_url,"https://zxq9.com/projects/zomp/"}.