diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-05-16 19:04:06 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-05-16 19:34:52 +0000 |
commit | 39f625fff05d457b01f088017f463a86d3b6c626 (patch) | |
tree | eae2a3a759b70e0f6d12caefdf177d3eca418efe /lib/rainbows/configurator.rb | |
parent | d520222050ce88388ae5e446c63642d79cc9796e (diff) | |
download | rainbows-39f625fff05d457b01f088017f463a86d3b6c626.tar.gz |
This allows using IO::Splice.copy_stream from the "io_splice" RubyGem on recent Linux systems. This also allows users to disable copy_stream usage entirely and use traditional response_body.each calls which are compatible with all Rack servers (to workaround bugs in IO.copy_stream under 1.9.2-p180).
Diffstat (limited to 'lib/rainbows/configurator.rb')
-rw-r--r-- | lib/rainbows/configurator.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/rainbows/configurator.rb b/lib/rainbows/configurator.rb index 29d905b..a1d90cb 100644 --- a/lib/rainbows/configurator.rb +++ b/lib/rainbows/configurator.rb @@ -27,6 +27,7 @@ module Rainbows::Configurator :keepalive_requests => 100, :client_max_body_size => 1024 * 1024, :client_header_buffer_size => 1024, + :copy_stream => IO.respond_to?(:copy_stream) ? IO : false, }) # Configures \Rainbows! with a given concurrency model to +use+ and @@ -161,6 +162,44 @@ module Rainbows::Configurator check! set_int(:client_header_buffer_size, bytes, 1) end + + # Allows overriding the +klass+ where the +copy_stream+ method is + # used to do efficient copying of regular files, pipes, and sockets. + # + # This is only used with multi-threaded concurrency models: + # + # * ThreadSpawn + # * ThreadPool + # * WriterThreadSpawn + # * WriterThreadPool + # * XEpollThreadSpawn + # * XEpollThreadPool + # + # Due to existing {bugs}[http://redmine.ruby-lang.org/search?q=copy_stream] + # in the Ruby IO.copy_stream implementation, \Rainbows! uses the + # "sendfile" RubyGem that instead of copy_stream to transfer regular files + # to clients. The "sendfile" RubyGem also supports more operating systems, + # and works with more concurrency models. + # + # Recent Linux 2.6 users may override this with "IO::Splice" from the + # "io_splice" RubyGem: + # + # require "io/splice" + # Rainbows! do + # copy_stream IO::Splice + # end + # + # Keep in mind that splice(2) itself is a relatively new system call + # and has been buggy in many older Linux kernels. + # + # Default: IO on Ruby 1.9+, false otherwise + def copy_stream(klass) + check! + if klass && ! klass.respond_to?(:copy_stream) + abort "#{klass} must respond to `copy_stream' or be `false'" + end + set[:copy_stream] = klass + end end # :enddoc: |