Skip to content

Commit 281c20e

Browse files
committed
Set TCP_NODELAY on the listen socket only
All unixs inherit NODELAY from the listen socket to the sockets returned from accept(2), so you only need to set in on the listen socket once to use it on the client sockets.
1 parent 8d0515e commit 281c20e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/puma/server.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def initialize(app, events=Events::DEFAULT)
6161
}
6262
end
6363

64-
def add_tcp_listener(host, port)
65-
@ios << TCPServer.new(host, port)
64+
def add_tcp_listener(host, port, optimize_for_latency=true)
65+
s = TCPServer.new(host, port)
66+
if optimize_for_latency
67+
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
68+
end
69+
@ios << s
6670
end
6771

6872
def add_unix_listener(path)
@@ -126,10 +130,6 @@ def handle_check
126130
end
127131

128132
def process_client(client)
129-
if client.kind_of? TCPSocket
130-
client.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
131-
end
132-
133133
begin
134134
while true
135135
parser = HttpParser.new

0 commit comments

Comments
 (0)