anchor.diff:      [];
   api_to_connect_tcp4(_Config) when is_list(_Config) ->
       tc_begin(api_to_connect_tcp4),
  -    ok = api_to_connect_tcp(inet),
  +    InitState = #{domain => inet},
  +    ok = api_to_connect_tcp(InitState),
       tc_end().
       %% not_yet_implemented().
   
  
positive.code:     [];
  api_to_connect_tcp6(_Config) when is_list(_Config) ->
      %% tc_begin(api_to_connect_tcp6),
      %% ok = api_to_connect_tcp(inet6),
      %% tc_end().
      not_yet_implemented().
  
  
negative.code: %% For instance, on FreeBSD (11.2) the reponse when the backlog is full
  %% is a econreset.
  
  api_to_connect_tcp(InitState) ->
      process_flag(trap_exit, true),
  
      ServerSeq = 
          [
           %% *** Wait for start order part ***
           #{desc => "await start (from tester)",
             cmd  => fun(State) ->
                             receive
                                 {start, Tester} when is_pid(Tester) ->
                                     {ok, State#{tester => Tester}}
                             end
                     end},
  
           %% *** Init part ***
           #{desc => "which local address",
             cmd  => fun(#{domain := Domain} = State) ->
                             LAddr = which_local_addr(Domain),
                             LSA   = #{family => Domain, addr => LAddr},
                             {ok, State#{lsa => LSA}}
                     end},
           #{desc => "create listen socket",
             cmd  => fun(#{domain := Domain} = State) ->
                             case socket:open(Domain, stream, tcp) of
                                 {ok, Sock} ->
                                     {ok, State#{lsock => Sock}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "bind to local address",
             cmd  => fun(#{lsock := LSock, lsa := LSA} = State) ->
                             case socket:bind(LSock, LSA) of
                                 {ok, Port} ->
                                     {ok, State#{lport => Port}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "make listen socket (with backlog = 1)",
             cmd  => fun(#{lsock := LSock}) ->
                             socket:listen(LSock, 1)
                     end},
           #{desc => "monitor server",
             cmd  => fun(#{tester := Tester} = State) ->
                             MRef = erlang:monitor(process, Tester),
                             {ok, State#{tester_mref => MRef}}
                     end},
           #{desc => "announce ready",
             cmd  => fun(#{tester := Tester, lport := Port}) ->
                             ei("announcing ready to tester (~p)", [Tester]),
                             Tester ! {ready, self(), Port},
                             ok
                     end},
           #{desc => "await terminate (from tester)",
             cmd  => fun(#{tester := Tester}) ->
                             receive
                                 {'DOWN', _, process, Tester, Reason} ->
                                     {error, {unexpected_tester_exit, Reason}};
                                 {terminate, Tester} ->
                                     ok
                             end
                     end},
  
           %% *** We are done ***
           #{desc => "finish",
             cmd  => fun(_) ->
                             {ok, normal}
                     end}
          ],
  
      TesterSeq =
          [
           %% *** Init part ***
           #{desc => "which local address",
             cmd  => fun(#{domain := Domain} = State) ->
                             LAddr = which_local_addr(Domain),
                             LSA   = #{family => Domain, addr => LAddr},
                             {ok, State#{lsa => LSA}}
                     end},
           #{desc => "create socket 1",
             cmd  => fun(#{domain := Domain} = State) ->
                             case socket:open(Domain, stream, tcp) of
                                 {ok, Sock} ->
                                     {ok, State#{sock1 => Sock}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "create socket 2",
             cmd  => fun(#{domain := Domain} = State) ->
                             case socket:open(Domain, stream, tcp) of
                                 {ok, Sock} ->
                                     {ok, State#{sock2 => Sock}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "create socket 3",
             cmd  => fun(#{domain := Domain} = State) ->
                             case socket:open(Domain, stream, tcp) of
                                 {ok, Sock} ->
                                     {ok, State#{sock3 => Sock}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "bind socket 1 to local address",
             cmd  => fun(#{sock1 := Sock, lsa := LSA} = _State) ->
                             case socket:bind(Sock, LSA) of
                                 {ok, _} ->
                                     ok;
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "bind socket 2 to local address",
             cmd  => fun(#{sock2 := Sock, lsa := LSA} = _State) ->
                             case socket:bind(Sock, LSA) of
                                 {ok, _} ->
                                     ok;
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "bind socket 3 to local address",
             cmd  => fun(#{sock3 := Sock, lsa := LSA} = _State) ->
                             case socket:bind(Sock, LSA) of
                                 {ok, _} ->
                                     ok;
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
  
           %% *** Synchronize with the server ***
           #{desc => "order (server) start",
             cmd  => fun(#{server := Server}) ->
                             Server ! {start, self()},
                             ok
                     end},
           #{desc => "await ready (from server)",
             cmd  => fun(#{server := Server, lsa := LSA} = State) ->
                             receive
                                 {ready, Server, Port} ->
                                     {ok, State#{ssa => LSA#{port => Port}}}
                             end
                     end},
  
           %% *** Connect sequence ***
           #{desc => "order (server) start",
             cmd  => fun(#{sock1 := Sock1,
                           sock2 := Sock2,
                           sock3 := Sock3,
                           ssa   := SSA}) ->
                             Socks = [Sock1, Sock2, Sock3],
                             api_to_connect_tcp_await_timeout(Socks, SSA)
                     end},
  
           %% *** Terminate server ***
           #{desc => "monitor server",
             cmd  => fun(#{server := Server} = State) ->
                             MRef = erlang:monitor(process, Server),
                             {ok, State#{server_mref => MRef}}
                     end},
           #{desc => "order (server) terminate",
             cmd  => fun(#{server := Server} = _State) ->
                             Server ! {terminate, self()},
                             ok
                     end},
           #{desc => "await (server) down",
             cmd  => fun(#{server := Server} = State) ->
                             receive
                                 {'DOWN', _, process, Server, _} ->
                                     State1 = maps:remove(server, State),
                                     State2 = maps:remove(ssa, State1),
                                     {ok, State2}
                             end
                     end},
  
           %% *** Close our sockets ***
           #{desc => "close socket 3",
             cmd  => fun(#{sock3 := Sock} = State) ->
                             sock_close(Sock),
                             {ok, maps:remove(sock3, State)}
  
                     end},
           #{desc => "close socket 2",
             cmd  => fun(#{sock2 := Sock} = State) ->
                             sock_close(Sock),
                             {ok, maps:remove(sock2, State)}
  
                     end},
           #{desc => "close socket 1",
             cmd  => fun(#{sock1 := Sock} = State) ->
                             sock_close(Sock),
                             {ok, maps:remove(sock1, State)}
  
                     end},
  
           %% *** We are done ***
           #{desc => "finish",
             cmd  => fun(_) ->
                             {ok, normal}
                     end}
          ],
  
      p("create server evaluator"),
      ServerInitState = InitState,
      Server          = evaluator_start("server", ServerSeq, ServerInitState),
  
      p("create tester evaluator"),
      TesterInitState = InitState#{server => Server},
      Tester          = evaluator_start("tester", TesterSeq, TesterInitState),
  
      p("await evaluator(s)"),
      ok = await_evaluator_finish([Server, Tester]),
      ok.
  
  
  