anchor.diff:  %%
   
   -spec server(Event, State) -> Response when
  -    Event :: term(),
  +    Event :: timeout,
       State :: #state{},
       Response :: {next_state, server, State}.
   
  +server(timeout, State=#state{port=Port}) ->
  +    % TODO: It seems we don't need close process here?
  +    % TODO: We need to add request ID
  +    Data = term_to_binary({'e', {error, timeout, []}}),
  +    case send_data(Port, Data, false) of
  +        ok ->
  +            {next_state, server, State#state{call=undefined}};
  +        fail ->
  +            {stop, port_closed, State#state{call=undefined}}
  +    end;
   server(_Event, State) ->
       {next_state, server, State}.
   
  
positive.code: %%% Utility functions
  %%%
  
  try_to_send(Port, Data) ->
      try_to_send(Port, Data, true).
  
  try_to_send(Port, Data, WithTimer) ->
      try port_command(Port, Data, [nosuspend]) of
          true ->
              case WithTimer of
                  true ->
  
negative.code:                     {ok, Timer};
                  false ->
                      ok
              end
      catch
          error:badarg ->
              fail
      end.
  
  process_queue(StateName=client, State=#state{queue=Queue}) ->
      case queue:out(Queue) of
          {empty, Queue} ->
              {next_state, StateName, State};
          {{value, Queued}, Queue2} ->
              send_from_queue(Queued, Queue2, StateName, State)
      end;
  process_queue(StateName=server, State=#state{port=Port, queue=Queue}) ->
      case queue:out(Queue) of
          {empty, Queue} ->
              {next_state, StateName, State#state{in_process=undefined}};
          {{value, {response, Data}}, Queue2} ->
              case send_data(Port, Data, false) of
                  ok ->
                      {next_state, StateName, State#state{queue=Queue2}};
                  fail ->
                      {stop, port_closed, State}
              end
      end.
  
  send_request(Queued={Type, From, Data}, StateName, State=#state{port=Port,
          queue=Queue, in_process=InProcess}) ->
      case InProcess of
          undefined ->
              case send_data(Port, Data) of
                  {ok, Timer} ->
                      Info = {Type, From, Timer},
                      {next_state, StateName, State#state{in_process=Info}};
                  fail ->
                      {stop, port_closed, State}
              end;
          _ ->
              Queue2 = queue:in(Queued, Queue),
              {next_state, StateName, State#state{queue=Queue2}}
      end.
  
  send_from_queue({Type, From, Data}, Queue, StateName,
          State=#state{port=Port}) ->
      case send_data(Port, Data) of
          {ok, Timer} ->
              Info = {Type, From, Timer},
              {next_state, StateName, State#state{in_process=Info, queue=Queue}};
          fail ->
              {stop, port_closed, State}
      end.
  
  handle_response(ExpectedType, Response, State=#state{in_process=InProcess},
          StateName) ->
      case InProcess of
          {ExpectedType, From, Timer} ->
              gen_fsm:cancel_timer(Timer),
              gen_fsm:reply(From, Response),
              process_queue(StateName, State#state{in_process=undefined});
          undefined ->
              {stop, orphan_response, State};
          _ ->
              {stop, unexpected_response, State}
      end.
  
  error_response(Error, State=#state{in_process=InProcess}) ->
      case InProcess of
          {_Type, From, _Timer} ->
              gen_fsm:reply(From, {error, Error});
          undefined ->
              ok
      end,
      {stop, Error, State}.
  