Permalink
Browse files

Everything exept UTF8 killer string works great

  • Loading branch information...
1 parent 268defb commit 7c9f431a15e0ef0073cd3fa08159b957bf9463fb @egobrain committed Dec 30, 2011
Showing with 11 additions and 35 deletions.
  1. +1 −9 src/sockjs.erl
  2. +10 −26 src/sockjs_session.erl
View
@@ -5,8 +5,6 @@
-define(STILL_OPEN, {2010, "Another connection still open"}).
--include("../../../src/include/log.hrl").
-
-define(IFRAME, "<!DOCTYPE html>
<html>
<head>
@@ -239,23 +237,17 @@ reply_loop(Req, SessionId, Once, Fmt) ->
{ok, Heartbeat} = application:get_env(sockjs, heartbeat_ms),
case sockjs_session:reply(SessionId, Once, Req) of
wait ->
- ?DBG("wait"),
receive
- go ->
- ?DBG("go"),
- reply_loop(Req, SessionId, Once, Fmt)
+ go ->reply_loop(Req, SessionId, Once, Fmt)
after Heartbeat ->
- ?DBG("heart"),
chunk(Req, <<"h">>, Fmt),
reply_loop0(Req, SessionId, Once, Fmt)
end;
session_in_use ->
- ?DBG("in use"),
Err = sockjs_util:encode_list([{close, ?STILL_OPEN}]),
chunk(Req, Err, Fmt),
Req:chunk(done);
Reply ->
- ?DBG(Reply),
chunk(Req, Reply, Fmt),
reply_loop0(Req, SessionId, Once, Fmt)
end.
@@ -3,17 +3,15 @@
-behaviour(sockjs_sender).
-behaviour(gen_server).
--include("../../../src/include/log.hrl").
-
--export([init/0, start_link/2, maybe_create/2, sender/1, reply/3]).
+-export([start_link/2, maybe_create/2, sender/1, reply/3]).
-export([send/2, close/3, session/1]).
-export([init/1, handle_call/3, handle_info/2, terminate/2, code_change/3,
handle_cast/2]).
-record(session, {id,
- outbound_queue = queue:new(),
+ outbound_queue,
response_pid,
receiver,
session_timeout,
@@ -22,9 +20,6 @@
ws_loop
}).
-init() ->
- ok.
-
start_link(SessionId, Receive) ->
gen_server:start_link(?MODULE, {SessionId, Receive}, []).
@@ -39,7 +34,6 @@ maybe_create(SessionId, Loop) ->
{error,already_present} ->
gproc:lookup_local_name(SessionId);
{ok,SPid} ->
- enqueue({open, nil}, SessionId),
SPid
end.
@@ -63,9 +57,7 @@ reply(SessionId, Once, Req) ->
%% --------------------------------------------------------------------------
-
pop_from_queue(Q) ->
-
{PoppedRev, Rest} = pop_from_queue(any, [], Q),
{lists:reverse(PoppedRev), Rest}.
@@ -79,7 +71,7 @@ pop_from_queue(TypeAcc, Acc, Q) ->
spid(SessionId) ->
case gproc:lookup_local_name(SessionId) of
- undefined ->
+ undefined ->
throw(no_session);
SPid -> SPid
end.
@@ -107,40 +99,32 @@ init({SessionId, Loop}) ->
gproc:add_local_name(SessionId),
process_flag(trap_exit, true),
WS_LOOP = spawn_link(fun() ->
-% try
+ try
Loop({?MODULE, SessionId})
-% catch
-% throw:no_session ->
-% exit(normal)
-% end
+ catch
+ throw:no_session ->
+ exit(no_session)
+ end
end),
- {ok, #session{id = SessionId, receiver = Loop, ws_loop = WS_LOOP}}.
+ {ok, #session{id = SessionId, receiver = Loop, ws_loop = WS_LOOP, outbound_queue=queue:in({open,nil},queue:new())}}.
%% For non-streaming transports we want to send a closed message every time
%% we are asked - for streaming transports we only want to send it once.
handle_call({reply, Pid, true,_Req}, _From, State = #session{closed = true, close_msg = Msg}) ->
- ?DBG(Msg),
reply3(sockjs_util:encode_list(Msg), Pid, State);
handle_call({reply, Pid, _Once, Req}, From, State = #session{response_pid = RPid, outbound_queue = Q}) ->
- ?DBG(pop_from_queue(Q)),
case {pop_from_queue(Q), RPid} of
{{[], _}, P} when P =:= undefined orelse P =:= Pid ->
reply3(wait, Pid, State);
{{[], _}, _} ->
%% don't use reply(), this shouldn't touch the session lifetime
{reply, session_in_use, State};
{{Popped, Rest}, _} ->
- ?DBG("Popped: ~p~n",[Popped]),
case Popped of
[{session,To}] ->
- ?DBG("session"),
- Session = Req:session(),
- ?DBG(Session),
- Res = gen_server:reply(To,Session),
- ?DBG(Res),
+ gen_server:reply(To,Req:session()),
handle_call({reply,Pid,_Once,Req},From, State#session{outbound_queue = Rest});
_ ->
- ?DBG("other ~p"),
State1 = maybe_close(Popped, State),
reply3(sockjs_util:encode_list(Popped), Pid,State1#session{outbound_queue = Rest})
end

0 comments on commit 7c9f431

Please sign in to comment.