about summary refs log tree commit homepage
path: root/lib/unicorn/socket_helper.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-03-15 02:25:13 +0000
committerEric Wong <e@80x24.org>2017-03-15 02:25:13 +0000
commit26e32bdd2a61749b0d568b303fa767e531d8ce07 (patch)
tree0949be5e4904276bee90edc3654a2fd450a6af7d /lib/unicorn/socket_helper.rb
parente9b9af6ca2957752cb9c6ca6e935ef081751e61b (diff)
parent20c66dbf1ebd0ca993e7a79c9d0d833d747df358 (diff)
downloadunicorn-26e32bdd2a61749b0d568b303fa767e531d8ce07.tar.gz
* origin/ccc-tcp-v3:
  http_request: reduce insn size for check_client_connection
  support "struct tcp_info" on non-Linux and Ruby 2.2+
  revert signature change to HttpServer#process_client
  new test for check_client_connection
  check_client_connection: use tcp state on linux
Diffstat (limited to 'lib/unicorn/socket_helper.rb')
-rw-r--r--lib/unicorn/socket_helper.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb
index 7aa2bb0..f52dde2 100644
--- a/lib/unicorn/socket_helper.rb
+++ b/lib/unicorn/socket_helper.rb
@@ -3,6 +3,18 @@
 require 'socket'
 
 module Unicorn
+
+  # Instead of using a generic Kgio::Socket for everything,
+  # tag TCP sockets so we can use TCP_INFO under Linux without
+  # incurring extra syscalls for Unix domain sockets.
+  # TODO: remove these when we remove kgio
+  TCPClient = Class.new(Kgio::Socket) # :nodoc:
+  class TCPSrv < Kgio::TCPServer # :nodoc:
+    def kgio_tryaccept # :nodoc:
+      super(TCPClient)
+    end
+  end
+
   module SocketHelper
 
     # internal interface
@@ -151,7 +163,7 @@ module Unicorn
       end
       sock.bind(Socket.pack_sockaddr_in(port, addr))
       sock.autoclose = false
-      Kgio::TCPServer.for_fd(sock.fileno)
+      TCPSrv.for_fd(sock.fileno)
     end
 
     # returns rfc2732-style (e.g. "[::1]:666") addresses for IPv6
@@ -188,7 +200,7 @@ module Unicorn
     def server_cast(sock)
       begin
         Socket.unpack_sockaddr_in(sock.getsockname)
-        Kgio::TCPServer.for_fd(sock.fileno)
+        TCPSrv.for_fd(sock.fileno)
       rescue ArgumentError
         Kgio::UNIXServer.for_fd(sock.fileno)
       end