anchor.diff:                           S2
                    end,
               {reply, ok, opened, S3};
  -        {ok, #connack{ return_code = Else }, S1} ->
  -            protocol_error(Else, S1);
  -        {ok, Else, S1} ->
  -            protocol_error({unexpected, Else}, S1);
  +        {ok, #connack{ return_code = Else }, _Rest, S1} ->
  +            E = {connection_refused, Else},
  +            {stop, E, {error, E}, S1};
  +        {ok, Else, _Rest, S1} ->
  +            E = {unexpected, Else},
  +            {stop, E, {error, unexpected_frame}, S1};
           {error, Reason} ->
  -            frame_error(Reason, S)
  +            {stop, Reason, {error, connection_error}, S0}
       end.
   
   opened({publish, P0}, S0 = #state{ id_counter = NextId }) ->
  
positive.code:             {ok, F, Rest, S0};
          {more, K} ->
              wait_for_more(S0, K);
          {error, R} ->
              frame_error(self(), R)
      end.
  
  wait_for_more(S = #state{ socket = Sock }, K) ->
      inet:setopts(Sock, [{active, once}]),
      receive
          {tcp, Sock, D} -> parse_frame(D, S, K);
          {tcp_closed, Sock} -> unexpected_closed(self());
          {tcp_error, Sock, Reason} -> socket_error(self(), Reason)
      end.
  
  ask_for_more(S = #state{ socket = Sock }) ->
  
negative.code: 
  selfsend_frame(Frame) ->
      ok = gen_fsm:send_event(self(), {frame, Frame}).
  
  %% Create a frame given the options (fields, effectively) as an alist
  opts(F, []) ->
  