[前][次][番号順一覧][スレッド一覧]

ruby-changes:19389

From: kosaki <ko1@a...>
Date: Wed, 4 May 2011 19:04:57 +0900 (JST)
Subject: [ruby-changes:19389] Ruby:r31429 (trunk): * thread.c (rb_wait_for_single_fd): Fix wrong return value.

kosaki	2011-05-04 19:02:06 +0900 (Wed, 04 May 2011)

  New Revision: 31429

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31429

  Log:
    * thread.c (rb_wait_for_single_fd): Fix wrong return value.
    * test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb
    (TestWaitForSingleFD#test_wait_for_closed_pipe): test for it.

  Modified files:
    trunk/ChangeLog
    trunk/test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31428)
+++ ChangeLog	(revision 31429)
@@ -1,3 +1,9 @@
+Wed May  4 19:00:59 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* thread.c (rb_wait_for_single_fd): Fix wrong return value.
+	* test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb
+	(TestWaitForSingleFD#test_wait_for_closed_pipe): test for it.
+
 Wed May  4 18:46:39 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* ext/-test-/wait_for_single_fd: New. for testing
Index: thread.c
===================================================================
--- thread.c	(revision 31428)
+++ thread.c	(revision 31429)
@@ -2714,6 +2714,13 @@
 #endif
 
 #ifdef USE_POLL
+
+
+/* The same with linux kernel. TODO: make platform independent definition. */
+#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
+#define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
+#define POLLEX_SET (POLLPRI)
+
 /*
  * returns a mask of events
  */
@@ -2736,15 +2743,6 @@
 	if (result < 0) lerrno = errno;
     }, ubf_select, GET_THREAD());
 
-    if (result > 0) {
-	if (fds.revents & POLLNVAL) {
-	    errno = EBADF;
-	    return -1;
-	}
-	result = (int)(fds.revents & fds.events);
-	return result == 0 ? events : result;
-    }
-
     if (result < 0) {
 	errno = lerrno;
 	switch (errno) {
@@ -2759,8 +2757,26 @@
 	    }
 	    goto retry;
 	}
+	return -1;
     }
 
+    if (fds.revents & POLLNVAL) {
+	errno = EBADF;
+	return -1;
+    }
+
+    /*
+     * POLLIN, POLLOUT have a different meanings from select(2)'s read/write bit.
+     * Therefore we need fix it up.
+     */
+    result = 0;
+    if (fds.revents & POLLIN_SET)
+	result |= RB_WAITFD_IN;
+    if (fds.revents & POLLOUT_SET)
+	result |= RB_WAITFD_OUT;
+    if (fds.revents & POLLEX_SET)
+	result |= RB_WAITFD_PRI;
+
     return result;
 }
 #else /* ! USE_POLL - implement rb_io_poll_fd() using select() */
Index: test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb
===================================================================
--- test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb	(revision 31428)
+++ test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb	(revision 31429)
@@ -29,4 +29,14 @@
       end
     end
   end
+
+  def test_wait_for_closed_pipe
+    with_pipe do |r,w|
+      w.close
+      rc = IO.wait_for_single_fd(r.fileno, RB_WAITFD_IN, nil)
+      assert_equal RB_WAITFD_IN, rc
+    end
+  end
+
+
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]