about summary refs log tree commit homepage
path: root/lib/rainbows/epoll/state.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/state.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/state.rb')
-rw-r--r--lib/rainbows/epoll/state.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/rainbows/epoll/state.rb b/lib/rainbows/epoll/state.rb
new file mode 100644
index 0000000..6e554be
--- /dev/null
+++ b/lib/rainbows/epoll/state.rb
@@ -0,0 +1,22 @@
+# -*- encoding: binary -*-
+# :enddoc:
+# used to keep track of state for each descriptor and avoid
+# unneeded syscall or ENONENT overhead
+module Rainbows::Epoll::State
+  EP = SleepyPenguin::Epoll.new
+
+  def epoll_disable
+    @epoll_active or return
+    @epoll_active = false
+    EP.del(self)
+  end
+
+  def epoll_enable(flags)
+    if @epoll_active
+      flags == @epoll_active or
+        EP.mod(self, @epoll_active = flags)
+    else
+      EP.add(self, @epoll_active = flags)
+    end
+  end
+end