about summary refs log tree commit homepage
path: root/lib/rainbows/rev/sendfile.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rainbows/rev/sendfile.rb')
-rw-r--r--lib/rainbows/rev/sendfile.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb
new file mode 100644
index 0000000..9ab28bd
--- /dev/null
+++ b/lib/rainbows/rev/sendfile.rb
@@ -0,0 +1,15 @@
+# -*- encoding: binary -*-
+module Rainbows::Rev::Sendfile
+  if IO.method_defined?(:sendfile_nonblock)
+    def rev_sendfile(body)
+      body.pos += @_io.sendfile_nonblock(body, body.pos, 0x10000)
+      rescue Errno::EAGAIN
+      ensure
+        enable_write_watcher
+    end
+  else
+    def rev_sendfile(body)
+      write(body.sysread(0x4000))
+    end
+  end
+end