diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-11-28 11:43:45 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-11-28 12:19:21 -0800 |
commit | f824f4e13a13daf56439e16ecb3a62469a8c9bf0 (patch) | |
tree | 162c80491bdf7ad7d258479af092c23a5557c2be /lib | |
parent | 2489368a624cff50a330238cf3c3f16eb0bd743c (diff) | |
download | rainbows-f824f4e13a13daf56439e16ecb3a62469a8c9bf0.tar.gz |
Some people fork processes, so it avoid hanging a connection open because of that...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rainbows.rb | 16 | ||||
-rw-r--r-- | lib/rainbows/revactor.rb | 2 |
2 files changed, 15 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 diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 4e4b381..9a18157 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -30,6 +30,8 @@ module Rainbows # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) + defined?(Fcntl::FD_CLOEXEC) and + client.instance_eval { @_io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } rd_args = [ nil ] remote_addr = if ::Revactor::TCP::Socket === client rd_args << RD_ARGS |