about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-07 08:30:22 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-08 07:58:59 +0000
commit13baf8bd44683a376b79c01c3abbaa71e5b86a71 (patch)
tree13f7b00b6d0fa1093b9c8b3796150750929eda5b /lib
parent9ce364b079efdb3bcef504a84e2460a9b2b4b9ad (diff)
downloadrainbows-13baf8bd44683a376b79c01c3abbaa71e5b86a71.tar.gz
Other concurrency models will eventually be able to use it, too.
Diffstat (limited to 'lib')
-rw-r--r--lib/rainbows.rb1
-rw-r--r--lib/rainbows/rev/sendfile.rb7
-rw-r--r--lib/rainbows/stream_file.rb14
3 files changed, 16 insertions, 6 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index b1ec220..3ea98ed 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -123,4 +123,5 @@ module Rainbows
   # :startdoc:
   autoload :Fiber, 'rainbows/fiber' # core class
   autoload :ByteSlice, 'rainbows/byte_slice'
+  autoload :StreamFile, 'rainbows/stream_file'
 end
diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb
index 11cd114..ae0b116 100644
--- a/lib/rainbows/rev/sendfile.rb
+++ b/lib/rainbows/rev/sendfile.rb
@@ -1,12 +1,7 @@
 # -*- encoding: binary -*-
 module Rainbows::Rev::Sendfile
   if IO.method_defined?(:sendfile_nonblock)
-    class F < Struct.new(:offset, :to_io)
-      def close
-        to_io.close
-        self.to_io = nil
-      end
-    end
+    F = Rainbows::StreamFile
 
     def to_sendfile(io)
       F[0, io]
diff --git a/lib/rainbows/stream_file.rb b/lib/rainbows/stream_file.rb
new file mode 100644
index 0000000..f533f18
--- /dev/null
+++ b/lib/rainbows/stream_file.rb
@@ -0,0 +1,14 @@
+# -*- encoding: binary -*-
+# :enddoc:
+
+# Used to keep track of file offsets in IO#sendfile_nonblock + evented
+# models.  We always maintain our own file offsets in userspace because
+# because sendfile() implementations offer pread()-like idempotency for
+# concurrency (multiple clients can read the same underlying file handle).
+class Rainbows::StreamFile < Struct.new(:offset, :to_io)
+
+  def close
+    to_io.close
+    self.to_io = nil
+  end
+end