From 1132117b38cfe33e770a0d5b1a782d48667427c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Thu, 5 Mar 2015 13:37:16 +0100 Subject: Use new time API and be back-compatible in inets Remove unused functions and removed redundant test --- lib/inets/test/httpd_time_test.erl | 44 ++++++++++---------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) (limited to 'lib/inets/test/httpd_time_test.erl') diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index 0bb457f9b9..0c27f47aa9 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2001-2011. All Rights Reserved. +%% Copyright Ericsson AB 2001-2015. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -122,7 +122,7 @@ loop(Pollers, Timeout) -> case is_poller(Pid, Pollers) of true -> error_msg("received unexpected exit from poller ~p~n" - "befor completion of test " + "before completion of test " "after ~p micro sec" "~n SocketType: ~p" "~n Host: ~p" @@ -412,35 +412,6 @@ validate(ExpStatusCode, _SocketType, _Socket, Response) -> end. -trash_the_rest(Socket, N) -> - receive - {ssl, Socket, Trash} -> - trash_the_rest(Socket, add(N,sz(Trash))); - {ssl_closed, Socket} -> - N; - {ssl_error, Socket, Error} -> - exit({connection_error, Error}); - - {tcp, Socket, Trash} -> - trash_the_rest(Socket, add(N,sz(Trash))); - {tcp_closed, Socket} -> - N; - {tcp_error, Socket, Error} -> - exit({connection_error, Error}) - - after 10000 -> - exit({connection_timed_out, N}) - end. - - -add(N1,N2) when is_integer(N1) andalso is_integer(N2) -> - N1 + N2; -add(N1,_) when is_integer(N1) -> - N1; -add(_,N2) when is_integer(N2) -> - N2. - - sz(L) when is_list(L) -> length(lists:flatten(L)); sz(B) when is_binary(B) -> @@ -510,8 +481,15 @@ to(To, Start) -> %% Time in milli seconds t() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). + %% Adapt to OTP 18 erlang time API and be back-compatible + try + erlang:monotonic_time(1000) + catch + error:undef -> + %% Use Erlang system time as monotonic time + {A,B,C} = erlang:now(), + A*1000000000+B*1000+(C div 1000) + end. %% ---------------------------------------------------------------- -- cgit v1.2.3 From f4a774425a440caa912da71cfb8c0c70df4df69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Mon, 9 Mar 2015 11:16:01 +0100 Subject: Suppress deprecated warning on erlang:now/0 --- lib/inets/test/httpd_time_test.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/inets/test/httpd_time_test.erl') diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index 0c27f47aa9..43bafe5714 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -18,6 +18,7 @@ %% %% -module(httpd_time_test). +-compile([{nowarn_deprecated_function,{erlang,now,0}}]). -export([t/3, t1/2, t2/2, t4/2]). -- cgit v1.2.3 From 87ae700c7383b74b8ddade6bfe30481dcdc5b6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Fri, 13 Mar 2015 10:12:57 +0100 Subject: inets: Update comments --- lib/inets/test/httpd_time_test.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/inets/test/httpd_time_test.erl') diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index 43bafe5714..b2a2075520 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -482,7 +482,7 @@ to(To, Start) -> %% Time in milli seconds t() -> - %% Adapt to OTP 18 erlang time API and be back-compatible + %% Adapt to OTP 18 erlang time API and be backwards compatible try erlang:monotonic_time(1000) catch -- cgit v1.2.3 From 7cdde7537deccd53d95d03860379f3d20ad2e265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Tue, 17 Mar 2015 11:56:14 +0100 Subject: inets: Cleanup of multiple copies of functions Add inets_lib with common functions used by multiple modules --- lib/inets/test/httpd_time_test.erl | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'lib/inets/test/httpd_time_test.erl') diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index b2a2075520..b3e6746a01 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -117,7 +117,16 @@ main(N, SocketType, Host, Port, Time) loop(Pollers, Timeout) -> d("loop -> entry when" "~n Timeout: ~p", [Timeout]), - Start = t(), + %% Adapt to OTP 18 erlang time API and be backwards compatible + Start = try + erlang:monotonic_time(1000) + catch + error:undef -> + %% Use Erlang system time as monotonic time + {A,B,C} = erlang:now(), + A*1000000000+B*1000+(C div 1000) + end, + receive {'EXIT', Pid, {poller_stat_failure, SocketType, Host, Port, Time, Reason}} -> case is_poller(Pid, Pollers) of @@ -134,7 +143,7 @@ loop(Pollers, Timeout) -> false -> error_msg("received unexpected ~p from ~p" "befor completion of test", [Reason, Pid]), - loop(Pollers, to(Timeout, Start)) + loop(Pollers, Timeout - inets_lib:millisec_passed(Start)) end; {poller_stat_failure, Pid, {SocketType, Host, Port, Time, Reason}} -> @@ -477,24 +486,6 @@ status_to_message(Code) -> io_lib:format("Unknown status code: ~p",[Code]). %% ---------------------------------------------------------------- -to(To, Start) -> - To - (t() - Start). - -%% Time in milli seconds -t() -> - %% Adapt to OTP 18 erlang time API and be backwards compatible - try - erlang:monotonic_time(1000) - catch - error:undef -> - %% Use Erlang system time as monotonic time - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000) - end. - - -%% ---------------------------------------------------------------- - % close(Socket) -> -- cgit v1.2.3