From: Motohiro KOSAKI Date: 2011-05-04T09:29:26+09:00 Subject: [ruby-core:35987] [Ruby 1.9 - Feature #4531] [PATCH 0/7] use poll() instead of select() in certain cases Issue #4531 has been updated by Motohiro KOSAKI. ----------------------------------------------------------------------- int rb_wait_for_single_fd(int fd, int events, struct timeval *tv) { (snip) BLOCKING_REGION({ result = poll(&fds, 1, timeout); if (result < 0) lerrno = errno; }, ubf_select, GET_THREAD()); if (result > 0) { /* remain compatible with select(2)-based implementation */ result = (int)(fds.revents & fds.events); return result == 0 ? events : result; } ----------------------------------------------------------------------- It's really unclear comment. select_internal() doesn't have such quirk. Can you please clarify this? -------------------------------------------------------------------------------- static VALUE select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds) { (snip) n = rb_thread_fd_select(max, rp, wp, ep, tp); if (n < 0) { rb_sys_fail(0); } if (!pending && n == 0) return Qnil; /* returns nil on timeout */ ---------------------------------------- Feature #4531: [PATCH 0/7] use poll() instead of select() in certain cases http://redmine.ruby-lang.org/issues/4531 Author: Eric Wong Status: Open Priority: Low Assignee: Motohiro KOSAKI Category: core Target version: 1.9.x =begin ref: [ruby-core:35527] This adds a new C API function with the following prototype: rb_io_poll_fd(int fd, short events, int timeout); It is emulated using select() for platforms that we do not support poll() for. It is much easier to use than rb_thread_select() and rb_thread_fd_select() for the common case in C extensions[1]. For Linux (and eventually any other platforms where poll() works for all select()-able files), we actually implement rb_io_poll_fd() using the poll() system call which means it is faster for high numbered file descriptors and does not put malloc pressure on the garbage collector. Lastly, since IO.select() is commonly used with a single IO object in my experience, we will try to use rb_io_poll_fd() in that case. There is also a new testcase for io/wait since I needed to verify my changes to ext/io/wait.c were correct. No failures were introduced to test-all and test-rubyspec targets with either the select() or poll()-based implementation of rb_io_poll_fd() on my platform (Linux x86_64) [1] see patches for changes I made in ext/socket/init.c, ext/io/wait.c, and ext/readline/readline.c: $ git diff --stat origin/trunk -- ext ext/io/wait/wait.c | 34 +++------------------- ext/readline/readline.c | 6 +--- ext/socket/init.c | 72 ++++++++--------------------------------------- 3 files changed, 18 insertions(+), 94 deletions(-) =end -- http://redmine.ruby-lang.org