aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-12-22 18:32:35 +0100
committerLoïc Hoguin <[email protected]>2012-12-22 18:32:35 +0100
commit31c7bf7234a7ec89f791fa8ec76ada6e89166d6d (patch)
treedb1dc3d6baf9807ea88b289f9d07a06e4432ca00 /src
parent7ff2a62585258e65830e80d5ac0abb75b9c1cf0b (diff)
parent5f122d9fa670f9c239f3f68b4053b35884704f9e (diff)
downloadcowboy-31c7bf7234a7ec89f791fa8ec76ada6e89166d6d.tar.gz
cowboy-31c7bf7234a7ec89f791fa8ec76ada6e89166d6d.tar.bz2
cowboy-31c7bf7234a7ec89f791fa8ec76ada6e89166d6d.zip
Merge branch 'fix-websocket-timeout' of git://github.com/jeremyong/cowboy
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_websocket.erl24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index 8b01522..8c02ac7 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -188,7 +188,8 @@ websocket_handshake(State=#state{transport=Transport, challenge=Challenge},
Req),
%% Flush the resp_sent message before moving on.
receive {cowboy_req, resp_sent} -> ok after 0 -> ok end,
- handler_before_loop(State#state{messages=Transport:messages()},
+ State2 = handler_loop_timeout(State),
+ handler_before_loop(State2#state{messages=Transport:messages()},
Req2, HandlerState, <<>>).
-spec handler_before_loop(#state{}, cowboy_req:req(), any(), binary()) -> closed.
@@ -196,15 +197,13 @@ handler_before_loop(State=#state{
socket=Socket, transport=Transport, hibernate=true},
Req, HandlerState, SoFar) ->
Transport:setopts(Socket, [{active, once}]),
- State2 = handler_loop_timeout(State),
catch erlang:hibernate(?MODULE, handler_loop,
- [State2#state{hibernate=false}, Req, HandlerState, SoFar]),
+ [State#state{hibernate=false}, Req, HandlerState, SoFar]),
closed;
handler_before_loop(State=#state{socket=Socket, transport=Transport},
Req, HandlerState, SoFar) ->
Transport:setopts(Socket, [{active, once}]),
- State2 = handler_loop_timeout(State),
- handler_loop(State2, Req, HandlerState, SoFar).
+ handler_loop(State, Req, HandlerState, SoFar).
-spec handler_loop_timeout(#state{}) -> #state{}.
handler_loop_timeout(State=#state{timeout=infinity}) ->
@@ -222,7 +221,8 @@ handler_loop(State=#state{
Req, HandlerState, SoFar) ->
receive
{OK, Socket, Data} ->
- websocket_data(State, Req, HandlerState,
+ State2 = handler_loop_timeout(State),
+ websocket_data(State2, Req, HandlerState,
<< SoFar/binary, Data/binary >>);
{Closed, Socket} ->
handler_terminate(State, Req, HandlerState, {error, closed});
@@ -460,7 +460,8 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
when is_tuple(Payload) ->
case websocket_send(Payload, State) of
ok ->
- NextState(State, Req2, HandlerState2, RemainingData);
+ State2 = handler_loop_timeout(State),
+ NextState(State2, Req2, HandlerState2, RemainingData);
shutdown ->
handler_terminate(State, Req2, HandlerState,
{normal, shutdown});
@@ -471,7 +472,8 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
when is_tuple(Payload) ->
case websocket_send(Payload, State) of
ok ->
- NextState(State#state{hibernate=true},
+ State2 = handler_loop_timeout(State),
+ NextState(State2#state{hibernate=true},
Req2, HandlerState2, RemainingData);
shutdown ->
handler_terminate(State, Req2, HandlerState,
@@ -483,7 +485,8 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
when is_list(Payload) ->
case websocket_send_many(Payload, State) of
ok ->
- NextState(State, Req2, HandlerState2, RemainingData);
+ State2 = handler_loop_timeout(State),
+ NextState(State2, Req2, HandlerState2, RemainingData);
shutdown ->
handler_terminate(State, Req2, HandlerState,
{normal, shutdown});
@@ -494,7 +497,8 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
when is_list(Payload) ->
case websocket_send_many(Payload, State) of
ok ->
- NextState(State#state{hibernate=true},
+ State2 = handler_loop_timeout(State),
+ NextState(State2#state{hibernate=true},
Req2, HandlerState2, RemainingData);
shutdown ->
handler_terminate(State, Req2, HandlerState,