Skip to content

Commit

Permalink
Update docs for low_latency option and fix parsing issue (#2631)
Browse files Browse the repository at this point in the history
* Treat low_latency=false as false instead of true

Previously the binder.parse code was just checking that the low_latency
key existed, but the docs (and other options) support passing options in
the format `option=false`. This commit now treats `low_latency=false` as
false, while still treating `low_latency` with no `=` as true

* Update docs to reflect code behaviour

* Skip getsockopt tests in JRuby

JRuby (at least this version) doesn't support basic Socket constants or
methods

Ref: jruby/jruby#3438
  • Loading branch information
seangoedecke committed May 20, 2021
1 parent ffa5d56 commit 8c211dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puma/binder.rb
Expand Up @@ -163,7 +163,7 @@ def parse(binds, logger, log_msg = 'Listening')
ios_len = @ios.length
params = Util.parse_query uri.query

opt = params.key?('low_latency')
opt = params.key?('low_latency') && params['low_latency'] != 'false'
bak = params.fetch('backlog', 1024).to_i

io = add_tcp_listener uri.host, uri.port, opt, bak
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/dsl.rb
Expand Up @@ -201,7 +201,7 @@ def load(file)
# * Set the socket backlog depth with +backlog+, default is 1024.
# * Set up an SSL certificate with +key+ & +cert+.
# * Set whether to optimize for low latency instead of throughput with
# +low_latency+, default is to optimize for low latency. This is done
# +low_latency+, default is to not optimize for low latency. This is done
# via +Socket::TCP_NODELAY+.
# * Set socket permissions with +umask+.
#
Expand Down
27 changes: 27 additions & 0 deletions test/test_binder.rb
Expand Up @@ -192,6 +192,33 @@ def test_pre_existing_unix
end
end

def test_binder_parses_nil_low_latency
skip_if :jruby
@binder.parse ["tcp://0.0.0.0:0?low_latency"], @events

socket = @binder.listeners.first.last

assert socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool
end

def test_binder_parses_true_low_latency
skip_if :jruby
@binder.parse ["tcp://0.0.0.0:0?low_latency=true"], @events

socket = @binder.listeners.first.last

assert socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool
end

def test_binder_parses_false_low_latency
skip_if :jruby
@binder.parse ["tcp://0.0.0.0:0?low_latency=false"], @events

socket = @binder.listeners.first.last

refute socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool
end

def test_binder_parses_tlsv1_disabled
skip_unless :ssl
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1=true"], @events
Expand Down

0 comments on commit 8c211dc

Please sign in to comment.