about summary refs log tree commit homepage
path: root/lib/rainbows.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rainbows.rb')
-rw-r--r--lib/rainbows.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index a252ba6..5521e81 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -1,6 +1,7 @@
 # -*- encoding: binary -*-
 require 'unicorn'
 require 'rainbows/error'
+require 'fcntl'
 
 module Rainbows
 
@@ -87,9 +88,18 @@ module Rainbows
   autoload :Fiber, 'rainbows/fiber' # core class
 
   # returns nil if accept fails
-  def self.accept(sock)
-    sock.accept_nonblock
-  rescue Errno::EAGAIN, Errno::ECONNABORTED
+  if defined?(Fcntl::FD_CLOEXEC)
+    def self.accept(sock)
+      rv = sock.accept_nonblock
+      rv.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
+      rv
+    rescue Errno::EAGAIN, Errno::ECONNABORTED
+    end
+  else
+    def self.accept(sock)
+      sock.accept_nonblock
+    rescue Errno::EAGAIN, Errno::ECONNABORTED
+    end
   end
 
 end