Method: IO#nread

Defined in:
wait/wait.c

#nreadInteger

Returns number of bytes that can be read without blocking. Returns zero if no information available.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'wait/wait.c', line 51

static VALUE
io_nread(VALUE io)
{
    rb_io_t *fptr = NULL;
    ioctl_arg n;

    GetOpenFile(io, fptr);
    rb_io_check_readable(fptr);
    int len = rb_io_read_pending(fptr);
    if (len > 0) return INT2FIX(len);
    if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
    if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
    if (n > 0) return ioctl_arg2num(n);
    return INT2FIX(0);
}