Rainbows! Rack HTTP server user/dev discussion
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: rainbows-public@bogomips.org
Subject: [PATCH v2] response: convert source arg to path before IO.copy_stream
Date: Tue, 13 Oct 2015 23:45:59 +0000
Message-ID: <20151013234559.21457-1-e@80x24.org> (raw)
In-Reply-To: <20151010015258.19805-1-e@80x24.org>

This will allow us use the sendfile syscall under Linux on
Ruby which favor #read/#readpartial methods for non-IO objects.

This also allows us to revert changes made in
commit db790ff3531acdfa23ab290998bba29360a6782b
("sync_close: This fix breakage from Ruby-trunk r50118")
 lib/rainbows/response.rb   | 5 +++++
 lib/rainbows/sync_close.rb | 8 --------
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb
index 8d0de1d..b7b6aa8 100644
--- a/lib/rainbows/response.rb
+++ b/lib/rainbows/response.rb
@@ -128,6 +128,11 @@ module Rainbows::Response
     unless IO.method_defined?(:trysendfile)
       module CopyStream
         def write_body_file(body, range)
+          # ensure sendfile gets used for SyncClose objects:
+          if !body.kind_of?(IO) && body.respond_to?(:to_path)
+            body = body.to_path
+          end
           range ? COPY_STREAM.copy_stream(body, self, range[1], range[0]) :
                   COPY_STREAM.copy_stream(body, self)
diff --git a/lib/rainbows/sync_close.rb b/lib/rainbows/sync_close.rb
index 8738cae..999f003 100644
--- a/lib/rainbows/sync_close.rb
+++ b/lib/rainbows/sync_close.rb
@@ -16,14 +16,6 @@ class Rainbows::SyncClose
-  def readpartial(*args)
-    @body.readpartial(*args)
-  end
-  def read(*args)
-    @body.read(*args)
-  end
   def to_path

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-10  1:52 [PATCH] " Eric Wong
2015-10-13 23:45 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://yhbt.net/rainbows/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151013234559.21457-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=rainbows-public@bogomips.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Rainbows! Rack HTTP server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/rainbows-public
	git clone --mirror http://ou63pmih66umazou.onion/rainbows-public

Example config snippet for mirrors

Newsgroups are available over NNTP:

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git