Browse files

Fixing issue #44

When trying to start the socketio_listener more than once, we crash
the application.

This patch makes it so we always return the Pid if the initial process
was already started, to deal with the issue transparently.
  • Loading branch information...
1 parent 6763645 commit 8578f0f54895238caa71db214014e86df1406cea @ferd ferd committed Jun 11, 2011
Showing with 12 additions and 4 deletions.
  1. +2 −0 demo/demo.erl
  2. +10 −4 src/socketio_listener.erl
View
2 demo/demo.erl
@@ -12,6 +12,8 @@ main(_) ->
application:start(socketio),
{ok, Pid} = socketio_listener:start([{http_port, 7878},
{default_http_handler,?MODULE}]),
+ {ok, Pid} = socketio_listener:start([{http_port, 7878},
+ {default_http_handler,?MODULE}]),
EventMgr = socketio_listener:event_manager(Pid),
ok = gen_event:add_handler(EventMgr, ?MODULE,[]),
receive _ -> ok end.
View
14 src/socketio_listener.erl
@@ -24,10 +24,16 @@
%%%===================================================================
start(Options) ->
- {ok, Pid} = supervisor:start_child(socketio_listener_sup_sup, [Options]),
- Children = supervisor:which_children(Pid),
- {_, Listener, _, _} = lists:keyfind(socketio_listener, 1, Children),
- {ok, Listener}.
+ case supervisor:start_child(socketio_listener_sup_sup, [Options]) of
+ {ok, Pid} ->
+ Children = supervisor:which_children(Pid),
+ {_, Listener, _, _} = lists:keyfind(socketio_listener, 1, Children),
+ {ok, Listener};
+ {error,{already_started, Pid}} ->
+ Children = supervisor:which_children(Pid),
+ {_, Listener, _, _} = lists:keyfind(socketio_listener, 1, Children),
+ {ok, Listener}
+ end.
server(Sup) ->
Children = supervisor:which_children(Sup),

0 comments on commit 8578f0f

Please sign in to comment.