aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBob Ippolito <[email protected]>2012-04-24 11:38:27 -0700
committerBob Ippolito <[email protected]>2012-04-24 11:38:27 -0700
commit4a8ba147fb70809e8b1e42460ca7489e933399e8 (patch)
tree8791915710c659ff0d1961d769ce7600d89b68a6 /src
parentbc2d53d2a5e865ce36a0419c4d4698b30359415b (diff)
downloadcowboy-4a8ba147fb70809e8b1e42460ca7489e933399e8.tar.gz
cowboy-4a8ba147fb70809e8b1e42460ca7489e933399e8.tar.bz2
cowboy-4a8ba147fb70809e8b1e42460ca7489e933399e8.zip
use erlang:start_timer/3 instead of erlang:send_after/3 for handling timeouts
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_protocol.erl7
-rw-r--r--src/cowboy_http_websocket.erl7
2 files changed, 6 insertions, 8 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 04abfbc..9e4cca5 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -316,16 +316,15 @@ handler_loop_timeout(State=#state{loop_timeout=Timeout,
loop_timeout_ref=PrevRef}) ->
_ = case PrevRef of undefined -> ignore; PrevRef ->
erlang:cancel_timer(PrevRef) end,
- TRef = make_ref(),
- erlang:send_after(Timeout, self(), {?MODULE, timeout, TRef}),
+ TRef = erlang:start_timer(Timeout, self(), ?MODULE),
State#state{loop_timeout_ref=TRef}.
-spec handler_loop(any(), #http_req{}, #state{}) -> ok.
handler_loop(HandlerState, Req, State=#state{loop_timeout_ref=TRef}) ->
receive
- {?MODULE, timeout, TRef} ->
+ {timeout, TRef, ?MODULE} ->
terminate_request(HandlerState, Req, State);
- {?MODULE, timeout, OlderTRef} when is_reference(OlderTRef) ->
+ {timeout, OlderTRef, ?MODULE} when is_reference(OlderTRef) ->
handler_loop(HandlerState, Req, State);
Message ->
handler_call(HandlerState, Req, State, Message)
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index ab96e93..f3f1cae 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -232,8 +232,7 @@ handler_loop_timeout(State=#state{timeout=infinity}) ->
handler_loop_timeout(State=#state{timeout=Timeout, timeout_ref=PrevRef}) ->
_ = case PrevRef of undefined -> ignore; PrevRef ->
erlang:cancel_timer(PrevRef) end,
- TRef = make_ref(),
- erlang:send_after(Timeout, self(), {?MODULE, timeout, TRef}),
+ TRef = erlang:start_timer(Timeout, self(), ?MODULE),
State#state{timeout_ref=TRef}.
%% @private
@@ -248,9 +247,9 @@ handler_loop(State=#state{messages={OK, Closed, Error}, timeout_ref=TRef},
handler_terminate(State, Req, HandlerState, {error, closed});
{Error, Socket, Reason} ->
handler_terminate(State, Req, HandlerState, {error, Reason});
- {?MODULE, timeout, TRef} ->
+ {timeout, TRef, ?MODULE} ->
websocket_close(State, Req, HandlerState, {normal, timeout});
- {?MODULE, timeout, OlderTRef} when is_reference(OlderTRef) ->
+ {timeout, OlderTRef, ?MODULE} when is_reference(OlderTRef) ->
handler_loop(State, Req, HandlerState, SoFar);
Message ->
handler_call(State, Req, HandlerState,