Skip to content

Commit

Permalink
Support Erlang 19
Browse files Browse the repository at this point in the history
 * Replace erlang:now() keeping compabibility with older versions)
  • Loading branch information
edescourtis committed Oct 18, 2016
1 parent b254c68 commit 981a278
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/examples/sample_mc.erl
Expand Up @@ -106,7 +106,7 @@ success() ->
%%% INIT/TERMINATE EXPORTS
%%%-----------------------------------------------------------------------------
init([Silent]) ->
{A1, A2, A3} = now(),
{A1, A2, A3} = ?NOW(),
random:seed(A1, A2, A3),
{ok, #st{silent = Silent}}.

Expand Down
9 changes: 9 additions & 0 deletions include/oserl.hrl
Expand Up @@ -134,4 +134,13 @@
inactivity_time = ?INACTIVITY_TIME,
response_time = ?RESPONSE_TIME}).


-ifdef(use_new_time_api).
-define(NOW(), erlang:timestamp()).
-define(UNOW(), {erlang:monotonic_time(), erlang:unique_integer([monotonic]), erlang:unique_integer([monotonic])}).
-else.
-define(NOW(), os:timestamp()).
-define(UNOW(), erlang:now()).
-endif. % -ifdef(use_new_time_api)

-endif. % -ifndef(oserl)
9 changes: 6 additions & 3 deletions rebar.config
@@ -1,9 +1,12 @@
{lib_dirs, ["deps"]}.

{erl_opts, [warnings_as_errors, debug_info]}.
{erl_opts, [
warnings_as_errors, debug_info,
{platform_define, "^1[8,9]", 'use_new_time_api'}
]}.

{deps, [{common_lib, "3.3.4",
{git, "git://github.com/iamaleksey/common_lib.git", {tag, "3.3.4"}}}]}.
{deps, [{common_lib, ".*",
{git, "git://github.com/edescourtis/common_lib.git", {branch, master}}}]}.

{erl_first_files, ["src/gen_esme_session.erl",
"src/gen_mc_session.erl",
Expand Down
2 changes: 1 addition & 1 deletion src/smpp_disk_log_hlr.erl
Expand Up @@ -141,7 +141,7 @@ handle_call(Req, St) ->
handle_event({pdu, Pdu}, St) ->
case catch (St#st.filter)(Pdu) of
true ->
disk_log:alog(St#st.name, {now(), (St#st.format)(Pdu)});
disk_log:alog(St#st.name, {?NOW(), (St#st.format)(Pdu)});
_Otherwise ->
ok
end,
Expand Down
2 changes: 2 additions & 0 deletions src/smpp_param.hrl
@@ -1,3 +1,5 @@
%% coding: latin-1

%%% Copyright (C) 2009 Enrique Marcote, Miguel Rodriguez
%%% All rights reserved.
%%%
Expand Down
8 changes: 4 additions & 4 deletions src/smpp_session.erl
Expand Up @@ -70,7 +70,7 @@
%% instant congestion state value is calculated. Notice this value cannot be
%% greater than 99.
congestion(CongestionSt, WaitTime, Timestamp) ->
case (timer:now_diff(now(), Timestamp) div (WaitTime + 1)) * 85 of
case (timer:now_diff(?NOW(), Timestamp) div (WaitTime + 1)) * 85 of
Val when Val < 1 ->
0;
Val when Val > 99 -> % Out of bounds
Expand Down Expand Up @@ -161,11 +161,11 @@ wait_recv(Pid, Sock, Log) ->


recv_loop(Pid, Sock, Buffer, Log) ->
Timestamp = now(),
Timestamp = ?NOW(),
inet:setopts(Sock, [{active, once}]),
receive
{tcp, Sock, Input} ->
L = timer:now_diff(now(), Timestamp),
L = timer:now_diff(?NOW(), Timestamp),
B = handle_input(Pid, list_to_binary([Buffer, Input]), L, 1, Log),
?MODULE:recv_loop(Pid, Sock, B, Log);
{tcp_closed, Sock} ->
Expand Down Expand Up @@ -223,7 +223,7 @@ handle_accept(Pid, Sock) ->


handle_input(Pid, <<CmdLen:32, Rest/binary>> = Buffer, Lapse, N, Log) ->
Now = now(), % PDU received. PDU handling starts now!
Now = ?NOW(), % PDU received. PDU handling starts now!
Len = CmdLen - 4,
case Rest of
<<PduRest:Len/binary-unit:8, NextPdus/binary>> ->
Expand Down
2 changes: 1 addition & 1 deletion test/gen_esme_SUITE.erl
Expand Up @@ -70,7 +70,7 @@ suite() ->
%% @end
init_per_suite(Conf) ->
lists:foreach(fun(X) -> code:add_path(X) end, ct:get_config(paths, [])),
{A1, A2, A3} = now(),
{A1, A2, A3} = ?NOW(),
random:seed(A1, A2, A3),
application:start(common_lib),
dbg:tracer(),
Expand Down
2 changes: 1 addition & 1 deletion test/gen_mc_SUITE.erl
Expand Up @@ -63,7 +63,7 @@ suite() ->
%%%-----------------------------------------------------------------------------
init_per_suite(Conf) ->
lists:foreach(fun(X) -> code:add_path(X) end, ct:get_config(paths, [])),
{A1, A2, A3} = now(),
{A1, A2, A3} = ?NOW(),
random:seed(A1, A2, A3),
application:start(common_lib),
dbg:tracer(),
Expand Down
2 changes: 1 addition & 1 deletion test/operation_SUITE.erl
Expand Up @@ -60,7 +60,7 @@ suite() ->
%%%-----------------------------------------------------------------------------
init_per_suite(Conf) ->
lists:foreach(fun(X) -> code:add_path(X) end, ct:get_config(paths, [])),
{A1, A2, A3} = now(),
{A1, A2, A3} = ?NOW(),
random:seed(A1, A2, A3),
dbg:tracer(),
dbg:p(all, [c, sos, sol]),
Expand Down
2 changes: 1 addition & 1 deletion test/test_mc.erl
Expand Up @@ -201,7 +201,7 @@ success() ->
%%% INIT/TERMINATE EXPORTS
%%%-----------------------------------------------------------------------------
init([Silent]) ->
{A1, A2, A3} = now(),
{A1, A2, A3} = ?NOW(),
random:seed(A1, A2, A3),
{ok, #st{silent = Silent}}.

Expand Down

0 comments on commit 981a278

Please sign in to comment.