method

__read_nonblock

Importance_0
v2_5_5 - Show latest stable - 0 notes - Class: IO
__read_nonblock(p1, p2, p3) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
static VALUE
io_read_nonblock(VALUE io, VALUE length, VALUE str, VALUE ex)
{
    rb_io_t *fptr;
    long n, len;
    struct read_internal_arg arg;
    int shrinkable;

    if ((len = NUM2LONG(length)) < 0) {
        rb_raise(rb_eArgError, "negative length %ld given", len);
    }

    shrinkable = io_setstrbuf(&str, len);
    OBJ_TAINT(str);
    GetOpenFile(io, fptr);
    rb_io_check_byte_readable(fptr);

    if (len == 0)
        return str;

    n = read_buffered_data(RSTRING_PTR(str), len, fptr);
    if (n <= 0) {
        rb_io_set_nonblock(fptr);
        shrinkable |= io_setstrbuf(&str, len);
        arg.fd = fptr->fd;
        arg.str_ptr = RSTRING_PTR(str);
        arg.len = len;
        rb_str_locktmp_ensure(str, read_internal_call, (VALUE)&arg);
        n = arg.len;
        if (n < 0) {
            int e = errno;
            if ((e == EWOULDBLOCK || e == EAGAIN)) {
                if (ex == Qfalse) return sym_wait_readable;
                rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
                                         e, "read would block");
            }
            rb_syserr_fail_path(e, fptr->pathv);
        }
    }
    io_set_read_length(str, n, shrinkable);

    if (n == 0) {
        if (ex == Qfalse) return Qnil;
        rb_eof_error();
    }

    return str;
}
Register or log in to add new notes.