From 13baf8bd44683a376b79c01c3abbaa71e5b86a71 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 7 Jul 2010 08:30:22 +0000 Subject: stream_file: split this out from rev/sendfile Other concurrency models will eventually be able to use it, too. --- lib/rainbows/rev/sendfile.rb | 7 +------ lib/rainbows/stream_file.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 lib/rainbows/stream_file.rb (limited to 'lib/rainbows') 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 -- cgit v1.2.3-24-ge0c7