Permalink
Browse files

Fixed a bug which was causing slow clients to be disconnected a few s…

…econds after they sent messages while polling.
  • Loading branch information...
1 parent 1954f07 commit d8484c76d0740eaddfb8c85022b7df2f1f482a01 @omarkj omarkj committed Mar 25, 2011
Showing with 7 additions and 6 deletions.
  1. +7 −6 src/socketio_transport_polling.erl
@@ -101,13 +101,13 @@ init([Sup, SessionId, {TransportType, Req}]) ->
%% @end
%%--------------------------------------------------------------------
%% Incoming data
-handle_call({_TransportType, data, Req}, _From, #state{ event_manager = EventManager, sup = Sup } = State) ->
+handle_call({_TransportType, data, Req}, From, #state{ event_manager = EventManager, sup = Sup } = State) ->
Data = Req:parse_post(),
Self = self(),
Response =
case cors_headers(Req:get(headers), Sup) of
{false, _Headers} ->
- Req:respond(405, "unauthorized");
+ gen_server:reply(From, Req:respond(405, "unauthorized"));
{_, Headers0} ->
Data = Req:parse_post(),
Self = self(),
@@ -119,7 +119,7 @@ handle_call({_TransportType, data, Req}, _From, #state{ event_manager = EventMan
F(socketio_data:decode(#msg{content=M}))
end)
end, Data),
- Req:ok([Headers0|[{"Content-Type", "text/plain"}]], "ok")
+ gen_server:reply(From, Req:ok([Headers0|[{"Content-Type", "text/plain"}]], "ok"))
end,
{reply, Response, State};
@@ -162,9 +162,10 @@ handle_cast({TransportType, polling_request, Req, Server}, #state { message_buff
handle_cast({send, Message}, #state{ connection_reference = {_TransportType, none}, message_buffer = Buffer } = State) ->
{noreply, State#state{ message_buffer = lists:append(Buffer, [Message])}};
-handle_cast({send, Message}, #state{ connection_reference = {TransportType, connected }, req = Req, caller = Caller, index = Index, sup = Sup} = State) -> %% FIXME: SOLUTION FOR BELOW IS TO MATCH ON INDEX=UNDEF HERE
+handle_cast({send, Message}, #state{ connection_reference = {TransportType, connected }, req = Req, caller = Caller,
+ index = Index, sup = Sup, polling_duration = Interval} = State) ->
gen_server:reply(Caller, send_message(Message, Req, Index, Sup)),
- {noreply, State#state{ connection_reference = {TransportType, none}}};
+ {noreply, State#state{ connection_reference = {TransportType, none}}, Interval};
handle_cast(_, State) ->
{noreply, State}.
@@ -180,7 +181,7 @@ handle_cast(_, State) ->
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
-handle_info({'EXIT',_Port,_Reason}, #state{ connection_reference = {TransportType, _ }, close_timeout = CloseTimeout} = State) when is_port(_Port) ->
+handle_info({'EXIT',Port,_Reason}, #state{ connection_reference = {TransportType, _ }, close_timeout = CloseTimeout} = State) when is_port(Port) ->
{noreply, State#state { connection_reference = {TransportType, none}}, CloseTimeout};
%% Connection has timed out

0 comments on commit d8484c7

Please sign in to comment.