about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-06 12:59:45 -0700
committerEric Wong <normalperson@yhbt.net>2010-07-06 14:39:40 -0700
commitda0160d1eaf9fda309939253e51d88bb20f03ff4 (patch)
tree6a7298da53b9e7378077100dc6f410a88f52ab18
parent8dbcf5390091b7aedf8c1f76ca11659c13d931b4 (diff)
downloadunicorn-da0160d1eaf9fda309939253e51d88bb20f03ff4.tar.gz
Instead of detecting at startup if filters may be used, just try
anyways and log the error.  It is better to ask for forgiveness
than permission :)
(cherry picked from commit 2b4b15cf513f66dc7a5aabaae4491c17895c288c)
-rw-r--r--lib/unicorn/socket_helper.rb33
1 files changed, 12 insertions, 21 deletions
diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb
index 769cdf1..08b3d06 100644
--- a/lib/unicorn/socket_helper.rb
+++ b/lib/unicorn/socket_helper.rb
@@ -31,28 +31,13 @@ module Unicorn
 
       # do not send out partial frames (Linux)
       TCP_CORK = 3 unless defined?(TCP_CORK)
-    when /freebsd(([1-4]\..{1,2})|5\.[0-4])/
-      # Do nothing for httpready, just closing a bug when freebsd <= 5.4
-      TCP_NOPUSH = 4 unless defined?(TCP_NOPUSH) # :nodoc:
     when /freebsd/
       # do not send out partial frames (FreeBSD)
       TCP_NOPUSH = 4 unless defined?(TCP_NOPUSH)
 
-      # Use the HTTP accept filter if available.
-      # The struct made by pack() is defined in /usr/include/sys/socket.h
-      # as accept_filter_arg
-      unless `/sbin/sysctl -nq net.inet.accf.http`.empty?
-        # struct accept_filter_arg {
-        #   char af_name[16];
-        #   char af_arg[240];
-        # };
-        #
-        # +af_name+ is either "httpready" or "dataready",
-        # though other filters may be supported by FreeBSD
-        def accf_arg(af_name)
-          [ af_name, nil ].pack('a16a240')
-        end
-      end
+      def accf_arg(af_name)
+        [ af_name, nil ].pack('a16a240')
+      end if defined?(SO_ACCEPTFILTER)
     end
 
     def set_tcp_sockopt(sock, opt)
@@ -81,10 +66,16 @@ module Unicorn
         seconds = DEFAULTS[:tcp_defer_accept] if seconds == true
         seconds = 0 unless seconds # nil/false means disable this
         sock.setsockopt(SOL_TCP, TCP_DEFER_ACCEPT, seconds)
-      elsif defined?(SO_ACCEPTFILTER) && respond_to?(:accf_arg)
+      elsif respond_to?(:accf_arg)
         tmp = DEFAULTS.merge(opt)
-        name = tmp[:accept_filter] and
-          sock.setsockopt(SOL_SOCKET, SO_ACCEPTFILTER, accf_arg(name))
+        if name = tmp[:accept_filter]
+          begin
+            sock.setsockopt(SOL_SOCKET, SO_ACCEPTFILTER, accf_arg(name))
+          rescue => e
+            logger.error("#{sock_name(sock)} " \
+                         "failed to set accept_filter=#{name} (#{e.inspect})")
+          end
+        end
       end
     end