ruby-changes:2516
From: ko1@a...
Date: 23 Nov 2007 17:35:51 +0900
Subject: [ruby-changes:2516] ko1 - Ruby:r14007 (trunk): * io.c: add rb_read_internal() as blocking function.
ko1 2007-11-23 17:35:29 +0900 (Fri, 23 Nov 2007)
New Revision: 14007
Modified files:
trunk/ChangeLog
trunk/io.c
Log:
* io.c: add rb_read_internal() as blocking function.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14007&r2=14006
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=14007&r2=14006
Index: ChangeLog
===================================================================
--- ChangeLog (revision 14006)
+++ ChangeLog (revision 14007)
@@ -1,3 +1,7 @@
+Fri Nov 23 17:34:24 2007 Koichi Sasada <ko1@a...>
+
+ * io.c: add rb_read_internal() as blocking function.
+
Fri Nov 23 17:33:39 2007 Koichi Sasada <ko1@a...>
* vm.c: fix comment.
Index: io.c
===================================================================
--- io.c (revision 14006)
+++ io.c (revision 14007)
@@ -902,7 +902,28 @@
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)
{
int r;
@@ -915,9 +936,9 @@
}
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 @@
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,10 +2810,9 @@
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);
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml