File 2862-kernel-New-kernel-parameters-for-UDP-and-SCTP-socket.patch of Package erlang
From 4c866eab7ea982df8ca1f3a7cbcc66e6d37f9051 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Fri, 4 Apr 2025 19:18:10 +0200
Subject: [PATCH 2/3] [kernel] New kernel parameters for UDP and SCTP sockets
Add two new kernel parameters for modifying the socket options
when creating UDP and SCTP sockets; inet_default_udp_options
and inet_default_sctp_options. This makes it possible to, among
other things, change the initial buffer sizes.
Removed the explicit setting of the recbuf option (to 8192) when
creating an UDP socket (gen_udp:open), since the sockets now
by default has the buffer size of 9216.
Add documentation for the new kernel paremeters.
OTP-19576
---
lib/kernel/src/gen_udp.erl | 2 +-
lib/kernel/src/inet.erl | 28 ++++++++++++++++++++++++----
lib/kernel/src/inet_udp.erl | 6 ++----
3 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index fac973b05c..5db90e4b52 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -3304,7 +3310,14 @@ udp_options() ->
udp_options(Opts, Mod) ->
- case udp_opt(Opts, #udp_opts { }, udp_options()) of
+ BaseOpts =
+ case application:get_env(kernel, inet_default_udp_options) of
+ {ok, List} when is_list(List) ->
+ #udp_opts{opts = List};
+ _ ->
+ #udp_opts{}
+ end,
+ case udp_opt(Opts, BaseOpts, udp_options()) of
{ok, R} ->
{ok, R#udp_opts {
opts = lists:reverse(R#udp_opts.opts),
@@ -3437,7 +3450,14 @@ sctp_options() ->
sctp_options(Opts, Mod) ->
%% ?DBG([{opts, Opts}, {mod, Mod}]),
- case sctp_opt(Opts, Mod, #sctp_opts{}, sctp_options()) of
+ BaseOpts =
+ case application:get_env(kernel, inet_default_sctp_options) of
+ {ok, List} when is_list(List) ->
+ #sctp_opts{opts = List};
+ _ ->
+ #sctp_opts{}
+ end,
+ case sctp_opt(Opts, Mod, BaseOpts, sctp_options()) of
{ok, SO} ->
{ok,SO#sctp_opts{opts=lists:reverse(SO#sctp_opts.opts)}};
Error ->
diff --git a/lib/kernel/src/inet_udp.erl b/lib/kernel/src/inet_udp.erl
index 7c1039bce8..f45d3b03f8 100644
--- a/lib/kernel/src/inet_udp.erl
+++ b/lib/kernel/src/inet_udp.erl
@@ -32,7 +32,6 @@
-define(FAMILY, inet).
-define(PROTO, udp).
-define(TYPE, dgram).
--define(RECBUF, (8*1024)).
%% inet_udp port lookup
@@ -51,9 +50,7 @@ open(Port) -> open(Port, []).
-spec open(_, _) -> {ok, port()} | {error, atom()}.
open(Port, Opts) ->
- case inet:udp_options(
- [{port,Port}, {recbuf, ?RECBUF} | Opts],
- ?MODULE) of
+ case inet:udp_options([{port,Port} | Opts], ?MODULE) of
{error, Reason} -> exit(Reason);
{ok,
#udp_opts{
@@ -119,6 +116,7 @@ controlling_process(Socket, NewOwner) ->
%%
%% Create a port/socket from a file descriptor
%%
+-define(RECBUF, 9216). %% Just to be on the safe side...
fdopen(Fd, Opts) ->
inet:fdopen(
Fd, optuniquify([{recbuf, ?RECBUF} | Opts]),
--
2.43.0