about summary refs log tree commit homepage
path: root/lib/unicorn
diff options
context:
space:
mode:
authorDylan Thacker-Smith <dylan.smith@shopify.com>2017-03-25 21:49:03 -0400
committerEric Wong <e@80x24.org>2017-03-26 03:34:53 +0000
commit477a2207869ff6b11a1cdee428b55604f2caa69e (patch)
tree6c816d32d8ef949686386bfc27f346d76cb6bbcd /lib/unicorn
parent9cced5d3ace9fc333c95b63f443225887f774a47 (diff)
downloadunicorn-477a2207869ff6b11a1cdee428b55604f2caa69e.tar.gz
The ruby constant Socket::TCP_INFO is only defined if TCP_INFO is defined
in C, so we can just check for the presence of that ruby constant instead
of rescuing SocketError from the call to getsockopt.
Diffstat (limited to 'lib/unicorn')
-rw-r--r--lib/unicorn/http_request.rb17
1 files changed, 3 insertions, 14 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index 6dc0aa7..f83a566 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -29,7 +29,7 @@ class Unicorn::HttpParser
   EMPTY_ARRAY = [].freeze
   @@input_class = Unicorn::TeeInput
   @@check_client_connection = false
-  @@tcpi_inspect_ok = nil
+  @@tcpi_inspect_ok = Socket.const_defined?(:TCP_INFO)
 
   def self.input_class
     @@input_class
@@ -154,19 +154,8 @@ class Unicorn::HttpParser
     # Not that efficient, but probably still better than doing unnecessary
     # work after a client gives up.
     def check_client_connection(socket) # :nodoc:
-      if Unicorn::TCPClient === socket && @@tcpi_inspect_ok != false
-        if @@tcpi_inspect_ok
-          opt = socket.getsockopt(:IPPROTO_TCP, :TCP_INFO).inspect
-        else
-          @@tcpi_inspect_ok = true
-          opt = begin
-            socket.getsockopt(:IPPROTO_TCP, :TCP_INFO)
-          rescue SocketError
-            @@tcpi_inspect_ok = false
-            return write_http_header(socket)
-          end.inspect
-        end
-
+      if Unicorn::TCPClient === socket && @@tcpi_inspect_ok
+        opt = socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_INFO).inspect
         if opt =~ /\bstate=(\S+)/
           raise Errno::EPIPE, "client closed connection".freeze,
                 EMPTY_ARRAY if closed_state_str?($1)