anchor.diff:  filter_badrpc({badrpc, _}) -> false;
   filter_badrpc(_) -> true.
   
  -is_connected(riak_repl_tcp_server, _Status) ->
  -    true;
  -
  -is_connected(riak_repl_tcp_client, Status) ->
  -    case lists:keyfind(connected, 1, Status) of
  -        {connected, _, _} ->
  -            true;
  -        _ ->
  -            false
  -    end.
  -
   critical() ->
  -    {critical, "Unexpected return from status", []}.
  +    {critical, "Unexpected return from process_info", []}.
   
   warning() ->
       {warning, "Socket errors were detected on some replication connections. These errors have been logged on the Riak node. No action is required", []}.
  
positive.code:             end
      end.
  
  
  check_repl(Node) ->
      case is_leader(Node) of
          true ->
              Clients = check_repl(Node, {riak_repl_client_sup, riak_repl_tcp_client}),
              Servers = check_repl(Node, {riak_repl_server_sup, riak_repl_tcp_server}),
              Clients ++ Servers;
          false ->
              []
      end.
  
  check_repl(Node, {Sup, Mod}) ->
      Pids = repl_pids(Node, Sup),
      [check_repl_pid(Node, Mod, Pid) || Pid <- Pids].
  
  repl_pids(Node, Sup) ->
      Nodes = riak_nodes(Node),
  
negative.code:     Children = lists:flatten([Res || Res <- ResL, filter_badrpc(Res)]),
      [Pid || {_,Pid,_,_} <- Children, Pid /= undefined].
  
  check_repl_pid(Node, Pid) ->
      case rpc:call(Node, erlang, process_info, [Pid]) of
          undefined ->
              critical;
          Info ->
              Links = proplists:get_value(links, Info),
              Port = first_port(Links),
              case Port of
                  unefined ->
                      %% no port to check
                      ok;
                  _ ->
                      case port_info(Port) of
                          undefined ->
                              %% port is closed
                              Pid ! {tcp_closed, Port},
                              warning;
                          _ ->
                              case sockname(Port) of
                                  {ok, _} ->
                                      ok;
                                  {error, _Reason} ->
                                      %% something has gone wrong
                                      close_port(Port),
                                      Pid ! {tcp_closed, Port},
                                      warning
                              end
                      end
              end
      end.
  
  first_port([Link|_Links]) when is_port(Link) -> Link;
  first_port([_|Links]) -> first_port(Links);
  first_port([]) -> undefined.
  
  sockname(Socket) ->
      Node = erlang:node(Socket),
      rpc:call(Node, inet, sockname, [Socket]).
  
  port_info(Socket) ->
      Node = erlang:node(Socket),
      rpc:call(Node, erlang, port_info, [Socket]).
  
  close_port(Socket) ->
      Node = erlang:node(Socket),
      rpc:call(Node, erlang, port_close, [Socket]).
  
  is_leader(Node) ->
      rpc:call(Node, riak_repl_leader, leader_node, []) == Node.
  