Skip to content

Commit

Permalink
[client] add more socket options to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed Apr 17, 2024
1 parent 4635106 commit 9642705
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/eradius_client_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,8 @@ close(Socket) ->
%%% gen_server callbacks
%%%===================================================================

init([#{family := Family, ip := IP, active_n := ActiveN,
recbuf := RecBuf, sndbuf := SndBuf} = _Config]) ->
case IP of
any ->
ExtraOptions = [];
_ when is_tuple(IP) ->
ExtraOptions = [{ip, IP}]
end,

Opts = [{active, ActiveN}, binary, {recbuf, RecBuf}, {sndbuf, SndBuf},
Family | ExtraOptions],
init([#{family := Family, active_n := ActiveN} = Config]) ->
Opts = inet_opts(Config, [{active, ActiveN}, binary, Family]),
{ok, Socket} = gen_udp:open(0, Opts),

State = #state{
Expand Down Expand Up @@ -165,3 +156,15 @@ send_ip(inet6, {_, _, _, _,_, _, _, _} = IP) ->
{ok, IP};
send_ip(_, _) ->
{error, eafnosupport}.

inet_opts(Config, Opts0) ->
Opts =
maps:to_list(
maps:with([recbuf, sndbuf, ip,
ipv6_v6only, netns, bind_to_device, read_packets], Config)) ++ Opts0,
case Config of
#{inet_backend := Backend} when Backend =:= inet; Backend =:= socket ->
[{inet_backend, Backend} | Opts];
_ ->
Opts
end.

0 comments on commit 9642705

Please sign in to comment.