* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2a989121db
commit
c06da4735d
@ -1,3 +1,9 @@
|
|||||||
|
Wed May 4 19:00:59 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* 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@gmail.com>
|
Wed May 4 18:46:39 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* ext/-test-/wait_for_single_fd: New. for testing
|
* ext/-test-/wait_for_single_fd: New. for testing
|
||||||
|
@ -29,4 +29,14 @@ class TestWaitForSingleFD < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
34
thread.c
34
thread.c
@ -2714,6 +2714,13 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POLL
|
#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
|
* returns a mask of events
|
||||||
*/
|
*/
|
||||||
@ -2736,15 +2743,6 @@ retry:
|
|||||||
if (result < 0) lerrno = errno;
|
if (result < 0) lerrno = errno;
|
||||||
}, ubf_select, GET_THREAD());
|
}, 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) {
|
if (result < 0) {
|
||||||
errno = lerrno;
|
errno = lerrno;
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
@ -2759,8 +2757,26 @@ retry:
|
|||||||
}
|
}
|
||||||
goto retry;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
#else /* ! USE_POLL - implement rb_io_poll_fd() using select() */
|
#else /* ! USE_POLL - implement rb_io_poll_fd() using select() */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user