anchor.diff:          Other ->
               Other
       end;
  -
  -ws_frame_info(WSState = #ws_state{sock=Socket}, FirstPacket, Opts) ->
  -    ws_frame_info(WSState, buffer(Socket, 2, FirstPacket), Opts).
  -
  -
  -ws_frame_info_secondary(Socket, Masked, Len1, Rest, Opts) ->
  +ws_frame_info(_Packet, _Opts) ->
  +    frame_incomplete.
  +
  +
  +ws_frame_info_secondary(Masked, Len1, Rest, Opts) ->
       MaxLen = get_opts(max_frame_size, Opts),
       CloseIfUnmasked = get_opts(close_if_unmasked, Opts),
       MaskLength = case Masked of
                        0 -> 0;
                        1 -> 4
                    end,
  -    case Len1 of
  -        126 ->
  -            <<Len:16, MaskingKey:MaskLength/binary, Rest2/binary>> =
  -                buffer(Socket, MaskLength + 2 , Rest);
  -        127 ->
  -            <<Len:64, MaskingKey:MaskLength/binary, Rest2/binary>> =
  -                buffer(Socket, MaskLength + 8 , Rest);
  -        Len ->
  -            <<MaskingKey:MaskLength/binary, Rest2/binary>> =
  -                buffer(Socket, MaskLength, Rest)
  +    FirstCase = case {Len1, Rest} of
  +        {126, <<Len:16, MaskingKey:MaskLength/binary,
  +                Payload:Len/binary, Excess/binary>>} ->
  +            {Len, MaskingKey, Payload, Excess};
  +        {127, <<Len:64, MaskingKey:MaskLength/binary,
  +                Payload:Len/binary, Excess/binary>>} ->
  +            {Len, MaskingKey, Payload, Excess};
  +        {Len, <<MaskingKey:MaskLength/binary,
  +                Payload:Len1/binary, Excess/binary>>} when Len < 126 ->
  +            {Len, MaskingKey, Payload, Excess};
  +        {126, <<Len:16, _/binary>>} ->
  +            {Len, frame_incomplete};
  +        {127, <<Len:64, _/binary>>} ->
  +            {Len, frame_incomplete};
  +        Len when Len < 126 ->
  +            {Len, frame_incomplete};
  +        _ ->
  +            {unknown, frame_incomplete}
       end,
  -    if
  -        CloseIfUnmasked == true andalso MaskingKey == <<>> ->
  +    case FirstCase of
  +        {unknown, frame_incomplete} ->
  +            frame_incomplete;
  +        {Len0, _} when Len0 > MaxLen ->
  +            error_logger:error_msg(
  +                "Payload length ~p longer than max allowed of ~p",
  +                [Len0, MaxLen]
  +            ),
  +            {fail_connection, ?WS_STATUS_MSG_TOO_BIG, <<"Frame too big">>};
  +        {_, frame_incomplete} ->
  +            frame_incomplete;
  +        {_Len, <<>>, _Payload, _Excess} when CloseIfUnmasked == true ->
               error_logger:error_msg("Unmasked frame forbidden", []),
               {fail_connection, ?WS_STATUS_PROTO_ERROR,
                <<"Unmasked frame forbidden">>};
  -        Len > MaxLen ->
  -            error_logger:error_msg(
  -              "Payload length ~p longer than max allowed of ~p",
  -              [Len, MaxLen]
  -             ),
  -            {fail_connection, ?WS_STATUS_MSG_TOO_BIG, <<"Frame too big">>};
  -        true ->
  -            <<Payload:Len/binary, Excess/binary>> = buffer(Socket, Len, Rest2),
  -            {ws_frame_info_secondary, Len, MaskingKey, Payload, Excess}
  -    end.
  -
  -unframe_active_once(WSState, FirstPacket, Opts) ->
  -    Frames = unframe(WSState, FirstPacket, Opts),
  -    websocket_setopts(WSState, [{active, once}]),
  -    Frames.
  -
  +        {Len0, MaskingKey0, Payload0, Excess0} ->
  +            {ws_frame_info_secondary, Len0, MaskingKey0, Payload0, Excess0}
  +    end.
   
   %% Returns all the WebSocket frames fully or partially contained in FirstPacket,
   %% reading exactly as many more bytes from Socket as are needed to finish
  
positive.code:             end
      end.
  
  
  handle_callback(Type, [#state{cbinfo=CbInfo}=State | Args]) ->
      Cb = case Type of
  
negative.code:     advanced_messages(FrameInfos, State, State#state.timeout).
  
  advanced_messages([], State, Tout) ->
      {ok, State#state{unused_stream= <<>>}, Tout};
  advanced_messages([{frame_incomplete, Unused}], State, Tout) ->
      %% Unused is a part of a potentially large (some kb) binary,
      %% so we copy it to detach it for gc purposes
      {ok, State#state{unused_stream=binary:copy(Unused,1)}, Tout};
  advanced_messages([FrameInfo|Rest], #state{close_timer=TRef}=State,
                    Tout) when TRef /= undefined ->
      case FrameInfo of
  