about summary refs log tree commit homepage
path: root/lib/rainbows/epoll/client.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-19 23:54:59 -0700
committerEric Wong <normalperson@yhbt.net>2011-05-20 08:32:39 +0000
commit90af18f6884857704d72fd6b2bb91718aad72117 (patch)
tree3aad09eaac6d20d8f158d1fd7b1caad53f27ce2f /lib/rainbows/epoll/client.rb
parent5e4f790847198e1267b2fbd5decfa09e5cc3d618 (diff)
downloadrainbows-90af18f6884857704d72fd6b2bb91718aad72117.tar.gz
There's less logic in the server this way and easier
to potentially share code this way.
Diffstat (limited to 'lib/rainbows/epoll/client.rb')
-rw-r--r--lib/rainbows/epoll/client.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index 0d6a8c0..e23d4e7 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -11,7 +11,8 @@ module Rainbows::Epoll::Client
   KATO = {}
   KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
   Rainbows.config!(self, :keepalive_timeout)
-  EP = Rainbows::Epoll::EP
+  EP = Rainbows::EP
+  ReRun = []
   @@last_expire = Time.now
 
   def self.expire
@@ -23,6 +24,19 @@ module Rainbows::Epoll::Client
     @@last_expire = now
   end
 
+  def self.loop
+    begin
+      EP.wait(nil, 1000) { |_, obj| obj.epoll_run }
+      while obj = ReRun.shift
+        obj.epoll_run
+      end
+      expire
+    rescue Errno::EINTR
+    rescue => e
+      Rainbows::Error.listen_loop(e)
+    end while Rainbows.tick || Server.nr > 0
+  end
+
   # only call this once
   def epoll_once
     @wr_queue = [] # may contain String, ResponsePipe, and StreamFile objects
@@ -100,7 +114,7 @@ module Rainbows::Epoll::Client
   end
 
   def want_more
-    Rainbows::Epoll::ReRun << self
+    ReRun << self
   end
 
   def on_deferred_write_complete