From 894aadb824ccf386aeb42db5bb044e1ef4ea5b96 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Wed, 3 Feb 2021 21:34:57 -0600 Subject: [PATCH] server.rb - properly cork & uncork ssl client --- lib/puma/request.rb | 2 +- lib/puma/server.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/puma/request.rb b/lib/puma/request.rb index 415d15cc75..8a629bf3d9 100644 --- a/lib/puma/request.rb +++ b/lib/puma/request.rb @@ -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) diff --git a/lib/puma/server.rb b/lib/puma/server.rb index d60d64742f..cda127791e 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -120,7 +120,7 @@ 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 @@ -128,7 +128,7 @@ def tcp_cork_supported? # :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 @@ -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 @@ -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