diff --git a/doc/examples/sample_mc.erl b/doc/examples/sample_mc.erl index 3e83868..da8f29f 100644 --- a/doc/examples/sample_mc.erl +++ b/doc/examples/sample_mc.erl @@ -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}}. diff --git a/include/oserl.hrl b/include/oserl.hrl index 5926372..d3e9bd0 100644 --- a/include/oserl.hrl +++ b/include/oserl.hrl @@ -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) diff --git a/rebar.config b/rebar.config index 6d86061..9213cb6 100644 --- a/rebar.config +++ b/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", diff --git a/src/smpp_disk_log_hlr.erl b/src/smpp_disk_log_hlr.erl index cf4db4d..1de2603 100644 --- a/src/smpp_disk_log_hlr.erl +++ b/src/smpp_disk_log_hlr.erl @@ -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, diff --git a/src/smpp_param.hrl b/src/smpp_param.hrl index 1a6b676..d50c494 100644 --- a/src/smpp_param.hrl +++ b/src/smpp_param.hrl @@ -1,3 +1,5 @@ +%% coding: latin-1 + %%% Copyright (C) 2009 Enrique Marcote, Miguel Rodriguez %%% All rights reserved. %%% diff --git a/src/smpp_session.erl b/src/smpp_session.erl index 97975ae..073286f 100644 --- a/src/smpp_session.erl +++ b/src/smpp_session.erl @@ -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 @@ -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} -> @@ -223,7 +223,7 @@ handle_accept(Pid, Sock) -> handle_input(Pid, <> = 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 <> -> diff --git a/test/gen_esme_SUITE.erl b/test/gen_esme_SUITE.erl index 743e1f8..d471d6d 100644 --- a/test/gen_esme_SUITE.erl +++ b/test/gen_esme_SUITE.erl @@ -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(), diff --git a/test/gen_mc_SUITE.erl b/test/gen_mc_SUITE.erl index f84086a..44b354d 100644 --- a/test/gen_mc_SUITE.erl +++ b/test/gen_mc_SUITE.erl @@ -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(), diff --git a/test/operation_SUITE.erl b/test/operation_SUITE.erl index 47408cc..3467c70 100644 --- a/test/operation_SUITE.erl +++ b/test/operation_SUITE.erl @@ -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]), diff --git a/test/test_mc.erl b/test/test_mc.erl index 3f739bd..e0f99e8 100644 --- a/test/test_mc.erl +++ b/test/test_mc.erl @@ -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}}.