Object
# File io/wait/lib/nonblock.rb, line 17
def nonblock(nb = true)
nb, self.nonblock = nonblock?, nb
yield
ensure
self.nonblock = nb
end
# File io/wait/lib/nonblock.rb, line 7
def nonblock=(nb)
f = fcntl(Fcntl::F_GETFL)
if nb
f |= File::NONBLOCK
else
f &= ~File::NONBLOCK
end
fcntl(Fcntl::F_SETFL, f)
end
# File io/wait/lib/nonblock.rb, line 3
def nonblock?
(fcntl(Fcntl::F_GETFL) & File::NONBLOCK) != 0
end
/*
static VALUE
io_ready_p(io)
VALUE io;
{
OpenFile *fptr;
FILE *fp;
ioctl_arg n;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
fp = fptr->f;
if (feof(fp)) return Qfalse;
if (rb_read_pending(fp)) return Qtrue;
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return ioctl_arg2num(n);
return Qnil;
}
/*
static VALUE
io_wait(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
OpenFile *fptr;
fd_set rd;
FILE *fp;
int fd;
ioctl_arg n;
VALUE timeout;
struct timeval *tp, timerec;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
if (NIL_P(timeout)) {
tp = 0;
}
else {
timerec = rb_time_interval(timeout);
tp = &timerec;
}
fp = fptr->f;
if (feof(fp)) return Qfalse;
if (rb_read_pending(fp)) return Qtrue;
fd = fileno(fp);
FD_ZERO(&rd);
FD_SET(fd, &rd);
if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
return Qnil;
}
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.