aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percept
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2010-12-29 18:37:21 +0100
committerBjörn-Egil Dahlberg <[email protected]>2010-12-29 18:37:25 +0100
commit99372cc4053c2fa7662da2f871c9813fbf45ba7e (patch)
tree68fc7986c118ffc247fb02ed9f0890ef95388773 /lib/percept
parentdb945cc0cb32457903854d9b4b1c00af3d68cde6 (diff)
parentb5505246856d905d3981f8e1f82dbd3ca08a6ead (diff)
downloadotp-99372cc4053c2fa7662da2f871c9813fbf45ba7e.tar.gz
otp-99372cc4053c2fa7662da2f871c9813fbf45ba7e.tar.bz2
otp-99372cc4053c2fa7662da2f871c9813fbf45ba7e.zip
Merge branch 'ao/percept-web-stop-rebased' into dev
* ao/percept-web-stop-rebased: Verifies the consistency of stopping behavior. Fixes a bug found in percept:stop_webserver/1, where it doesn't stop the webserver completely OTP-9012
Diffstat (limited to 'lib/percept')
-rw-r--r--lib/percept/src/percept.erl32
-rw-r--r--lib/percept/test/percept_SUITE.erl4
2 files changed, 26 insertions, 10 deletions
diff --git a/lib/percept/src/percept.erl b/lib/percept/src/percept.erl
index f5e0f7e469..3a2d9f7601 100644
--- a/lib/percept/src/percept.erl
+++ b/lib/percept/src/percept.erl
@@ -185,10 +185,27 @@ stop_webserver() ->
undefined ->
{error, not_started};
Pid ->
- Pid ! {self(), get_port},
- receive Port -> ok end,
- Pid ! quit,
- stop_webserver(Port)
+ do_stop([], Pid)
+ end.
+
+do_stop([], Pid)->
+ Pid ! {self(), get_port},
+ Port = receive P -> P end,
+ do_stop(Port, Pid);
+do_stop(Port, [])->
+ case whereis(percept_httpd) of
+ undefined ->
+ {error, not_started};
+ Pid ->
+ do_stop(Port, Pid)
+ end;
+do_stop(Port, Pid)->
+ case find_service_pid_from_port(inets:services_info(), Port) of
+ undefined ->
+ {error, not_started};
+ Pid2 ->
+ Pid ! quit,
+ inets:stop(httpd, Pid2)
end.
%% @spec stop_webserver(integer()) -> ok | {error, not_started}
@@ -196,12 +213,7 @@ stop_webserver() ->
%% @hidden
stop_webserver(Port) ->
- case find_service_pid_from_port(inets:services_info(), Port) of
- undefined ->
- {error, not_started};
- Pid ->
- inets:stop(httpd, Pid)
- end.
+ do_stop(Port,[]).
%%==========================================================================
%%
diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl
index ff7cccdaa8..964ac68481 100644
--- a/lib/percept/test/percept_SUITE.erl
+++ b/lib/percept/test/percept_SUITE.erl
@@ -70,6 +70,10 @@ webserver(Config) when is_list(Config) ->
% Explicit start inets?
?line {started, _, Port} = percept:start_webserver(),
?line ok = percept:stop_webserver(Port),
+ ?line {started, _, _} = percept:start_webserver(),
+ ?line ok = percept:stop_webserver(),
+ ?line {started, _, NewPort} = percept:start_webserver(),
+ ?line ok = percept:stop_webserver(NewPort),
?line application:stop(inets),
ok.