aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-11-27 16:42:02 +0100
committerLoïc Hoguin <[email protected]>2012-11-27 16:42:02 +0100
commitbb07b48d7f821ce3ec295837f7ec8ebd8da2cf35 (patch)
treea52924066ec07a988507eddee97892e8bb13abb1
parentf63d3f08cf942433ba068ed2a78c69530a642452 (diff)
parent9b0049fdd77a1e717b7647af2edcd2872201ac89 (diff)
downloadcowboy-bb07b48d7f821ce3ec295837f7ec8ebd8da2cf35.tar.gz
cowboy-bb07b48d7f821ce3ec295837f7ec8ebd8da2cf35.tar.bz2
cowboy-bb07b48d7f821ce3ec295837f7ec8ebd8da2cf35.zip
Merge branch 'fix/websocket-check-error-on-send' of git://github.com/tillitech/cowboy
-rw-r--r--src/cowboy_websocket.erl42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index 1c6d20c..515c6d4 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -452,22 +452,38 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
Req2, HandlerState2, RemainingData);
{reply, Payload, Req2, HandlerState2}
when is_tuple(Payload) ->
- ok = websocket_send(Payload, State),
- NextState(State, Req2, HandlerState2, RemainingData);
+ case websocket_send(Payload, State) of
+ ok ->
+ NextState(State, Req2, HandlerState2, RemainingData);
+ {error, _} = Error ->
+ handler_terminate(State, Req2, HandlerState2, Error)
+ end;
{reply, Payload, Req2, HandlerState2, hibernate}
when is_tuple(Payload) ->
- ok = websocket_send(Payload, State),
- NextState(State#state{hibernate=true},
- Req2, HandlerState2, RemainingData);
+ case websocket_send(Payload, State) of
+ ok ->
+ NextState(State#state{hibernate=true},
+ Req2, HandlerState2, RemainingData);
+ {error, _} = Error ->
+ handler_terminate(State, Req2, HandlerState2, Error)
+ end;
{reply, Payload, Req2, HandlerState2}
when is_list(Payload) ->
- ok = websocket_send_many(Payload, State),
- NextState(State, Req2, HandlerState2, RemainingData);
+ case websocket_send_many(Payload, State) of
+ ok ->
+ NextState(State, Req2, HandlerState2, RemainingData);
+ {error, _} = Error ->
+ handler_terminate(State, Req2, HandlerState2, Error)
+ end;
{reply, Payload, Req2, HandlerState2, hibernate}
when is_list(Payload) ->
- ok = websocket_send_many(Payload, State),
- NextState(State#state{hibernate=true},
- Req2, HandlerState2, RemainingData);
+ case websocket_send_many(Payload, State) of
+ ok ->
+ NextState(State#state{hibernate=true},
+ Req2, HandlerState2, RemainingData);
+ {error, _} = Error ->
+ handler_terminate(State, Req2, HandlerState2, Error)
+ end;
{shutdown, Req2, HandlerState2} ->
websocket_close(State, Req2, HandlerState2, {normal, shutdown})
catch Class:Reason ->
@@ -507,8 +523,10 @@ websocket_send({Type, Payload}, #state{socket=Socket, transport=Transport}) ->
websocket_send_many([], _) ->
ok;
websocket_send_many([Frame|Tail], State) ->
- ok = websocket_send(Frame, State),
- websocket_send_many(Tail, State).
+ case websocket_send(Frame, State) of
+ ok -> websocket_send_many(Tail, State);
+ Error -> Error
+ end.
-spec websocket_close(#state{}, cowboy_req:req(), any(), {atom(), atom()})
-> closed.