about summary refs log tree commit homepage
path: root/lib/rainbows/epoll
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-10 15:06:10 -0800
committerEric Wong <normalperson@yhbt.net>2011-03-10 15:06:10 -0800
commitcd8a874d18fe01e11bb57b91186b6c9f712a4b3f (patch)
treea8400f2e6eeca1a4d4a686e138b97eb831eb9a8d /lib/rainbows/epoll
parentafea5cd7c691de95b37d29728ab4880e3b737a42 (diff)
downloadrainbows-cd8a874d18fe01e11bb57b91186b6c9f712a4b3f.tar.gz
IO#trysendfile does not raise exceptions for common EAGAIN
errors, making it far less expensive to use with the following
concurrency models:

* Coolio
* CoolioFiberSpawn
* Revactor
* FiberSpawn
* FiberPool

This requires the new sendfile 1.1.0 RubyGem and removes support
for the sendfile 1.0.0.  All sendfile users must upgrade or be
left without sendfile(2) support.  IO#sendfile behaves the same
if you're using a multi-threaded concurrency option, but we
don't detect nor use it unless IO#trysendfile exists.
Diffstat (limited to 'lib/rainbows/epoll')
-rw-r--r--lib/rainbows/epoll/client.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index a243d5d..b7b0c9e 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -183,15 +183,16 @@ module Rainbows::Epoll::Client
 
   # returns +nil+ on EOF, :wait_writable if the client blocks
   def stream_file(sf) # +sf+ is a Rainbows::StreamFile object
-    begin
-      sf.offset += (n = sendfile_nonblock(sf, sf.offset, sf.count))
+    case n = trysendfile(sf, sf.offset, sf.count)
+    when Integer
+      sf.offset += n
       0 == (sf.count -= n) and return sf.close
-    rescue Errno::EAGAIN
-      return :wait_writable
+    else
+      return n # :wait_writable or nil
+    end while true
     rescue
       sf.close
       raise
-    end while true
   end
 
   def defer_file_stream(offset, count, io, body)