diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -1484,6 +1484,7 @@ io_fread(VALUE str, long offset, rb_io_t *fptr) long n = len; long c; + rb_str_locktmp(str); if (READ_DATA_PENDING(fptr) == 0) { while (n > 0) { again: @@ -1501,6 +1502,7 @@ io_fread(VALUE str, long offset, rb_io_t *fptr) if ((n -= c) <= 0) break; rb_thread_wait_fd(fptr->fd); } + rb_str_unlocktmp(str); return len - n; } @@ -1516,6 +1518,7 @@ io_fread(VALUE str, long offset, rb_io_t *fptr) break; } } + rb_str_unlocktmp(str); return len - n; } @@ -1807,18 +1810,15 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock) if (!nonblock) READ_CHECK(fptr); - if (RSTRING_LEN(str) != len) { - modified: - rb_raise(rb_eRuntimeError, "buffer string modified"); - } n = read_buffered_data(RSTRING_PTR(str), len, fptr); if (n <= 0) { again: - if (RSTRING_LEN(str) != len) goto modified; if (nonblock) { rb_io_set_nonblock(fptr); } + rb_str_locktmp(str); n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len); + rb_str_unlocktmp(str); if (n < 0) { if (!nonblock && rb_io_wait_readable(fptr->fd)) goto again; @@ -1938,14 +1938,21 @@ io_readpartial(int argc, VALUE *argv, VALUE io) * until io is readable for avoiding busy loop. * This can be done as follows. * + * # emulates blocking read (readpartial). * begin * result = io.read_nonblock(maxlen) - * rescue IO::WaitReadable, Errno::EINTR + * rescue IO::WaitReadable * IO.select([io]) * retry * end * - * Note that this is identical to readpartial + * Although IO#read_nonblock doesn't raise IO::WaitWritable. + * OpenSSL::Buffering#read_nonblock can raise IO::WaitWritable. + * If IO and SSL should be used polymorphically, + * IO::WaitWritable should be rescued too. + * See the document of OpenSSL::Buffering#read_nonblock for sample code. + * + * Note that this method is identical to readpartial * except the non-blocking flag is set. */ @@ -2133,9 +2140,6 @@ io_read(int argc, VALUE *argv, VALUE io) if (len == 0) return str; READ_CHECK(fptr); - if (RSTRING_LEN(str) != len) { - rb_raise(rb_eRuntimeError, "buffer string modified"); - } n = io_fread(str, 0, fptr); if (n == 0) { if (fptr->fd < 0) return Qnil; @@ -3850,11 +3854,10 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io) n = fptr->fd; rb_thread_wait_fd(fptr->fd); rb_io_check_closed(fptr); - if (RSTRING_LEN(str) != ilen) { - rb_raise(rb_eRuntimeError, "buffer string modified"); - } + rb_str_locktmp(str); n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen); + rb_str_unlocktmp(str); if (n == -1) { rb_sys_fail_path(fptr->pathv); |