Skip to content
Browse files

simplify sanity_check

  • Loading branch information...
1 parent 0da38b4 commit 059a19efb47fec0e0c3a6273abc97e1455d097d1 @RJ committed Nov 22, 2011
Showing with 4 additions and 12 deletions.
  1. +4 −12 src/misultin_websocket_draft-hybi-10_17.erl
View
16 src/misultin_websocket_draft-hybi-10_17.erl
@@ -256,7 +256,7 @@ i_handle_data(#state{buffer=ToParse} = State, {Socket, SocketMode, WsHandleLoopP
?LOG_DEBUG("parsed frame ~p, remaining buffer is: ~p", [Frame,Rest]),
%% sanity check, in case client is broken
case sanity_check(Frame) of
- ok ->
+ true ->
?LOG_DEBUG("sanity checks successfully performed",[]),
case handle_frame(Frame,
State#state{buffer = Rest},
@@ -267,30 +267,22 @@ i_handle_data(#state{buffer=ToParse} = State, {Socket, SocketMode, WsHandleLoopP
Other ->
Other
end;
- protocol_error ->
+ false -> % protocol error
?LOG_DEBUG("sanity checks errors encountered, closing websocket",[]),
{websocket_close, websocket_close_data()}
end
end.
% format sanity checks
--spec sanity_check(#frame{}) -> ok | protocol_error.
+-spec sanity_check(#frame{}) -> true | false.
sanity_check(Frame) ->
Checks = [
{1, Frame#frame.maskbit},
{0, Frame#frame.rsv1},
{0, Frame#frame.rsv2},
{0, Frame#frame.rsv3}
],
- ChecksVerified = lists:dropwhile(
- fun ({A, A}) -> true;
- ({_A, _}) -> false
- end, Checks
- ),
- case ChecksVerified of
- [] -> ok;
- _ -> protocol_error
- end.
+ lists:foldl(fun({A,B}, Acc) -> Acc andalso (A =:= B) end, true, Checks).
% ---------------------------- /\ frame parsing ------------------------------------------------------------

0 comments on commit 059a19e

Please sign in to comment.
Something went wrong with that request. Please try again.