about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-26 16:47:40 -0800
committerEric Wong <normalperson@yhbt.net>2011-02-26 16:54:42 -0800
commitc32ddca888259c391e126154ff62fdcdb2e3759c (patch)
tree5a118e99ccba6212bc64add79e0e2075a50e5514
parent4ba0bb32bb717d1f77c2f4f3cb41e646eb243a7f (diff)
downloadruby_io_splice-c32ddca888259c391e126154ff62fdcdb2e3759c.tar.gz
It makes more sense this way if non-blocking I/O is expected.
-rw-r--r--ext/io_splice/io_splice_ext.c8
-rw-r--r--test/test_io_splice.rb7
2 files changed, 11 insertions, 4 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index ff39b25..79d96ee 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -127,7 +127,7 @@ static VALUE nogvl_splice(void *ptr)
                              a->len, a->flags);
 }
 
-static long do_splice(int argc, VALUE *argv)
+static long do_splice(int argc, VALUE *argv, unsigned dflags)
 {
         off_t i, o;
         VALUE fd_in, off_in, fd_out, off_out, len, flags;
@@ -141,7 +141,7 @@ static long do_splice(int argc, VALUE *argv)
         a.fd_in = my_fileno(fd_in);
         a.fd_out = my_fileno(fd_out);
         a.len = (size_t)NUM2ULONG(len);
-        a.flags = NIL_P(flags) ? 0 : NUM2UINT(flags);
+        a.flags = NIL_P(flags) ? dflags : NUM2UINT(flags) | dflags;
 
         return (long)io_run(nogvl_splice, &a);
 }
@@ -184,7 +184,7 @@ static long do_splice(int argc, VALUE *argv)
  */
 static VALUE my_splice(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_splice(argc, argv);
+        long n = do_splice(argc, argv, 0);
 
         if (n == 0)
                 rb_eof_error();
@@ -195,7 +195,7 @@ static VALUE my_splice(int argc, VALUE *argv, VALUE self)
 
 static VALUE trysplice(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_splice(argc, argv);
+        long n = do_splice(argc, argv, SPLICE_F_NONBLOCK);
 
         if (n == 0)
                 return Qnil;
diff --git a/test/test_io_splice.rb b/test/test_io_splice.rb
index 6b287ae..f5bce6a 100644
--- a/test/test_io_splice.rb
+++ b/test/test_io_splice.rb
@@ -138,6 +138,13 @@ class Test_IO_Splice < Test::Unit::TestCase
            IO.trysplice(rd, nil, tmp, 0, 5, IO::Splice::F_NONBLOCK)
   end
 
+  def test_trysplice_nonblock_noargs
+    rd, wr = IO.pipe
+    tmp = Tempfile.new('ruby_io_splice')
+    assert_equal :EAGAIN, IO.trysplice(rd, nil, tmp, 0, 5)
+    assert_equal :EAGAIN, IO.trysplice(rd, nil, tmp, 0, 5, IO::Splice::F_MORE)
+  end
+
   def test_splice_eof
     rd, wr = IO.pipe
     tmp = Tempfile.new('ruby_io_splice')