method
__read_nonblock

v2_6_3 -
Show latest stable
-
0 notes -
Class: IO
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
__read_nonblock(p1, p2, p3)
private
Hide source
static VALUE io_read_nonblock(VALUE io, VALUE length, VALUE str, VALUE ex) { rb_io_t *fptr; long n, len; struct io_internal_read_struct iis; 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); iis.fd = fptr->fd; iis.nonblock = 1; iis.buf = RSTRING_PTR(str); iis.capa = len; n = read_internal_locktmp(str, &iis); 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; }