summaryrefslogtreecommitdiff
path: root/lib/percept
diff options
context:
space:
mode:
authorAhmed Omar <spawn.think@gmail.com>2010-12-16 11:45:10 +0100
committerBjörn-Egil Dahlberg <psyeugenic@gmail.com>2010-12-29 18:33:09 +0100
commit50d40fd0bf6c796e7acf20fc2ca377cfca734251 (patch)
tree7cf0ce4afc856f17de3f3a7c59be4177e37940f3 /lib/percept
parent99e34bba1a60b262e24496cc9288b549360c6377 (diff)
downloaderlang-50d40fd0bf6c796e7acf20fc2ca377cfca734251.tar.gz
Fixes a bug found in percept:stop_webserver/1, where it doesn't stop the webserver completely
percept:stop_webserver/1 will only stop the httpd service in inets, but not the percept_httpd process. As a result, when trying to start the webserver again it will return {error, already_started}. Test case was updated to simulate this case and fix is included to stop the webserver in a consistent way wether stop_webserver/0 or stop_webserver/1 was used.
Diffstat (limited to 'lib/percept')
-rw-r--r--lib/percept/src/percept.erl32
-rw-r--r--lib/percept/test/percept_SUITE.erl2
2 files changed, 24 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..803ce6b95f 100644
--- a/lib/percept/test/percept_SUITE.erl
+++ b/lib/percept/test/percept_SUITE.erl
@@ -70,6 +70,8 @@ webserver(Config) when is_list(Config) ->
% Explicit start inets?
?line {started, _, Port} = percept:start_webserver(),
?line ok = percept:stop_webserver(Port),
+ ?line {started, _, NewPort} = percept:start_webserver(),
+ ?line ok = percept:stop_webserver(NewPort),
?line application:stop(inets),
ok.