1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2011-05-04 01:09:08 +00:00
parent 249fe0e742
commit cd796c609f
2 changed files with 10 additions and 29 deletions

View file

@ -1,3 +1,8 @@
Wed May 4 10:07:48 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* 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@gmail.com>
* thread.c (rb_wait_for_single_fd): new. poll(2) based backend for rb_wait_for_single_fd().

View file

@ -88,22 +88,6 @@ io_ready_p(VALUE io)
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 @@ static VALUE
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);