anchor.diff:      write(S1, P1),
       {next_state, opened, S1};
   
  -opened({rpc, Frame, From}, S0) ->
  -    S1 = rpc(S0, Frame, From),
  +opened({rpc, Frame, Ref, From}, S0) ->
  +    S1 = do_rpc(S0, Frame, Ref, From),
       {next_state, opened, S1};
   
   opened({frame, Frame}, S0) ->
  
positive.code: 
  %% worth putting specs on these?
  
  unopened({open, Socket, Receiver, Connect}, From,
           S0 = #state{ socket = undefined }) ->
      Monitor = monitor(process, Receiver),
      S = S0#state{ socket = Socket,
  
negative.code:     ok = gen_tcp:send(S, mqtt_framing:serialise(Frame)),
      ok.
  
  %% Send an RPC frame (one that expects a reply) and return a receipt
  rpc(Conn, Frame, From) ->
      Ref = make_ref(),
      gen_fsm:send_event(Conn, {rpc, Frame, Ref, From}),
      {ok, Ref}.
  
  %% Record the fact of an RPC and send the frame with the correct id.
  do_rpc(S0, Req, Ref, From) ->
      #state{ id_counter = Id,
              rpcs = RPC0 } = S0,
      RPC1 = gb_trees:insert(Id, {Ref, From}, RPC0),
      write(S0, with_id(Id, Req)),
      S0#state{ id_counter = Id + 1, rpcs = RPC1 }.
  
  