summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-23 08:35:29 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-23 08:35:29 +0000
commitd54d8c3bafd2a08885a55fd92b02bfcb42b7422d (patch)
tree38e161a8ca4b62b9429ecea47005c0a851279f36 /io.c
parent2e35e1e0f3840528d9890674489b7ab25d1372a3 (diff)
downloadruby-d54d8c3bafd2a08885a55fd92b02bfcb42b7422d.tar.gz
ruby-d54d8c3bafd2a08885a55fd92b02bfcb42b7422d.tar.xz
ruby-d54d8c3bafd2a08885a55fd92b02bfcb42b7422d.zip
* io.c: add rb_read_internal() as blocking function.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/io.c b/io.c
index 677c3cab1..1bc806470 100644
--- a/io.c
+++ b/io.c
@@ -902,6 +902,27 @@ rb_io_rewind(VALUE io)
return INT2FIX(0);
}
+struct read_struct {
+ int fd;
+ void *buf;
+ size_t capa;
+};
+
+static VALUE
+read_func(void *ptr)
+{
+ struct read_struct *rs = (struct read_struct*)ptr;
+ return read(rs->fd, rs->buf, rs->capa);
+}
+
+
+static int
+rb_read_internal(int fd, void *buf, size_t count)
+{
+ struct read_struct rs = {fd, buf, count};
+ return rb_thread_blocking_region(read_func, &rs, RB_UBF_DFL, 0);
+}
+
static int
io_fillbuf(rb_io_t *fptr)
{
@@ -915,9 +936,9 @@ io_fillbuf(rb_io_t *fptr)
}
if (fptr->rbuf_len == 0) {
retry:
- TRAP_BEG;
- r = read(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
- TRAP_END; /* xxx: signal handler may modify rbuf */
+ {
+ r = rb_read_internal(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
+ }
if (r < 0) {
if (rb_io_wait_readable(fptr->fd))
goto retry;
@@ -1329,13 +1350,11 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
if (RSTRING_LEN(str) != len) goto modified;
if (nonblock) {
rb_io_set_nonblock(fptr);
- n = read(fptr->fd, RSTRING_PTR(str), len);
+ n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
}
else {
- TRAP_BEG;
- n = read(fptr->fd, RSTRING_PTR(str), len);
- TRAP_END;
- }
+ n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
+ }
if (n < 0) {
if (!nonblock && rb_io_wait_readable(fptr->fd))
goto again;
@@ -2791,9 +2810,8 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
if (RSTRING_LEN(str) != ilen) {
rb_raise(rb_eRuntimeError, "buffer string modified");
}
- TRAP_BEG;
- n = read(fptr->fd, RSTRING_PTR(str), ilen);
- TRAP_END;
+
+ n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen);
if (n == -1) {
rb_sys_fail(fptr->path);