Skip to content

Commit 6966ed5

Browse files
committed
Restrict dynamic buffer to rabbit_reader
But I found out rabbit_reader is both 0.9 and 1.0.
1 parent c35cfb7 commit 6966ed5

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

deps/rabbit/src/rabbit_networking.erl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
close_connection/2, close_connections/2, close_all_connections/1,
3333
close_all_user_connections/2,
3434
force_connection_event_refresh/1, force_non_amqp_connection_event_refresh/1,
35-
handshake/2, tcp_host/1,
35+
handshake/2, handshake/3, tcp_host/1,
3636
ranch_ref/1, ranch_ref/2, ranch_ref_of_protocol/1,
3737
listener_of_protocol/1, stop_ranch_listener_of_protocol/1,
3838
list_local_connections_of_protocol/1]).
@@ -551,6 +551,9 @@ failed_to_recv_proxy_header(Ref, Error) ->
551551
exit({shutdown, failed_to_recv_proxy_header}).
552552

553553
handshake(Ref, ProxyProtocolEnabled) ->
554+
handshake(Ref, ProxyProtocolEnabled, static_buffer).
555+
556+
handshake(Ref, ProxyProtocolEnabled, BufferStrategy) ->
554557
case ProxyProtocolEnabled of
555558
true ->
556559
case ranch:recv_proxy_header(Ref, 3000) of
@@ -560,29 +563,34 @@ handshake(Ref, ProxyProtocolEnabled) ->
560563
failed_to_recv_proxy_header(Ref, Error);
561564
{ok, ProxyInfo} ->
562565
{ok, Sock} = ranch:handshake(Ref),
563-
ok = tune_buffer_size(Sock),
566+
ok = tune_buffer_size(Sock, BufferStrategy),
564567
{ok, {rabbit_proxy_socket, Sock, ProxyInfo}}
565568
end;
566569
false ->
567570
{ok, Sock} = ranch:handshake(Ref),
568-
ok = tune_buffer_size(Sock),
571+
ok = tune_buffer_size(Sock, BufferStrategy),
569572
{ok, Sock}
570573
end.
571574

572-
tune_buffer_size(Sock) ->
573-
% case tune_buffer_size1(Sock) of
575+
tune_buffer_size(Sock, dynamic_buffer) ->
574576
case rabbit_net:setopts(Sock, [{buffer, 128}]) of
575577
ok -> ok;
576578
{error, _} -> rabbit_net:fast_close(Sock),
577579
exit(normal)
580+
end;
581+
tune_buffer_size(Sock, static_buffer) ->
582+
case tune_buffer_size_static(Sock) of
583+
ok -> ok;
584+
{error, _} -> rabbit_net:fast_close(Sock),
585+
exit(normal)
578586
end.
579587

580-
%tune_buffer_size1(Sock) ->
581-
% case rabbit_net:getopts(Sock, [sndbuf, recbuf, buffer]) of
582-
% {ok, BufSizes} -> BufSz = lists:max([Sz || {_Opt, Sz} <- BufSizes]),
583-
% rabbit_net:setopts(Sock, [{buffer, BufSz}]);
584-
% Error -> Error
585-
% end.
588+
tune_buffer_size_static(Sock) ->
589+
case rabbit_net:getopts(Sock, [sndbuf, recbuf, buffer]) of
590+
{ok, BufSizes} -> BufSz = lists:max([Sz || {_Opt, Sz} <- BufSizes]),
591+
rabbit_net:setopts(Sock, [{buffer, BufSz}]);
592+
Error -> Error
593+
end.
586594

587595
%%--------------------------------------------------------------------
588596

deps/rabbit/src/rabbit_reader.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ shutdown(Pid, Explanation) ->
159159
init(Parent, HelperSups, Ref) ->
160160
?LG_PROCESS_TYPE(reader),
161161
{ok, Sock} = rabbit_networking:handshake(Ref,
162-
application:get_env(rabbit, proxy_protocol, false)),
162+
application:get_env(rabbit, proxy_protocol, false),
163+
dynamic_buffer),
163164
Deb = sys:debug_options([]),
164165
start_connection(Parent, HelperSups, Ref, Deb, Sock).
165166

0 commit comments

Comments
 (0)