anchor.diff:                             ?SLEEP(?SECS(1)),
                              ok
                      end},
  -         #{desc => "order client continue (connect)",
  -           cmd  => fun(#{client := Pid} = _State) ->
  +         #{desc => "order client 1 continue (connect)",
  +           cmd  => fun(#{client1 := Pid} = _State) ->
                              ev_continue(Pid, connect),
                              ok
                      end},
  -         #{desc => "await server ready (accept)",
  -           cmd  => fun(#{server := Server,
  -                         client := Client} = _State) ->
  +         #{desc => "await client 1 ready (connect)",
  +           cmd  => fun(#{server  := Server,
  +                         client1 := Client1,
  +                         client2 := Client2,
  +                         client3 := Client3} = _State) ->
  +                           ev_await_ready(Client1, client1, connect, 
  +                                          [{server,  Server},
  +                                           {client2, Client2},
  +                                           {client3, Client3}]),
  +                           ok
  +                   end},
  +         #{desc => "order client 2 continue (connect)",
  +           cmd  => fun(#{client2 := Pid} = _State) ->
  +                           ev_continue(Pid, connect),
  +                           ok
  +                   end},
  +         #{desc => "await client 2 ready (connect)",
  +           cmd  => fun(#{server  := Server,
  +                         client1 := Client1,
  +                         client2 := Client2,
  +                         client3 := Client3} = _State) ->
  +                           ev_await_ready(Client2, client2, connect, 
  +                                          [{server,  Server},
  +                                           {client1, Client1},
  +                                           {client3, Client3}]),
  +                           ok
  +                   end},
  +         #{desc => "order client 3 continue (connect)",
  +           cmd  => fun(#{client3 := Pid} = _State) ->
  +                           ev_continue(Pid, connect),
  +                           ok
  +                   end},
  +         #{desc => "await client 3 ready (connect)",
  +           cmd  => fun(#{server  := Server,
  +                         client1 := Client1,
  +                         client2 := Client2,
  +                         client3 := Client3} = _State) ->
  +                           ev_await_ready(Client3, client3, connect, 
  +                                          [{server,  Server},
  +                                           {client1, Client1},
  +                                           {client2, Client2}]),
  +                           ok
  +                   end},
  +         #{desc => "await server ready (accept from all connections)",
  +           cmd  => fun(#{server  := Server,
  +                         client1 := Client1,
  +                         client2 := Client2,
  +                         client3 := Client3} = _State) ->
                              ev_await_ready(Server, server, accept,
  -                                          [{client, Client}]),
  -                           ok
  -                   end},
  -         #{desc => "await client ready (connect)",
  -           cmd  => fun(#{server := Server,
  -                         client := Client} = _State) ->
  -                           ev_await_ready(Client, client, connect, 
  -                                          [{server, Server}]),
  -                           ok
  -                   end},
  -         #{desc => "order server continue (recv)",
  +                                          [{client1, Client1},
  +                                           {client2, Client2},
  +                                           {client3, Client3}]),
  +                           ok
  +                   end},
  +         #{desc => "order server continue (recv for all connections)",
              cmd  => fun(#{server := Pid} = _State) ->
                              ev_continue(Pid, recv),
                              ok
  
positive.code:                            ok
                     end},
  
           %% The actual test
           #{desc => "await continue (accept)",
             cmd  => fun(#{tester := Tester} = _State) ->
                             ev_await_continue(Tester, tester, accept)
                     end},
           #{desc => "accept",
             cmd  => fun(#{lsock := LSock} = State) ->
                             case socket:accept(LSock) of
                                 {ok, Sock} ->
                                     {ok, State#{csock => Sock}};
                                 {error, _} = ERROR ->
                                     ERROR
                             end
                     end},
           #{desc => "announce ready (accept)",
             cmd  => fun(#{tester := Tester}) ->
                             ev_ready(Tester, accept),
                             ok
  
negative.code:             Reason;
          {'DOWN', _, process, Parent, _Reason} ->
              init:stop()
      end.
  
  
  %% The handlers run on the same node as the server (the local node).
  
  sc_rc_tcp_handler_start(ID, Recv, Sock) ->
      Self     = self(),
      Fun      = fun() -> sc_rc_tcp_handler(ID, Self, Recv, Sock) end,
      {Pid, _} = erlang:spawn_monitor(Fun),
      receive
          {started, Pid} ->
              {ok, Pid};
          {'DOWN', _, process, Pid, Reason} ->
              {error, Reason}
      end.
  
  sc_rc_tcp_handler(ID, Parent, Recv, Sock) ->
      sc_rc_tcp_handler_init(ID, Parent),
      sc_rc_tcp_handler_await_recv(Parent),
      RecvRes = sc_rc_tcp_handler_recv(Recv, Sock),
      sc_rc_tcp_handler_announce_ready(Parent, RecvRes),
      Reason = sc_rc_tcp_handler_await_terminate(Parent),
      exit(Reason).
  
  sc_rc_tcp_handler_init(ID, Parent) ->
      put(sname, f("handler-~w", [ID])),
      _MRef = erlang:monitor(process, Parent),
      Parent ! {started, self()},
      ei("started"),
      ok.
  
  sc_rc_tcp_handler_await_recv(Parent) ->
      ei("await recv"),
      receive
          {recv, Parent} ->
              ok;
          {'DOWN', _, process, Parent, Reason} ->
              ee("received DOWN regarding parent: "
                 "~n   ~p", [Reason]),
              exit({parent, Reason})
      end.
  
  sc_rc_tcp_handler_recv(Recv, Sock) ->
      ei("recv"),
      try Recv(Sock) of
          {error, closed} ->
              ok;
          {ok, _} ->
              ei("unexpected success"),
              {error, unexpected_success};
          {error, Reason} = ERROR ->
              ei("receive error: "
                 "~n   ~p", [Reason]),
              ERROR
      catch
          C:E:S ->
              ei("receive failure: "
                 "~n   Class: ~p"
                 "~n   Error: ~p"
                 "~n   Stack: ~p", [C, E, S]),
              {error, {recv, C, E, S}}
      end.
      
  sc_rc_tcp_handler_announce_ready(Parent, Result) ->
      ei("announce ready"),
      Parent ! {ready, self(), Result},
      ok.
  
  sc_rc_tcp_handler_await_terminate(Parent) ->
      ei("await terminate"),
      receive
          {terminate, Parent, Reason} ->
              Reason;
          {'DOWN', _, process, Parent, Reason} ->
              ee("received DOWN regarding parent: "
                 "~n   ~p", [Reason]),
              {parent, Reason}
      end.
  
  
  