anchor.diff:              {error, socket_down}
       after
           Timeout ->
  -            send_retry_loop(Socket, SMon, Peer, ReqId, EncRequest, Timeout, RetryN - 1)
  +            send_request_loop(Socket, SMon, Peer, ReqId, EncRequest, Timeout, RetryN - 1)
       end.
   
   %% ------------------------------------------------------------------------------------------
  
positive.code: -define(SERVER, ?MODULE).
  -define(DEFAULT_RETRIES, 3).
  -define(DEFAULT_TIMEOUT, 5000).
  
  -type nas_address() :: {inet:ip_address(), eradius_server:port_number(), eradius_lib:secret()}.
  -type options() :: [{retries, pos_integer()} | {timeout, timeout()}].
  
  %% ------------------------------------------------------------------------------------------
  %% -- API
  start_link() ->
      gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
  
  -spec send_request(nas_address(), #radius_request{}) -> {ok, binary()} | {error, 'timeout' | 'socket_down'}.
  send_request(NAS, Request) ->
      send_request(NAS, Request, []).
  
  -spec send_request(nas_address(), #radius_request{}, options()) -> {ok, binary()} | {error, 'timeout' | 'socket_down' | 'badcmd'}.
  send_request({IP, Port, Secret}, Request = #radius_request{cmd = Cmd}, Options) when Cmd =:= 'request'; Cmd =:= 'accreq' ->
      Retries = proplists:get_value(retries, Options, ?DEFAULT_RETRIES),
      Timeout = proplists:get_value(timeout, Options, ?DEFAULT_TIMEOUT),
      {Socket, ReqId} = gen_server:call(?SERVER, {wanna_send, {IP, Port}}),
      SMon = erlang:monitor(process, Socket),
      EncRequest = encode_request(Request#radius_request{reqid = ReqId, secret = Secret}),
      send_retry_loop(Socket, SMon, {IP, Port}, ReqId, EncRequest, Timeout, Retries).
  
  encode_request(Req = #radius_request{cmd = request}) ->
      eradius_lib:encode_request(Req#radius_request{authenticator = eradius_lib:random_authenticator()});
  encode_request(Req = #radius_request{cmd = accreq}) ->
      eradius_lib:encode_reply_request(Req#radius_request{authenticator = eradius_lib:zero_authenticator()}).
  
  send_retry_loop(_Socket, SMon, _Peer, _ReqId, _EncRequest, _Timeout, 0) ->
      erlang:demonitor(SMon, [flush]),
      {error, timeout};
  send_retry_loop(Socket, SMon, Peer, ReqId, EncRequest, Timeout, RetryN) ->
      Socket ! {self(), send_request, Peer, ReqId, EncRequest},
      receive
          {Socket, response, ReqId, Response} ->
  
negative.code: 
  %% @private
  init([]) ->
      {ok, ClientPortCount} = application:get_env(eradius, client_ports),
      NewState = #state{no_ports = ClientPortCount},
      {ok, NewState}.
  