Skip to content

Commit

Permalink
Merge pull request #2 from Santiniis/master
Browse files Browse the repository at this point in the history
Add compatibility to allow for OTP version advancement
  • Loading branch information
lrascao authored Aug 20, 2019
2 parents 9569e84 + 80c173a commit 0bdf4c2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
7 changes: 5 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{deps, [
{time_compat, "0.0.1"}
{time_compat, "0.0.1"},
{stacktrace_compat, "1.1.1"}
]}.

{erl_opts, [
Expand All @@ -11,5 +12,7 @@
warn_shadow_vars,
warn_unused_function,
warn_obsolete_guard,
warn_unused_import
warn_unused_import,
{parse_transform, stacktrace_transform},
{platform_define, "^[2-9]", post19}
]}.
4 changes: 3 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{"1.1.0",
[{<<"time_compat">>,{pkg,<<"time_compat">>,<<"0.0.1">>},0}]}.
[{<<"stacktrace_compat">>,{pkg,<<"stacktrace_compat">>,<<"1.1.1">>},0},
{<<"time_compat">>,{pkg,<<"time_compat">>,<<"0.0.1">>},0}]}.
[
{pkg_hash,[
{<<"stacktrace_compat">>, <<"1C064BC1725F5BD6470853487AC7FBDA5D5E8745CE4B57D0AE71765C85B4414A">>},
{<<"time_compat">>, <<"23FE0AD1FDF3B5B88821B2D04B4B5E865BF587AE66056D671FE0F53514ED8139">>}]}
].
2 changes: 1 addition & 1 deletion src/gen_server2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ adjust_timeout_state(SleptAt, AwokeAt, {backoff, CurrentTO, MinimumTO,
true -> lists:max([MinimumTO, CurrentTO div 2]);
false -> CurrentTO
end,
{Extra, RandomState1} = random:uniform_s(Base, RandomState),
{Extra, RandomState1} = rand:uniform_s(Base, RandomState),
CurrentTO1 = Base + Extra,
{backoff, CurrentTO1, MinimumTO, DesiredHibPeriod, RandomState1}.

Expand Down
9 changes: 5 additions & 4 deletions src/rabbit_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,13 @@ moving_average(Time, HalfLife, Next, Current) ->
random(N) ->
case get(random_seed) of
undefined ->
random:seed(erlang:phash2([node()]),
time_compat:monotonic_time(),
time_compat:unique_integer());
rand:seed(exsplus,
{erlang:phash2([node()]),
time_compat:monotonic_time(),
time_compat:unique_integer()});
_ -> ok
end,
random:uniform(N).
rand:uniform(N).

%% Moved from rabbit/src/rabbit_cli.erl
%% If the server we are talking to has non-standard net_ticktime, and
Expand Down
17 changes: 13 additions & 4 deletions src/ssl_compat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@

connection_information(SslSocket) ->
code_version:update(?MODULE),
ssl_compat:connection_information(SslSocket).
compat_connection_information(SslSocket).

connection_information_post_18(SslSocket) ->
ssl:connection_information(SslSocket).
compat_connection_information(SslSocket).

connection_information_pre_18(SslSocket) ->
case ssl:connection_info(SslSocket) of
case compat_connection_information(SslSocket) of
{ok, {ProtocolVersion, CipherSuite}} ->
{ok, [{protocol, ProtocolVersion},
{cipher_suite, CipherSuite}]};
Expand All @@ -64,7 +64,7 @@ connection_information_pre_18(SslSocket, Items) ->
WantCipherSuite = lists:member(cipher_suite, Items),
if
WantProtocolVersion orelse WantCipherSuite ->
case ssl:connection_info(SslSocket) of
case compat_connection_information(SslSocket) of
{ok, {ProtocolVersion, CipherSuite}} ->
filter_information_items(ProtocolVersion,
CipherSuite,
Expand All @@ -90,3 +90,12 @@ filter_information_items(ProtocolVersion, CipherSuite, [_ | Rest],
filter_information_items(ProtocolVersion, CipherSuite, Rest, Result);
filter_information_items(_ProtocolVersion, _CipherSuite, [], Result) ->
{ok, lists:reverse(Result)}.


-ifdef(post19).
compat_connection_information(SslSocket) ->
ssl:connection_information(SslSocket).
-else.
compat_connection_information(SslSocket) ->
ssl:connection_info(SslSocket).
-endif.

0 comments on commit 0bdf4c2

Please sign in to comment.