]> granicus.if.org Git - ejabberd/commitdiff
Receiving missing http-bind request shouldn't close waiting out-ouf-order request
authorPaweł Chmielowski <pchmielowski@process-one.net>
Wed, 2 May 2012 18:59:09 +0000 (20:59 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Thu, 3 May 2012 09:44:21 +0000 (11:44 +0200)
src/web/ejabberd_http_bind.erl

index 0108d4aa1c79fb008dfd0dfe158cb9246d51616c..0024cb17dc892f455ae96781ee7d0107da214b28 100644 (file)
@@ -441,8 +441,6 @@ handle_sync_event(#http_put{payload_size = PayloadSize} = Request,
 %% HTTP GET: send packets to the client
 handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) ->
     %% setup timer
-    send_receiver_reply(StateData#state.http_receiver, {ok, empty}),
-    cancel_timer(StateData#state.wait_timer),
     TNow = tnow(),
     if
        (Hold > 0) and
@@ -450,7 +448,9 @@ handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) ->
        ((TNow - StateData#state.ctime) < (Wait*1000*1000)) and
        (StateData#state.rid =< Rid) and
        (StateData#state.input /= cancel) and
-        (StateData#state.pause == 0) ->
+       (StateData#state.pause == 0) ->
+           send_receiver_reply(StateData#state.http_receiver, {ok, empty}),
+           cancel_timer(StateData#state.wait_timer),
            WaitTimer = erlang:start_timer(Wait * 1000, self(), []),
            %% MR: Not sure we should cancel the state timer here.
            cancel_timer(StateData#state.timer),
@@ -460,6 +460,8 @@ handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) ->
                                      wait_timer = WaitTimer,
                                      timer = undefined}};
        (StateData#state.input == cancel) ->
+           send_receiver_reply(StateData#state.http_receiver, {ok, empty}),
+           cancel_timer(StateData#state.wait_timer),
            cancel_timer(StateData#state.timer),
            Timer = set_inactivity_timer(StateData#state.pause,
                                         StateData#state.max_inactivity),
@@ -471,8 +473,6 @@ handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) ->
                                        timer = Timer}};
        true ->
            cancel_timer(StateData#state.timer),
-           Timer = set_inactivity_timer(StateData#state.pause,
-                                        StateData#state.max_inactivity),
            Reply = {ok, StateData#state.output},
            %% save request
            ReqList = [#hbr{rid = Rid,
@@ -482,12 +482,26 @@ handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) ->
                       [El || El <- StateData#state.req_list,
                              El#hbr.rid /= Rid ]
                      ],
-           {reply, Reply, StateName, StateData#state{
-                                       output = [],
-                                       http_receiver = undefined,
-                                       wait_timer = undefined,
-                                       timer = Timer,
-                                       req_list = ReqList}}
+           if
+                (StateData#state.http_receiver /= undefined) and
+                StateData#state.out_of_order_receiver ->
+                    {reply, Reply, StateName, StateData#state{
+                                                output = [],
+                                                timer = undefined,
+                                                req_list = ReqList,
+                                                out_of_order_receiver = false}};
+                true ->
+                    send_receiver_reply(StateData#state.http_receiver, {ok, empty}),
+                    cancel_timer(StateData#state.wait_timer),
+                    Timer = set_inactivity_timer(StateData#state.pause,
+                                                 StateData#state.max_inactivity),
+                    {reply, Reply, StateName,
+                     StateData#state{output = [],
+                                     http_receiver = undefined,
+                                     wait_timer = undefined,
+                                     timer = Timer,
+                                     req_list = ReqList}}
+            end
     end;
 
 handle_sync_event(peername, _From, StateName, StateData) ->