[前][次][番号順一覧][スレッド一覧]

ruby-changes:2937

From: ko1@a...
Date: 21 Dec 2007 18:44:12 +0900
Subject: [ruby-changes:2937] ko1 - Ruby:r14428 (trunk): * io.c: write() should be in blocking region.

ko1	2007-12-21 18:43:49 +0900 (Fri, 21 Dec 2007)

  New Revision: 14428

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_io.rb
    trunk/bootstraptest/test_knownbug.rb
    trunk/io.c

  Log:
    * io.c: write() should be in blocking region.
    * bootstraptest/test_io.rb, test_knownbug.rb: move a fixed test.
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_io.rb?r1=14428&r2=14427
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14428&r2=14427
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=14428&r2=14427
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14428&r2=14427

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14427)
+++ ChangeLog	(revision 14428)
@@ -1,3 +1,9 @@
+Fri Dec 21 18:40:54 2007  Koichi Sasada  <ko1@a...>
+
+	* io.c: write() should be in blocking region.
+
+	* bootstraptest/test_io.rb, test_knownbug.rb: move a fixed test.
+
 Fri Dec 21 17:56:30 2007    <nagai@o...>
 
 	* ext/tk/tcltklib.c: provisional support on Ruby-VM.
Index: bootstraptest/test_knownbug.rb
===================================================================
--- bootstraptest/test_knownbug.rb	(revision 14427)
+++ bootstraptest/test_knownbug.rb	(revision 14428)
@@ -3,18 +3,3 @@
 # So all tests will cause failure.
 #
 
-assert_finish 2, %q{
-  require "io/nonblock"
-  r, w = IO.pipe
-  w.nonblock = true
-  w.write_nonblock("a" * 100000)
-  w.nonblock = false
-  t1 = Thread.new { w.write("b" * 4096) }
-  t2 = Thread.new { w.write("c" * 4096) }
-  sleep 0.5
-  r.sysread(4096).length
-  sleep 0.5
-  r.sysread(4096).length
-  t1.join
-  t2.join
-}, '[ruby-dev:32566]'
Index: bootstraptest/test_io.rb
===================================================================
--- bootstraptest/test_io.rb	(revision 14427)
+++ bootstraptest/test_io.rb	(revision 14428)
@@ -7,3 +7,19 @@
   sleep 0.1
   w.write "a"
 }, '[ruby-dev:31866]'
+
+assert_finish 10, %q{
+  require "io/nonblock"
+  r, w = IO.pipe
+  w.nonblock = true
+  w.write_nonblock("a" * 100000)
+  w.nonblock = false
+  t1 = Thread.new { w.write("b" * 4096) }
+  t2 = Thread.new { w.write("c" * 4096) }
+  sleep 0.5
+  r.sysread(4096).length
+  sleep 0.5
+  r.sysread(4096).length
+  t1.join
+  t2.join
+}, '[ruby-dev:32566]'
Index: io.c
===================================================================
--- io.c	(revision 14427)
+++ io.c	(revision 14428)
@@ -455,7 +455,50 @@
     return fptr->mode & FMODE_WSPLIT;
 }
 
+struct io_internal_struct {
+    int fd;
+    void *buf;
+    size_t capa;
+    int is_read;
+};
+
+static VALUE
+internal_io_func(void *ptr)
+{
+    struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
+    if (iis->is_read) {
+	return read(iis->fd, iis->buf, iis->capa);
+    }
+    else {
+	return write(iis->fd, iis->buf, iis->capa);
+    }
+}
+
 static int
+rb_read_internal(int fd, void *buf, size_t count)
+{
+    struct io_internal_struct iis;
+    iis.fd = fd;
+    iis.buf = buf;
+    iis.capa = count;
+    iis.is_read = 1;
+
+    return rb_thread_blocking_region(internal_io_func, &iis, RB_UBF_DFL, 0);
+}
+
+static int
+rb_write_internal(int fd, void *buf, size_t count)
+{
+    struct io_internal_struct iis;
+    iis.fd = fd;
+    iis.buf = buf;
+    iis.capa = count;
+    iis.is_read = 0;
+
+    return rb_thread_blocking_region(internal_io_func, &iis, RB_UBF_DFL, 0);
+}
+
+static int
 io_fflush(rb_io_t *fptr)
 {
     int r, l;
@@ -479,9 +522,8 @@
         wsplit_p(fptr)) {
         l = PIPE_BUF;
     }
-    TRAP_BEG;
-    r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
-    TRAP_END; /* xxx: signal handler may modify wbuf */
+    r = rb_write_internal(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
+    /* xxx: signal handler may modify wbuf */
     if (r == fptr->wbuf_len) {
         fptr->wbuf_off = 0;
         fptr->wbuf_len = 0;
@@ -627,9 +669,8 @@
             wsplit_p(fptr)) {
             l = PIPE_BUF;
         }
-        TRAP_BEG;
-	r = write(fptr->fd, RSTRING_PTR(str)+offset, l);
-        TRAP_END; /* xxx: signal handler may modify given string. */
+	r = rb_write_internal(fptr->fd, RSTRING_PTR(str)+offset, l);
+	/* xxx: signal handler may modify given string. */
         if (r == n) return len;
         if (0 <= r) {
             offset += r;
@@ -905,31 +946,7 @@
     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;
-    rs.fd = fd;
-    rs.buf = buf;
-    rs.capa = count;
-    return rb_thread_blocking_region(read_func, &rs, RB_UBF_DFL, 0);
-}
-
-static int
 io_fillbuf(rb_io_t *fptr)
 {
     int r;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]