anchor.diff:  			MRef, Pid, Reason) ->
       case maps:take(Pid, Clients0) of
   	{{ID, MRef, Backend}, Clients1} ->
  -	    i("received down from ~w-client ~w (~p): "
  +	    i("received down from (gen) ~w-client ~w (~p): "
   	      "~n   ~p", [Backend, ID, Pid, Reason]),
  -	    start_client(State#{clients => Clients1}, Backend);
  +	    start_gen_client(State#{clients => Clients1}, Backend);
  +	{{ID, MRef}, Clients1} ->
  +	    i("received down from (esock) ~w-client ~w (~p): "
  +	      "~n   ~p", [ID, Pid, Reason]),
  +	    start_esock_client(State#{clients => Clients1});
   	error ->
   	    i("received down from unknown process ~p: "
   	      "~n   ~p", [Pid, Reason]),
  
positive.code:     end.
  
  
  client_loop(#{condition := terminate,
  	      sock      := Sock}) ->
      (catch gen_trcp:close(Sock)),
      exit(normal);
  client_loop(#{condition := {await_reply, _MID},
  	      parent    := Parent,
  	      sock      := Sock} = State) ->
      receive
  	{'DOWN', _MRef, process, Parent, Reason} ->
  	    e("unexpected down from parent received: "
  	      "~n   ~p", [Reason]),
  	    client_exit(State, parent_down, Reason);
  	
  	{tcp, Sock, Data} ->
  	    %% i("received (~w bytes of) data", [size(Data)]),
  	    client_loop(client_process_data(State, Data));
  
  	terminate ->
  	    client_loop(State#{condition => terminate})
  
      end;
  client_loop(#{condition := send_request, sock := Sock, mid := MID} = State) ->
      %% i("try send request ~w", [MID]),
      Data = ?DATA,
      SZ   = size(Data),
      Req  = <<?MTAG:32, MID:32, ?REQUEST:32, SZ:32, Data/binary>>,
      case gen_tcp:send(Sock, Req) of
  	ok ->
  	    client_loop(State#{condition => {await_reply, MID},
  			       mid => MID + 1});
  	{error, Reason} ->
  	    e("failed sending request ~w: "
  	      "~n   ~p", [MID, Reason]),
  	    client_exit(State, send, Reason)
      end.
  
  
  client_process_data(#{condition := {await_reply, MID},
  
negative.code:     end.
  
  
  start_esock_client(#{domain   := Domain,
  		     type     := Type,
  		     protocol := Proto,
  		     server   := #{addr := Addr, port := Port},
  		     cid      := ID,
  		     clients  := Clients0} = State) ->
      Self = self(),
      i("try start (esock) client ~w", [ID]),
      LifeTime = rand:uniform(timer:minutes(3)) + timer:minutes(2),
      {Pid, MRef} =
  	spawn_monitor(fun() ->
  			      esock_client_start(Self,
  						 ID,
  						 LifeTime,
  						 Domain, Type, Proto,
  						 Addr, Port)
  		      end),
      receive
  	{'DOWN', MRef, process, Pid, Reason} ->
  	    e("received unexpected down message from client ~w (~p):"
  	      "~n   ~p", [ID, Pid, Reason]),
  	    client_ctrl_exit({client, ID}, Reason);
  
  	{Pid, ready} ->
  	    i("received expected ready from client ~w (~p)", [ID, Pid]),
  	    Clients1 = Clients0#{Pid => {ID, MRef}},
  	    State#{cid => ID + 1, clients => Clients1}
      end.
  
  
  gen_client_start(Parent, Backend, ID,
  		 LifeTime,
  		 Domain, Type, Proto,
  		 ServerAddr, ServerPort)
    when (Type =:= stream) andalso (Proto =:= tcp) ->
      put(sname, f("gen-client[~w,~w]", [Backend, ID])),
      %% put(debug, true),
      i("starting"),
      State = gen_client_connect(#{id          => ID,
  				 backend     => Backend,
  				 domain      => Domain,
  				 type        => Type,
  				 protocol    => Proto,
  				 server_addr => ServerAddr,
  				 server_port => ServerPort}),
      erlang:send_after(LifeTime, self(), terminate),
      MRef = erlang:monitor(process, Parent),
      Parent ! {self(), ready},
      i("started"),
      gen_client_loop(State#{condition => send_request,
  			   mid       => 1,
  			   parent    => Parent,
  			   mref      => MRef,
  			   buf       => <<>>}).
  
  
  gen_client_connect(#{backend     := Backend,
  		     type        := Type,
  		     protocol    := Proto,
  		     server_addr := ServerAddr,
  		     server_port := ServerPort} = State)
    when (Type =:= stream) andalso (Proto =:= tcp) ->
      COpts = [{inet_backend, Backend}, {active, true}, binary],
      i("try connect to ~s:~w",
        [inet_parse:ntoa(ServerAddr), ServerPort]),
      case gen_tcp:connect(ServerAddr, ServerPort, COpts) of
  	{ok, Sock} ->
  	    %% i("connected"),
  	    ?SOCKET_MONITOR !
  		{monitor, Sock,
  		 string_of(inet, Sock),
  