about summary refs log tree commit homepage
path: root/lib/rainbows/epoll/response_pipe.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-01-19 15:06:10 -0800
committerEric Wong <normalperson@yhbt.net>2011-01-19 15:06:27 -0800
commit9424b13255a238dfa44952ebeb07bea3acee999c (patch)
tree9a517e9b22a3cc73c9ad16c9288eedf09ac18b8a /lib/rainbows/epoll/response_pipe.rb
parent7a04133c1ab57923cac8a9de04b00bfe89bcce2d (diff)
downloadrainbows-9424b13255a238dfa44952ebeb07bea3acee999c.tar.gz
Coolio and EventMachine only use level-triggered epoll,
but being Rainbows!, we live on the EDGE!
Diffstat (limited to 'lib/rainbows/epoll/response_pipe.rb')
-rw-r--r--lib/rainbows/epoll/response_pipe.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/rainbows/epoll/response_pipe.rb b/lib/rainbows/epoll/response_pipe.rb
new file mode 100644
index 0000000..ce240f5
--- /dev/null
+++ b/lib/rainbows/epoll/response_pipe.rb
@@ -0,0 +1,38 @@
+# -*- encoding: binary -*-
+# :enddoc:
+#
+class Rainbows::Epoll::ResponsePipe
+  include Rainbows::Epoll::State
+  attr_reader :io
+  alias to_io io
+  IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ET
+  RBUF = Rainbows::EvCore::RBUF
+
+  def initialize(io, client, body)
+    @io, @client, @body = io, client, body
+    @epoll_active = false
+  end
+
+  def epoll_run
+    return close if @client.closed?
+    @client.stream_pipe(self) or @client.on_deferred_write_complete
+    rescue => e
+      close
+      @client.handle_error(e)
+  end
+
+  def close
+    epoll_disable
+    @body.respond_to?(:close) and @body.close
+    @io = @body = nil
+  end
+
+  def tryread
+    io = @io
+    io.respond_to?(:kgio_tryread) and return io.kgio_tryread(16384, RBUF)
+    io.read_nonblock(16384, RBUF)
+    rescue Errno::EAGAIN
+      :wait_readable
+    rescue EOFError
+  end
+end