File 3355-Don-t-try-to-recv-peek-the-header.patch of Package erlang

From 74790e3854f4ca610c6128cdac797a601f12b4e4 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Fri, 30 Aug 2024 15:50:49 +0200
Subject: [PATCH 5/8] Don't try to recv peek the header

---
 lib/kernel/src/gen_tcp_socket.erl | 48 ++++---------------------------
 1 file changed, 5 insertions(+), 43 deletions(-)

diff --git a/lib/kernel/src/gen_tcp_socket.erl b/lib/kernel/src/gen_tcp_socket.erl
index 0e87b1fe15..cea9740bcb 100644
--- a/lib/kernel/src/gen_tcp_socket.erl
+++ b/lib/kernel/src/gen_tcp_socket.erl
@@ -887,15 +887,11 @@ socket_send_error(Result) ->
     end.
 
 
--compile({inline, [socket_recv/2, socket_recv_peek/2]}).
+-compile({inline, [socket_recv/2]}).
 socket_recv(Socket, Length) ->
     Result = socket:recv(Socket, Length, [], nowait),
     %% ?DBG({Socket, Length, Result}),
     Result.
-socket_recv_peek(Socket, Length) ->
-    Result = socket:recv(Socket, Length, [peek], 0),
-    %% ?DBG({Socket, Length, Result}),
-    Result.
 
 -compile({inline, [socket_close/1]}).
 socket_close(Socket) ->
@@ -2336,8 +2332,8 @@ handle_recv(
             MinHdrLen = packet_header_length(PacketType),
             if
                 BufferSize < MinHdrLen ->
-                    handle_recv_packet_peek(
-                      P, D, ActionsR, Buffer, BufferSize, MinHdrLen, CS);
+                    handle_recv_more(
+                      P, D, ActionsR, Buffer, BufferSize, MinHdrLen);
                 true ->
                     handle_recv_packet(
                       P, D, ActionsR, Buffer, BufferSize, CS)
@@ -2384,42 +2380,6 @@ handle_recv_packet(
             handle_recv_error(P, D, ActionsR, Reason)
     end.
 
-handle_recv_packet_peek(
-  P, D, ActionsR, Buffer, BufferSize, MinHdrLen, recv = _CS) ->
-    %% ?DBG({Buffer, BufferSize, MinHdrLen, _CS}),
-    case socket_recv_peek(P#params.socket, MinHdrLen-BufferSize) of
-        {ok, <<Data/binary>>} ->
-            Header = condense_buffer(Data, Buffer),
-            case decode_packet(D, Header) of
-                {more, undefined} ->
-                    %% Odd bad case - try one byte more, see above
-                    handle_recv_more(
-                      P, D, ActionsR, Buffer, BufferSize, MinHdrLen + 1);
-                {more, PacketLength} ->
-                    handle_recv_more(
-                      P, D, ActionsR, Buffer, BufferSize, PacketLength);
-                _ ->
-                    %% Fall back to generic path
-                    handle_recv_packet(
-                      P, D, ActionsR, Buffer, BufferSize, recv)
-            end;
-
-        %% Fallbacks when not enough data could be peeked
-        {error, {timeout, _}} ->
-            handle_recv_packet(P, D, ActionsR, Buffer, BufferSize, recv);
-        {error, timeout} ->
-            handle_recv_packet(P, D, ActionsR, Buffer, BufferSize, recv);
-
-        {error, {Reason, _}} ->
-            handle_recv_error(P, D, ActionsR, Reason);
-        {error, Reason} ->
-            handle_recv_error(P, D, ActionsR, Reason)
-    end;
-handle_recv_packet_peek(
-  P, D, ActionsR, Buffer, BufferSize, _MinHdrLen, {recv, _} = CS) ->
-    %% ?DBG({Buffer, BufferSize, _MinHdrLen, CS}),
-    handle_recv_packet(P, D, ActionsR, Buffer, BufferSize, CS).
-
 handle_recv_more(
   P, D, ActionsR, Buffer, BufferSize, Length) ->
     %% ?DBG({Buffer, BufferSize, Length}),
@@ -2832,8 +2792,10 @@ condense_buffer([Bin]) when is_binary(Bin) -> Bin;
 condense_buffer(Buffer) ->
     iolist_to_binary(reverse(Buffer)).
 
+-ifdef(undefined).
 condense_buffer(Data, Buffer) ->
     condense_buffer(buffer(Data, Buffer)).
+-endif.
 
 deliver_data(Data, Mode, Header, Packet) ->
     if
-- 
2.43.0

openSUSE Build Service is sponsored by