Skip to content

Commit

Permalink
Erlang 18.0+ compatibility
Browse files Browse the repository at this point in the history
- use a compatible record-to-type declaration
- adapt to the new time API while remaining backwards compatible.
  • Loading branch information
ferd committed Jul 16, 2015
1 parent 0d440de commit aa54c1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: erlang
otp_release:
- 18.0
- 17.5
- R16B
- R15B02
- R15B01
Expand Down
15 changes: 12 additions & 3 deletions src/epna_pool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
%%% Types
%%%===================================================================

-type state() :: record(state).
-type state() :: #state{}.

%%%===================================================================
%%% API
Expand Down Expand Up @@ -284,8 +284,17 @@ cleanup_connection(C, State = #state{working=Working}) ->
%% Return the current time in seconds, used for timeouts.
-spec now_secs() -> non_neg_integer().
now_secs() ->
{M,S,_M} = erlang:now(),
M*1000 + S.
try
%% use apply/3 because otherwise cover compilation
%% fails on < 18.0
apply(erlang, monotonic_time, [seconds])
catch
error:undef ->
%% use apply/3 because otherwise the compiler
%% warns in 18.0+
{M,S,_M} = apply(erlang, now, []),

This comment has been minimized.

Copy link
@michalwski

michalwski Aug 13, 2015

Would os:timestamp/1 be enough here? I see that only MegaSec and Sec are used here.

This comment has been minimized.

Copy link
@ferd

ferd Aug 13, 2015

Author Contributor

No. The reason being that here we want to count an interval in time (how many seconds passed) and not just the OS time. os:timestamp() is sensitive to clock readjustments on the host whereas monotonic time and now() don't have the same problem and provide a stabler time view.

They're the appropriate tool for time differences as they are used here if we don't want weird things to happen when the clock jumps forwards or backwards.

M*1000 + S
end.

-spec make_registered_name(episcina:name()) -> term().
make_registered_name(Name) ->
Expand Down

0 comments on commit aa54c1c

Please sign in to comment.