feat(eqmx_misc): add an api to ensure ipv6_probe socket option
This commit is contained in:
parent
e54433d342
commit
b688bcfe74
|
@ -43,6 +43,7 @@
|
||||||
, now_to_secs/1
|
, now_to_secs/1
|
||||||
, now_to_ms/1
|
, now_to_ms/1
|
||||||
, index_of/2
|
, index_of/2
|
||||||
|
, ipv6_probe/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ bin2hexstr_A_F/1
|
-export([ bin2hexstr_A_F/1
|
||||||
|
@ -50,6 +51,22 @@
|
||||||
, hexstr2bin/1
|
, hexstr2bin/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%% @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.
|
||||||
|
|
||||||
|
ipv6_probe(false, Opts) -> Opts;
|
||||||
|
ipv6_probe(true, Opts) -> [ipv6_probe | Opts].
|
||||||
|
|
||||||
%% @doc Merge options
|
%% @doc Merge options
|
||||||
-spec(merge_opts(Opts, Opts) -> Opts when Opts :: proplists:proplist()).
|
-spec(merge_opts(Opts, Opts) -> Opts when Opts :: proplists:proplist()).
|
||||||
merge_opts(Defaults, Options) ->
|
merge_opts(Defaults, Options) ->
|
||||||
|
@ -258,3 +275,10 @@ hexchar2int(I) when I >= $0 andalso I =< $9 -> I - $0;
|
||||||
hexchar2int(I) when I >= $A andalso I =< $F -> I - $A + 10;
|
hexchar2int(I) when I >= $A andalso I =< $F -> I - $A + 10;
|
||||||
hexchar2int(I) when I >= $a andalso I =< $f -> I - $a + 10.
|
hexchar2int(I) when I >= $a andalso I =< $f -> I - $a + 10.
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
ipv6_probe_test() ->
|
||||||
|
?assertEqual([ipv6_probe], ipv6_probe([])).
|
||||||
|
|
||||||
|
-endif.
|
||||||
|
|
|
@ -382,7 +382,7 @@ read_otp_version() ->
|
||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
%% running tests etc.
|
%% running tests etc.
|
||||||
OtpMajor = erlang:system_info(otp_release),
|
OtpMajor = erlang:system_info(otp_release),
|
||||||
OtpVsnFile = file:read_file(filename:join([ReleasesDir, OtpMajor, "OTP_VERSION"])),
|
OtpVsnFile = filename:join([ReleasesDir, OtpMajor, "OTP_VERSION"]),
|
||||||
{ok, Vsn} = file:read_file(OtpVsnFile),
|
{ok, Vsn} = file:read_file(OtpVsnFile),
|
||||||
Vsn
|
Vsn
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue