method
__read_nonblock
v2_5_5 -
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 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; }