fix(emqx_misc): call gen_tcp to decide if ipv6_probe is supported

This commit is contained in:
Zaiming Shi 2021-11-16 08:37:53 +01:00
parent a178b6cc08
commit 2dc63cffea
1 changed files with 3 additions and 10 deletions

View File

@ -66,16 +66,9 @@ maybe_parse_ip(Host) ->
%% @doc Add `ipv6_probe' socket option if it's supported.
ipv6_probe(Opts) ->
case persistent_term:get({?MODULE, ipv6_probe_supported}, unknown) of
unknown ->
%% e.g. 23.2.7.1-emqx-2-x86_64-unknown-linux-gnu-64
OtpVsn = emqx_vm:get_otp_version(),
Bool = (match =:= re:run(OtpVsn, "emqx", [{capture, none}])),
_ = persistent_term:put({?MODULE, ipv6_probe_supported}, Bool),
ipv6_probe(Bool, Opts);
Bool ->
ipv6_probe(Bool, Opts)
end.
Bool = try gen_tcp:ipv6_probe()
catch _ : _ -> false end,
ipv6_probe(Bool, Opts).
ipv6_probe(false, Opts) -> Opts;
ipv6_probe(true, Opts) -> [{ipv6_probe, true} | Opts].