about summary refs log tree commit homepage
path: root/lib/rainbows/coolio/sendfile.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-28 17:59:27 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-28 18:00:04 -0800
commit40445641f11f01c6a24bf96c8b80eed5fd33a512 (patch)
tree57a7652cc03f46407d51babfd04d72d1c401ac99 /lib/rainbows/coolio/sendfile.rb
parent3495d59763e6159975debf32728dc53fc41c5ea1 (diff)
downloadrainbows-40445641f11f01c6a24bf96c8b80eed5fd33a512.tar.gz
complete Rev => Coolio renaming
We use Cool.io internally everywhere now, but preserve
Rev-based models for anybody using them.
Diffstat (limited to 'lib/rainbows/coolio/sendfile.rb')
-rw-r--r--lib/rainbows/coolio/sendfile.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/rainbows/coolio/sendfile.rb b/lib/rainbows/coolio/sendfile.rb
new file mode 100644
index 0000000..ead51a8
--- /dev/null
+++ b/lib/rainbows/coolio/sendfile.rb
@@ -0,0 +1,17 @@
+# -*- encoding: binary -*-
+# :enddoc:
+module Rainbows::Coolio::Sendfile
+  if IO.method_defined?(:sendfile_nonblock)
+    def rev_sendfile(sf) # +sf+ is a Rainbows::StreamFile object
+      sf.offset += (n = @_io.sendfile_nonblock(sf, sf.offset, sf.count))
+      0 == (sf.count -= n) and raise EOFError
+      enable_write_watcher
+      rescue Errno::EAGAIN
+        enable_write_watcher
+    end
+  else
+    def rev_sendfile(body)
+      write(body.to_io.sysread(0x4000))
+    end
+  end
+end