about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2011-02-04 06:00:20 +0000
committerEric Wong <e@yhbt.net>2011-02-04 06:26:06 +0000
commitc02141cbfa965a19b236e4f9a09856bd2fcacca0 (patch)
treed7ecd897bee9127a20d5c61f08299245260b491e
parent9dda070b66753e04a179e0cd36d1eff29195a7cb (diff)
downloadsleepy_penguin-c02141cbfa965a19b236e4f9a09856bd2fcacca0.tar.gz
It's often used to drive event loops and EINTR should be
retried by the user (like IO.select and not like
IO#read_nonblock).
-rw-r--r--ext/sleepy_penguin/epoll.c17
-rw-r--r--test/test_epoll.rb6
2 files changed, 8 insertions, 15 deletions
diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c
index 986ecc9..4630307 100644
--- a/ext/sleepy_penguin/epoll.c
+++ b/ext/sleepy_penguin/epoll.c
@@ -355,12 +355,7 @@ static VALUE nogvl_wait(void *args)
 
 static VALUE real_epwait(struct rb_epoll *ep)
 {
-        int n;
-
-        do {
-                n = (int)rb_thread_blocking_region(nogvl_wait, ep,
-                                                   RUBY_UBF_IO, 0);
-        } while (n == -1 && errno == EINTR);
+        int n = (int)rb_thread_blocking_region(nogvl_wait, ep, RUBY_UBF_IO, 0);
 
         return epwait_result(ep, n);
 }
@@ -403,7 +398,7 @@ static int epwait_forever(struct rb_epoll *ep)
         do {
                 (void)rb_io_wait_readable(ep->fd);
                 n = safe_epoll_wait(ep);
-        } while (n == 0 || (n == -1 && errno == EINTR));
+        } while (n == 0);
 
         return n;
 }
@@ -426,13 +421,7 @@ static int epwait_timed(struct rb_epoll *ep)
                 gettimeofday(&t0, NULL);
                 (void)rb_thread_select(ep->fd + 1, &rfds, NULL, NULL, &tv);
                 n = safe_epoll_wait(ep);
-
-                /*
-                 * if we got EINTR from epoll_wait /and/ timed out
-                 * just consider it a timeout and don't raise an error
-                 */
-
-                if (n > 0 || (n == -1 && errno != EINTR))
+                if (n != 0)
                         return n;
 
                 /* XXX use CLOCK_MONOTONIC if people care about 1.8... */
diff --git a/test/test_epoll.rb b/test/test_epoll.rb
index 6e1b768..b75c2b7 100644
--- a/test/test_epoll.rb
+++ b/test/test_epoll.rb
@@ -129,7 +129,11 @@ class TestEpoll < Test::Unit::TestCase
       Process.kill(:USR1, Process.ppid)
     end
     time[:START_WAIT] = Time.now
-    @ep.wait { |flags, obj| tmp << [ flags, obj ]; time[:EP] = Time.now }
+    begin
+      @ep.wait { |flags, obj| tmp << [ flags, obj ]; time[:EP] = Time.now }
+    rescue Errno::EINTR
+      retry
+    end
     assert_equal([[Epoll::IN, @rd]], tmp)
     _, status = Process.waitpid2(pid)
     assert status.success?