Skip to content

Commit

Permalink
Fixed a bug which was causing slow clients to be disconnected a few s…
Browse files Browse the repository at this point in the history
…econds after they sent messages while polling.
  • Loading branch information
omarkj committed Mar 25, 2011
1 parent 1954f07 commit d8484c7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/socketio_transport_polling.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ init([Sup, SessionId, {TransportType, Req}]) ->
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Incoming data %% 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(), Data = Req:parse_post(),
Self = self(), Self = self(),
Response = Response =
case cors_headers(Req:get(headers), Sup) of case cors_headers(Req:get(headers), Sup) of
{false, _Headers} -> {false, _Headers} ->
Req:respond(405, "unauthorized"); gen_server:reply(From, Req:respond(405, "unauthorized"));
{_, Headers0} -> {_, Headers0} ->
Data = Req:parse_post(), Data = Req:parse_post(),
Self = self(), Self = self(),
Expand All @@ -119,7 +119,7 @@ handle_call({_TransportType, data, Req}, _From, #state{ event_manager = EventMan
F(socketio_data:decode(#msg{content=M})) F(socketio_data:decode(#msg{content=M}))
end) end)
end, Data), end, Data),
Req:ok([Headers0|[{"Content-Type", "text/plain"}]], "ok") gen_server:reply(From, Req:ok([Headers0|[{"Content-Type", "text/plain"}]], "ok"))
end, end,
{reply, Response, State}; {reply, Response, State};


Expand Down Expand Up @@ -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) -> handle_cast({send, Message}, #state{ connection_reference = {_TransportType, none}, message_buffer = Buffer } = State) ->
{noreply, State#state{ message_buffer = lists:append(Buffer, [Message])}}; {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)), 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) -> handle_cast(_, State) ->
{noreply, State}. {noreply, State}.
Expand All @@ -180,7 +181,7 @@ handle_cast(_, State) ->
%% {stop, Reason, State} %% {stop, Reason, State}
%% @end %% @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}; {noreply, State#state { connection_reference = {TransportType, none}}, CloseTimeout};


%% Connection has timed out %% Connection has timed out
Expand Down

0 comments on commit d8484c7

Please sign in to comment.