Skip to content

Commit 0d51bd0

Browse files
committed
plugin_helper/server: Add receive_buffer_size parameter in transport section
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 6f5ea89 commit 0d51bd0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/fluent/plugin_helper/server.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: t
8484
socket_options[:linger_timeout] ||= @transport_config&.linger_timeout || 0
8585
end
8686

87+
socket_options[:receive_buffer_size] = @transport_config&.receive_buffer_size
88+
8789
socket_option_validate!(proto, **socket_options)
8890
socket_option_setter = ->(sock){ socket_option_set(sock, **socket_options) }
8991

@@ -136,6 +138,8 @@ def server_create(title, port, proto: nil, bind: '0.0.0.0', shared: true, socket
136138
socket_options[:linger_timeout] ||= @transport_config&.linger_timeout || 0
137139
end
138140

141+
socket_options[:receive_buffer_size] = @transport_config&.receive_buffer_size
142+
139143
unless socket
140144
socket_option_validate!(proto, **socket_options)
141145
socket_option_setter = ->(sock){ socket_option_set(sock, **socket_options) }
@@ -266,6 +270,9 @@ module ServerTransportParams
266270

267271
### Socket Params ###
268272

273+
desc "The max size of socket receive buffer. SO_RCVBUF"
274+
config_param :receive_buffer_size, :size, default: nil
275+
269276
# SO_LINGER 0 to send RST rather than FIN to avoid lots of connections sitting in TIME_WAIT at src.
270277
# Set positive value if needing to send FIN on closing on non-Windows.
271278
# (On Windows, Fluentd can send FIN with zero `linger_timeout` since Fluentd doesn't set 0 to SO_LINGER on Windows.

test/plugin_helper/test_server.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ class Dummy < Fluent::Plugin::TestBase
8989
assert d.log
9090
assert_equal 1, d.transport_config.linger_timeout
9191
end
92+
93+
test 'can change receive_buffer_size option' do
94+
d = Dummy.new
95+
96+
transport_opts = {
97+
'receive_buffer_size' => 1024,
98+
}
99+
transport_conf = config_element('transport', 'tcp', transport_opts)
100+
conf = config_element('source', 'tag.*', {}, [transport_conf])
101+
102+
assert_nothing_raised do
103+
d.configure(conf)
104+
end
105+
assert d.plugin_id
106+
assert d.log
107+
assert_equal 1024, d.transport_config.receive_buffer_size
108+
end
92109
end
93110

94111
# run tests for tcp, udp, tls and unix

0 commit comments

Comments
 (0)