Skip to content

Commit 1b43a50

Browse files
author
Simon MacMullen
committed
Increase buffer size for the port driver to match that used by the underlying socket.
1 parent d1540ad commit 1b43a50

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/rabbit_net.erl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
-include("rabbit.hrl").
1919

2020
-export([is_ssl/1, ssl_info/1, controlling_process/2, getstat/2,
21-
recv/1, async_recv/3, port_command/2, setopts/2, send/2, close/1,
22-
maybe_fast_close/1, sockname/1, peername/1, peercert/1,
21+
recv/1, async_recv/3, port_command/2, getopts/2, setopts/2, send/2,
22+
close/1, maybe_fast_close/1, sockname/1, peername/1, peercert/1,
2323
connection_string/2]).
2424

2525
%%---------------------------------------------------------------------------
@@ -34,6 +34,8 @@
3434
-type(ok_val_or_error(A) :: rabbit_types:ok_or_error2(A, any())).
3535
-type(ok_or_any_error() :: rabbit_types:ok_or_error(any())).
3636
-type(socket() :: port() | #ssl_socket{}).
37+
-type(opts() :: [{atom(), any()} |
38+
{raw, non_neg_integer(), non_neg_integer(), binary()}]).
3739

3840
-spec(is_ssl/1 :: (socket()) -> boolean()).
3941
-spec(ssl_info/1 :: (socket())
@@ -49,9 +51,12 @@
4951
-spec(async_recv/3 ::
5052
(socket(), integer(), timeout()) -> rabbit_types:ok(any())).
5153
-spec(port_command/2 :: (socket(), iolist()) -> 'true').
52-
-spec(setopts/2 :: (socket(), [{atom(), any()} |
53-
{raw, non_neg_integer(), non_neg_integer(),
54-
binary()}]) -> ok_or_any_error()).
54+
-spec(getopts/2 :: (socket(), [atom() | {raw,
55+
non_neg_integer(),
56+
non_neg_integer(),
57+
non_neg_integer() | binary()}])
58+
-> ok_val_or_error(opts())).
59+
-spec(setopts/2 :: (socket(), opts()) -> ok_or_any_error()).
5560
-spec(send/2 :: (socket(), binary() | iolist()) -> ok_or_any_error()).
5661
-spec(close/1 :: (socket()) -> ok_or_any_error()).
5762
-spec(maybe_fast_close/1 :: (socket()) -> ok_or_any_error()).
@@ -126,6 +131,11 @@ port_command(Sock, Data) when ?IS_SSL(Sock) ->
126131
port_command(Sock, Data) when is_port(Sock) ->
127132
erlang:port_command(Sock, Data).
128133

134+
getopts(Sock, Options) when ?IS_SSL(Sock) ->
135+
ssl:getopts(Sock#ssl_socket.ssl, Options);
136+
getopts(Sock, Options) when is_port(Sock) ->
137+
inet:getopts(Sock, Options).
138+
129139
setopts(Sock, Options) when ?IS_SSL(Sock) ->
130140
ssl:setopts(Sock#ssl_socket.ssl, Options);
131141
setopts(Sock, Options) when is_port(Sock) ->

src/rabbit_reader.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ start_connection(Parent, ChannelSupSupPid, Collector, StartHeartbeatFun, Deb,
222222
last_blocked_by = none,
223223
last_blocked_at = never},
224224
try
225+
BufSizes = inet_op(fun () ->
226+
rabbit_net:getopts(
227+
ClientSock, [sndbuf, recbuf, buffer])
228+
end),
229+
BufSz = lists:max([Sz || {_Opt, Sz} <- BufSizes]),
230+
ok = inet_op(fun () ->
231+
rabbit_net:setopts(ClientSock, [{buffer, BufSz}])
232+
end),
225233
recvloop(Deb, switch_callback(rabbit_event:init_stats_timer(
226234
State, #v1.stats_timer),
227235
handshake, 8)),

0 commit comments

Comments
 (0)