ruby-changes:19381
From: kosaki <ko1@a...>
Date: Wed, 4 May 2011 10:16:32 +0900 (JST)
Subject: [ruby-changes:19381] Ruby:r31421 (trunk): * ext/io/wait/wait.c (io_wait): use rb_wait_for_single_fd().
kosaki 2011-05-04 10:09:08 +0900 (Wed, 04 May 2011) New Revision: 31421 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31421 Log: * ext/io/wait/wait.c (io_wait): use rb_wait_for_single_fd(). The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531] Modified files: trunk/ChangeLog trunk/ext/io/wait/wait.c Index: ChangeLog =================================================================== --- ChangeLog (revision 31420) +++ ChangeLog (revision 31421) @@ -1,3 +1,8 @@ +Wed May 4 10:07:48 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * ext/io/wait/wait.c (io_wait): use rb_wait_for_single_fd(). + The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531] + Wed May 4 10:01:27 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * thread.c (rb_wait_for_single_fd): new. poll(2) based backend for rb_wait_for_single_fd(). Index: ext/io/wait/wait.c =================================================================== --- ext/io/wait/wait.c (revision 31420) +++ ext/io/wait/wait.c (revision 31421) @@ -88,22 +88,6 @@ return Qfalse; } -struct wait_readable_arg { - rb_fdset_t fds; - struct timeval *timeout; -}; - -#ifdef HAVE_RB_FD_INIT -static VALUE -wait_readable(VALUE p) -{ - struct wait_readable_arg *arg = (struct wait_readable_arg *)p; - rb_fdset_t *fds = &arg->fds; - - return (VALUE)rb_thread_fd_select(rb_fd_max(fds), fds, NULL, NULL, arg->timeout); -} -#endif - /* * call-seq: * io.wait -> IO, true, false or nil @@ -117,34 +101,26 @@ io_wait(int argc, VALUE *argv, VALUE io) { rb_io_t *fptr; - struct wait_readable_arg arg; - int fd, i; + int i; ioctl_arg n; VALUE timeout; struct timeval timerec; + struct timeval *tv; GetOpenFile(io, fptr); rb_io_check_readable(fptr); rb_scan_args(argc, argv, "01", &timeout); if (NIL_P(timeout)) { - arg.timeout = 0; + tv = NULL; } else { timerec = rb_time_interval(timeout); - arg.timeout = &timerec; + tv = &timerec; } if (rb_io_read_pending(fptr)) return Qtrue; if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse; - fd = fptr->fd; - rb_fd_init(&arg.fds); - rb_fd_set(fd, &arg.fds); -#ifdef HAVE_RB_FD_INIT - i = (int)rb_ensure(wait_readable, (VALUE)&arg, - (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds); -#else - i = rb_thread_fd_select(fd + 1, &arg.fds, NULL, NULL, arg.timeout); -#endif + i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, tv); if (i < 0) rb_sys_fail(0); rb_io_check_closed(fptr); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/