instance method
IO#nonblock
io.nonblock {|io| } → object
io.nonblock(boolean) {|io| } → object
ext/io/nonblock/nonblock.c
View on GitHub ↗
static VALUE
rb_io_nonblock_block(int argc, VALUE *argv, VALUE self)
{
int nb = 1;
int descriptor = rb_io_descriptor(self);
if (argc > 0) {
VALUE v;
rb_scan_args(argc, argv, "01", &v);
nb = RTEST(v);
}
int current_flags = get_fcntl_flags(descriptor);
int restore[2] = {descriptor, current_flags};
if (!io_nonblock_set(descriptor, current_flags, nb))
return rb_yield(self);
return rb_ensure(rb_yield, self, io_nonblock_restore, (VALUE)restore);
}
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.