From b1bbd023c54def70cf748ff78c02b8b021e87c18 Mon Sep 17 00:00:00 2001 From: Magnus Klaar Date: Sat, 10 Dec 2011 17:58:31 +0100 Subject: update /bits in binary expressions to /binary This is a workaround for an issue in the hipe compiler where compilation of code matching on binaries using patterns of the form Data = <> fails because _Ignore is expected to be used. Using /binary instead of /bits resolves the issue. We're applying this change to all binary expressions in cowboy_http because all functions in this module process human readable text formats which are always expected to be bytestrings. Two uses of /bits has been changed to /binary in cowboy_http_websocket in two clauses of a single function, websocket_data/4. This is safe to change because the data is later passed to binary:match/2 which will always fail with a badarg error if the input is a bitstring instead of a bytestring. --- src/cowboy_http_websocket.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cowboy_http_websocket.erl') diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl index 7013d7f..20060e6 100644 --- a/src/cowboy_http_websocket.erl +++ b/src/cowboy_http_websocket.erl @@ -244,11 +244,11 @@ websocket_data(State, Req, HandlerState, <<>>) -> handler_before_loop(State, Req, HandlerState, <<>>); %% hixie-76 close frame. websocket_data(State=#state{version=0}, Req, HandlerState, - << 255, 0, _Rest/bits >>) -> + << 255, 0, _Rest/binary >>) -> websocket_close(State, Req, HandlerState, {normal, closed}); %% hixie-76 data frame. We only support the frame type 0, same as the specs. websocket_data(State=#state{version=0, eop=EOP}, Req, HandlerState, - Data = << 0, _/bits >>) -> + Data = << 0, _/binary >>) -> case binary:match(Data, EOP) of {Pos, 1} -> Pos2 = Pos - 1, -- cgit v1.2.3