diff --git a/io.c b/io.c index 0fe0d7a4b2..9ebf62d69d 100644 --- a/io.c +++ b/io.c @@ -1996,6 +1996,16 @@ rb_io_rewind(VALUE io) return INT2FIX(0); } +static int +fptr_wait_readable(rb_io_t *fptr) +{ + int ret = rb_io_wait_readable(fptr->fd); + + if (ret) + rb_io_check_closed(fptr); + return ret; +} + static int io_fillbuf(rb_io_t *fptr) { @@ -2016,7 +2026,7 @@ io_fillbuf(rb_io_t *fptr) r = rb_read_internal(fptr->fd, fptr->rbuf.ptr, fptr->rbuf.capa); } if (r < 0) { - if (rb_io_wait_readable(fptr->fd)) + if (fptr_wait_readable(fptr)) goto retry; { int e = errno; @@ -2363,7 +2373,7 @@ io_bufread(char *ptr, long len, rb_io_t *fptr) c = rb_read_internal(fptr->fd, ptr+offset, n); if (c == 0) break; if (c < 0) { - if (rb_io_wait_readable(fptr->fd)) + if (fptr_wait_readable(fptr)) goto again; return -1; } @@ -2788,7 +2798,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, VALUE opts, int nonblock) n = arg.len; if (n < 0) { int e = errno; - if (!nonblock && rb_io_wait_readable(fptr->fd)) + if (!nonblock && fptr_wait_readable(fptr)) goto again; if (nonblock && (e == EWOULDBLOCK || e == EAGAIN)) { if (no_exception_p(opts))