aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percept/src/percept.erl
diff options
context:
space:
mode:
authorAhmed Omar <[email protected]>2010-12-16 11:45:10 +0100
committerBjörn-Egil Dahlberg <[email protected]>2010-12-29 18:33:09 +0100
commit50d40fd0bf6c796e7acf20fc2ca377cfca734251 (patch)
tree7cf0ce4afc856f17de3f3a7c59be4177e37940f3 /lib/percept/src/percept.erl
parent99e34bba1a60b262e24496cc9288b549360c6377 (diff)
downloadotp-50d40fd0bf6c796e7acf20fc2ca377cfca734251.tar.gz
otp-50d40fd0bf6c796e7acf20fc2ca377cfca734251.tar.bz2
otp-50d40fd0bf6c796e7acf20fc2ca377cfca734251.zip
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/src/percept.erl')
-rw-r--r--lib/percept/src/percept.erl32
1 files changed, 22 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,[]).
%%==========================================================================
%%