anchor.diff:    end.
   
   gather_demand(Sock) ->
  -  gather_demand(Sock, "").
  -gather_demand(Sock, DataSoFar) ->
  -  case gen_tcp:recv(Sock, 0) of
  -    {ok, Data} ->
  -      % io:format("data = ~p~n", [Data]),
  -      TotalData = DataSoFar ++ Data,
  -      case regexp:first_match(TotalData, "0009done\n$") of
  -        {match, _Start, _Length} ->
  -          {ok, TotalData};
  -        _Else ->
  -          gather_demand(Sock, TotalData)
  -      end;
  -    {error, Reason} ->
  -      {error, Reason}
  +  gather_demand(Sock, [], pipe:new()).
  +gather_demand(Sock, DataSoFar, Pipe) ->
  +  {ok, Data, P2} = read_chunk_from_socket(Sock, Pipe),
  +  % io:format("+++~n~p~n+++~n", [Data]),
  +  TotalData = lists:append(DataSoFar, [Data]),
  +  case Data =:= <<"0000">> of
  +    true ->
  +      {ok, binary_to_list(list_to_binary(TotalData))};
  +    false ->
  +      gather_demand(Sock, TotalData, P2)
     end.
   
   gather_out(Port) ->
  
positive.code: % This is sent back immediately to the client.
  send_index_to_client(Port, Sock, Host, Path) ->
    Index = gather_out(Port),
    gen_tcp:send(Sock, Index),
    get_demand_from_client(Port, Sock, Host, Path).
    
  
negative.code: get_demand_from_client(Port, Sock, Host, Path) ->  
    case gather_demand(Sock) of
      {ok, Demand} ->
        io:format("demand = ~p~n", [Demand]),
        log_initial_clone(Demand, Host, Path),
        port_command(Port, Demand),
        send_pack_to_client(Port, Sock);
  