summaryrefslogtreecommitdiff
path: root/ext/io/wait
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 01:09:08 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 01:09:08 +0000
commitcd796c609fec41b412a78bd742c723b1d8319c61 (patch)
tree55d6193e382707eaf258fc731bc31f31dc422054 /ext/io/wait
parent249fe0e74252af65c3e2e47a5e9e27eb839ad7c0 (diff)
* 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
Diffstat (limited to 'ext/io/wait')
-rw-r--r--ext/io/wait/wait.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c
index 93de56000b7..34e832b122e 100644
--- a/ext/io/wait/wait.c
+++ b/ext/io/wait/wait.c
@@ -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);