read_nonblock(...)
public
Reads at most maxlen bytes from
ios using read(2) system call after O_NONBLOCK is set for the
underlying file descriptor.
If the optional outbuf argument is present, it must reference a String, which will receive the data.
read_nonblock just calls read(2). It
causes all errors read(2) causes: EAGAIN, EINTR, etc. The caller should
care such errors.
read_nonblock causes EOFError on EOF.
If the read buffer is not empty, read_nonblock reads from the buffer like
readpartial. In this case, read(2) is
not called.
Show source
/*
* call-seq:
* ios.read_nonblock(maxlen) => string
* ios.read_nonblock(maxlen, outbuf) => outbuf
*
* Reads at most <i>maxlen</i> bytes from <em>ios</em> using
* read(2) system call after O_NONBLOCK is set for
* the underlying file descriptor.
*
* If the optional <i>outbuf</i> argument is present,
* it must reference a String, which will receive the data.
*
* read_nonblock just calls read(2).
* It causes all errors read(2) causes: EAGAIN, EINTR, etc.
* The caller should care such errors.
*
* read_nonblock causes EOFError on EOF.
*
* If the read buffer is not empty,
* read_nonblock reads from the buffer like readpartial.
* In this case, read(2) is not called.
*
*/
static VALUE
io_read_nonblock(int argc, VALUE *argv, VALUE io)
{
VALUE ret;
ret = io_getpartial(argc, argv, io, 1);
if (NIL_P(ret))
rb_eof_error();
else
return ret;
}