File 2042-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/gen_udp.erl b/lib/kernel/src/gen_udp.erl
index 97fce0603d..9656945345 100644
--- a/lib/kernel/src/gen_udp.erl
+++ b/lib/kernel/src/gen_udp.erl
@@ -294,7 +294,7 @@ can be retrieved with the`recv/2,3`](`recv/2`) calls. Note that incoming
 UDP packets that are longer than the receive buffer option specifies
 can be truncated without warning.
 
-The default value for the receive buffer option is `{recbuf, 8192}`.
+The default value for the receive buffer option is `{recbuf, 9216}`.
 """.
 -spec open(Port, Opts) -> {ok, Socket} | {error, Reason} when
       Port   :: inet:port_number(),
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
@@ -30,14 +30,20 @@ See also [ERTS User's Guide: Inet Configuration](`e:erts:inet_cfg.md`)
 or more information about how to configure an Erlang runtime system
 for IP communication.
 
-The following two Kernel configuration parameters affect the behavior of all
-`m:gen_tcp` sockets opened on an Erlang node:
+The following four Kernel configuration parameters affect the behavior of all
+`m:gen_tcp`, `m:gen_udp` and `m:gen_sctp` sockets opened on an Erlang node:
 
 - `inet_default_connect_options` can contain a list of
   default options used for all sockets created by
   a `gen_tcp:connect/2,3,4`](`gen_tcp:connect/2`) call.
 - `inet_default_listen_options` can contain a list of default options
   used for sockets created by a `gen_tcp:listen/2` call.
+- `inet_default_udp_options` can contain a list of
+  default options used for all sockets created by
+  a `gen_udp:open/1,2`](`gen_udp:open/2`) call.
+- `inet_default_sctp_options` can contain a list of
+  default options used for all sockets created by
+  a `gen_sctp:open/0,1`](`gen_sctp:open/1`) call.
 
 For the [`gen_tcp:accept/1,2`](`gen_tcp:accept/1`) call,
 the values of the listening socket options are inherited.
@@ -3304,7 +3310,14 @@ udp_options() ->
 
 -doc false.
 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() ->
 -doc false.
 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

openSUSE Build Service is sponsored by