about summary refs log tree commit homepage
diff options
context:
space:
mode:
authornormalperson@yhbt.net <normalperson@yhbt.net>2013-04-29 20:07:52 +0000
committerEric Wong <normalperson@yhbt.net>2013-04-29 21:01:02 +0000
commita974d3acb4cf59696c71f82004e2b42d1c1903d9 (patch)
treeaf25d48e564882addbdd4fbc545461c7f1fc6309
parentdbcc2af6f5ec958fb71d96d20ebdcd7860be8274 (diff)
downloadsleepy_penguin-a974d3acb4cf59696c71f82004e2b42d1c1903d9.tar.gz
First off, the timeout is not handled properly when timing out,
resulting in an infinite loop.

Secondly, arguments were not passed to the yielded block correctly.

Finally, the return value of kevent was not returned correctly to
the caller.
-rw-r--r--lib/sleepy_penguin/kqueue/io.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sleepy_penguin/kqueue/io.rb b/lib/sleepy_penguin/kqueue/io.rb
index 1e5809d..15502d4 100644
--- a/lib/sleepy_penguin/kqueue/io.rb
+++ b/lib/sleepy_penguin/kqueue/io.rb
@@ -15,11 +15,12 @@ class SleepyPenguin::Kqueue::IO
       expire_at = timeout ? Time.now + timeout : nil
       begin
         IO.select([self], nil, nil, timeout)
-        n = __kevent(changelist, nevents, 0) do |a,b,c,d,e,f|
-          yield a, b, c, d, e
+        n = __kevent(changelist, nevents, 0) do |*args|
+          yield(*args)
         end
-      end while n == 0 &&
+      end while n == 0 && timeout != 0 &&
                 (expire_at == nil || timeout = __update_timeout(expire_at))
+      n
     else
       # nevents should be zero or nil here
       __kevent(changelist, nevents, 0)