Permalink
Browse files

store path and pid in shared memory

  • Loading branch information...
1 parent 5739c52 commit 095a8d11c72608ad338c2274ddeb19185521218d @dje committed May 15, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 jellyfish.erl
View
10 jellyfish.erl
@@ -2,11 +2,13 @@
-export([start/1, stop/0]).
start(Port) ->
+ ets:new(map, [public,named_table,bag]),
misultin:start_link([{port, Port},
{loop, fun(Req) -> route_rest(Req) end},
{ws_loop, fun(Ws) -> handle_websocket(Ws) end}]).
-stop() -> misultin:stop().
+stop() -> ets:delete(map),
+ misultin:stop().
route_rest(Req) ->
handle_r(Req:get(method), Req:resource([lowercase, urldecode]), Req).
@@ -21,12 +23,12 @@ handle_r(_, _, Req) ->
handle_websocket(Ws) ->
receive
+ {browser, Data} ->
+ ets:insert(map, { Ws:get(path), self() }),
+ handle_websocket(Ws);
{event} ->
Ws:send("event"),
handle_websocket(Ws);
_Ignore ->
handle_websocket(Ws)
- after 5000 ->
- Ws:send([Ws:get(path), pid_to_list(self())]),
- handle_websocket(Ws)
end.

0 comments on commit 095a8d1

Please sign in to comment.