anchor.diff:      Response :: {next_state, client, State}
           | {stop, timeout, State}.
   
  -client(timeout, State=#state{in_process=InProcess}) ->
  -    case InProcess of
  -        {call, From, _} ->
  -            % TODO: Need to send errors responses to all clients
  -            gen_fsm:reply(From, {error, timeout}),
  -            {stop, timeout, State};
  -        _ ->
  -            {next_state, client, State}
  -    end;
  +client(timeout, State=#state{}) ->
  +    error_response(timeout, State);
   client(_Event, State) ->
       {next_state, client, State}.
   
  
positive.code: client({call, Module, Function, Args}, From, State=#state{})
          when is_atom(Module), is_atom(Function), is_list(Args) ->
      Data = term_to_binary({'C', Module, Function, Args}),
      try_to_request(client, State, Data, {call, From});
  client({switch, Module, Function, Args}, From, State=#state{})
          when is_atom(Module), is_atom(Function), is_list(Args) ->
      Data = term_to_binary({'S', Module, Function, Args}),
      try_to_request(server, State, Data, {switch, From});
  client(Event, From, State) ->
      {reply, {bad_event, ?MODULE, Event, From}, client, State}.
  
  
negative.code: 
  %% @hidden
  
  handle_info({Port, {data, Data}}, StateName=client, State=#state{port=Port}) ->
      try binary_to_term(Data) of
          {'r', Result} ->
              handle_response(call, {ok, Result}, State, StateName);
          {'e', Result} ->
              handle_response(call, {error, Result}, State, StateName);
          Response ->
              error_response({invalid_response, Response}, State)
      catch
          error:badarg ->
              error_response({invalid_response_data, Data}, State)
      end;
  handle_info({Port, {data, Data}}, StateName=server, State=#state{port=Port}) ->
      try binary_to_term(Data) of
          's' ->
              handle_response(switch, ok, State, StateName);
          {'C', Module, Function, Args} when is_atom(Module), is_atom(Function),
                  is_list(Args) ->
              Timer = gen_fsm:send_event_after(?CALL_TIMEOUT, timeout),
              % FIXME: proc_lib:spawn and monitor?
              {Pid, Monitor} = spawn_monitor(fun () ->
                  exit(try {ok, apply(Module, Function, Args)}
                      catch
                          Class:Reason ->
                              {error, {Class, Reason, erlang:get_stacktrace()}}
                      end)
                  end),
              Info = {Monitor, Timer, Pid},
              {next_state, StateName, State#state{call=Info}};
          Request ->
              {stop, {invalid_request, Request}, State}
      catch
          error:badarg ->
              {stop, {invalid_request_data, Data}, State}
      end;
  handle_info({'DOWN', Monitor, process, Pid, Result}, StateName=server,
          State=#state{port=Port, call={Monitor, Timer, Pid}}) ->
      gen_fsm:cancel_timer(Timer),
      R = case Result of
          {ok, Response} ->
              {'r', Response};
          {error, Response} ->
              {'e', Response};
          Response ->
              {'e', {error, Response, []}}
      end,
      Data = term_to_binary(R),
      case send_data(Port, Data, false) of
          ok ->
              {next_state, StateName, State#state{call=undefined}};
          fail ->
              {stop, port_closed, State#state{call=undefined}}
      end;
  handle_info({Port, closed}, _StateName, State=#state{port=Port}) ->
      {stop, port_closed, State};
  handle_info({'EXIT', Port, Reason}, _StateName, State=#state{port=Port}) ->
      {stop, {port_closed, Reason}, State};
  handle_info(_Info, StateName, State) ->
      {next_state, StateName, State}.
  
  