Object
Yields self
in non-blocking mode.
When false
is given as an argument, self
is yielded in blocking mode. The original mode is restored after the block is executed.
static VALUE rb_io_nonblock_block(int argc, VALUE *argv, VALUE io) { int nb = 1; rb_io_t *fptr; int f, restore[2]; GetOpenFile(io, fptr); if (argc > 0) { VALUE v; rb_scan_args(argc, argv, "01", &v); nb = RTEST(v); } f = io_nonblock_mode(fptr->fd); restore[0] = fptr->fd; restore[1] = f; if (!io_nonblock_set(fptr->fd, f, nb)) return rb_yield(io); return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore); }
Enables non-blocking mode on a stream when set to true
, and blocking mode when set to false
.
static VALUE rb_io_nonblock_set(VALUE io, VALUE nb) { rb_io_t *fptr; GetOpenFile(io, fptr); if (RTEST(nb)) rb_io_set_nonblock(fptr); else io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb)); return io; }
Returns true
if an IO
object is in non-blocking mode.
static VALUE rb_io_nonblock_p(VALUE io) { rb_io_t *fptr; GetOpenFile(io, fptr); if (io_nonblock_mode(fptr->fd) & O_NONBLOCK) return Qtrue; return Qfalse; }