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
553553handshake (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
0 commit comments