From 9be37ca7d51513658f5f84d98fa5e46026cc5a04 Mon Sep 17 00:00:00 2001 From: kosaki Date: Wed, 4 May 2011 00:59:57 +0000 Subject: * thread.c (rb_wait_for_single_fd): new. * thread.c (select_single): select(2) based backend for rb_wait_for_single_fd(). * io.c (make_writeconv): use rb_wait_for_single_fd() instaed of rb_thread_fd_select(). * io.c (rb_io_wait_readable): ditto. * thread.c (rb_thread_wait_fd_rw): ditto. * io.c (wait_readable): removed. * thread.c (init_set_fd): new helper function. * include/ruby/io.h (RB_WAITFD_IN, RB_WAITFD_PRI, RB_WAITFD_OUT): new constant for rb_single_wait_fd(). The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 1278e7fa5b..425ef8083a 100644 --- a/io.c +++ b/io.c @@ -685,21 +685,9 @@ io_fflush(rb_io_t *fptr) return 0; } -#ifdef HAVE_RB_FD_INIT -static VALUE -wait_readable(VALUE p) -{ - rb_fdset_t *rfds = (rb_fdset_t *)p; - - return rb_thread_fd_select(rb_fd_max(rfds), rfds, NULL, NULL, NULL); -} -#endif - int rb_io_wait_readable(int f) { - rb_fdset_t rfds; - if (f < 0) { rb_raise(rb_eIOError, "closed stream"); } @@ -715,14 +703,7 @@ rb_io_wait_readable(int f) #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - rb_fd_init(&rfds); - rb_fd_set(f, &rfds); -#ifdef HAVE_RB_FD_INIT - rb_ensure(wait_readable, (VALUE)&rfds, - (VALUE (*)(VALUE))rb_fd_term, (VALUE)&rfds); -#else - rb_thread_fd_select(f + 1, &rfds, NULL, NULL, NULL); -#endif + rb_wait_for_single_fd(f, RB_WAITFD_IN, NULL); return TRUE; default: @@ -730,21 +711,9 @@ rb_io_wait_readable(int f) } } -#ifdef HAVE_RB_FD_INIT -static VALUE -wait_writable(VALUE p) -{ - rb_fdset_t *wfds = (rb_fdset_t *)p; - - return rb_thread_fd_select(rb_fd_max(wfds), NULL, wfds, NULL, NULL); -} -#endif - int rb_io_wait_writable(int f) { - rb_fdset_t wfds; - if (f < 0) { rb_raise(rb_eIOError, "closed stream"); } @@ -760,14 +729,7 @@ rb_io_wait_writable(int f) #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - rb_fd_init(&wfds); - rb_fd_set(f, &wfds); -#ifdef HAVE_RB_FD_INIT - rb_ensure(wait_writable, (VALUE)&wfds, - (VALUE (*)(VALUE))rb_fd_term, (VALUE)&wfds); -#else - rb_thread_fd_select(f + 1, NULL, &wfds, NULL, NULL); -#endif + rb_wait_for_single_fd(f, RB_WAITFD_OUT, NULL); return TRUE; default: -- cgit v1.2.3