Skip to content

Commit

Permalink
server.rb - properly cork & uncork ssl client
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Feb 4, 2021
1 parent f5d98ff commit 894aadb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/puma/request.rb
Expand Up @@ -30,7 +30,7 @@ module Request
#
def handle_request(client, lines)
env = client.env
io = client.io
io = client.io # io may be a MiniSSL::Socket

return false if closed_socket?(io)

Expand Down
11 changes: 7 additions & 4 deletions lib/puma/server.rb
Expand Up @@ -120,15 +120,15 @@ def current
# :nodoc:
# @version 5.0.0
def tcp_cork_supported?
RbConfig::CONFIG['host_os'] =~ /linux/ &&
RbConfig::CONFIG['host_os'].include?('linux') &&
Socket.const_defined?(:IPPROTO_TCP) &&
Socket.const_defined?(:TCP_CORK)
end

# :nodoc:
# @version 5.0.0
def closed_socket_supported?
RbConfig::CONFIG['host_os'] =~ /linux/ &&
RbConfig::CONFIG['host_os'].include?('linux') &&
Socket.const_defined?(:IPPROTO_TCP) &&
Socket.const_defined?(:TCP_INFO)
end
Expand All @@ -138,6 +138,7 @@ def closed_socket_supported?

# On Linux, use TCP_CORK to better control how the TCP stack
# packetizes our stream. This improves both latency and throughput.
# socket parameter may be an MiniSSL::Socket, so use to_io
#
if tcp_cork_supported?
UNPACK_TCP_STATE_FROM_TCP_INFO = "C".freeze
Expand All @@ -146,16 +147,18 @@ def closed_socket_supported?
# 3 == TCP_CORK
# 1/0 == turn on/off
def cork_socket(socket)
skt = socket.to_io
begin
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if socket.kind_of? TCPSocket
skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if skt.kind_of? TCPSocket
rescue IOError, SystemCallError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end
end

def uncork_socket(socket)
skt = socket.to_io
begin
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if socket.kind_of? TCPSocket
skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if skt.kind_of? TCPSocket
rescue IOError, SystemCallError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end
Expand Down

0 comments on commit 894aadb

Please sign in to comment.