Skip to content

Commit f2c217a

Browse files
committed
feat(tcpsocket): support tune_fun option
1 parent 3d6e943 commit f2c217a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/esockd_accept_inet.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ tune_socket(Sock, [{tune_buffer, true}|More]) ->
9494
Error
9595
end;
9696
tune_socket(Sock, [{tune_fun, {M, F, A}} | More]) ->
97+
%% NOTE: Socket is not part of the argument list, backward compatibility.
9798
case apply(M, F, A) of
9899
ok ->
99100
tune_socket(Sock, More);

src/esockd_accept_socket.erl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ eval_tune_socket_fun(Sock, {Fun, Opts}) ->
8383
mk_tune_socket_fun(Opts) ->
8484
TcpOpts = proplists:get_value(tcp_options, Opts, []),
8585
SockOpts = lists:flatten([sock_opt(O) || O <- merge_sock_defaults(TcpOpts)]),
86-
TuneOpts = [{Name, Val} || {Name, Val} <- Opts, Name =:= tune_buffer],
86+
TuneOpts = [{Name, Val} || {Name, Val} <- Opts,
87+
Name =:= tune_buffer orelse
88+
Name =:= tune_fun],
8789
{fun ?MODULE:tune_socket/2, [{setopts, SockOpts} | TuneOpts]}.
8890

8991
tune_socket(Sock, [{setopts, SockOpts} | Rest]) ->
@@ -93,16 +95,24 @@ tune_socket(Sock, [{setopts, SockOpts} | Rest]) ->
9395
Error ->
9496
Error
9597
end;
96-
tune_socket(Sock, [{tune_buffer, true} | _]) ->
98+
tune_socket(Sock, [{tune_buffer, true} | Rest]) ->
9799
try
98100
BufRecv = ensure(socket:getopt(Sock, {socket, rcvbuf})),
99101
Buffer = ensure(socket:getopt(Sock, {otp, rcvbuf})),
100102
Max = max(Buffer, BufRecv),
101103
ok = ensure(socket:setopt(Sock, {otp, rcvbuf}, Max)),
102-
{ok, Sock}
104+
tune_socket(Sock, Rest)
103105
catch
104106
Error -> Error
105107
end;
108+
tune_socket(Sock, [{tune_fun, {M, F, A}} | Rest]) ->
109+
%% NOTE: Socket is not part of the argument list, backward compatibility.
110+
case apply(M, F, A) of
111+
ok ->
112+
tune_socket(Sock, Rest);
113+
Error ->
114+
Error
115+
end;
106116
tune_socket(Sock, _) ->
107117
{ok, Sock}.
108118

0 commit comments

Comments
 (0)