about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-01-19 08:10:23 +0000
committerEric Wong <normalperson@yhbt.net>2013-01-19 08:10:23 +0000
commitaa94260ff6e8fe1d7d954bbcbadf5b06c6006777 (patch)
tree8756333a78ccb0ec18d5bbbc593ff265c864c5ed
parent1707419f13b206fdd9d4654b03cc34d977fdedc6 (diff)
downloadruby_io_splice-aa94260ff6e8fe1d7d954bbcbadf5b06c6006777.tar.gz
While vmsplice is hardly useful, its FD-closed-while-GVL-less
handling should be as good as our splice and tee wrappers.
-rw-r--r--ext/io_splice/io_splice_ext.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index 876d07d..e429266 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -493,6 +493,7 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
         ssize_t left;
         struct vmsplice_args a;
         struct iovec iov;
+        ssize_t n;
 
         VALUE io, data, flags;
 
@@ -513,21 +514,19 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
                          "(expected a String or Array of strings)",
                          rb_obj_classname(data));
         }
-        a.fd = my_fileno(io);
+
         a.flags = NIL_P(flags) ? 0 : NUM2UINT(flags);
 
         for (;;) {
-                ssize_t n = (ssize_t)io_run(nogvl_vmsplice, &a);
+                a.fd = check_fileno(io);
+                n = (ssize_t)io_run(nogvl_vmsplice, &a);
 
                 if (n == -1) {
                         if (errno == EAGAIN) {
-                                if (a.flags & SPLICE_F_NONBLOCK) {
+                                if (a.flags & SPLICE_F_NONBLOCK)
                                         rb_sys_fail("vmsplice");
-                                } else {
-                                        a.fd = check_fileno(io);
-                                        if (rb_io_wait_writable(a.fd))
-                                                continue;
-                                }
+                                if (rb_io_wait_writable(check_fileno(io)))
+                                        continue;
                                 /* fall through on error */
                         }
                         /*
@@ -537,10 +536,8 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
                          */
                         if (rv > 0)
                                 break;
-                        if (errno == EINTR) {
-                                a.fd = check_fileno(io);
+                        if (errno == EINTR)
                                 continue;
-                        }
                         rb_sys_fail("vmsplice");
                 }