about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-28 00:21:28 +0000
committerEric Wong <normalperson@yhbt.net>2011-02-28 00:21:28 +0000
commit38273a2a81db814eacd2257665eac2fe3ecd3b94 (patch)
treea7dfc4f44e4c7ca703ecc6115bf5e8112670251e
parent813c5300294046f9ae0f4bac8449a4734ddd7fd9 (diff)
downloadruby_io_splice-38273a2a81db814eacd2257665eac2fe3ecd3b94.tar.gz
For consistency with all of our other methods.
-rw-r--r--ext/io_splice/io_splice_ext.c9
-rw-r--r--test/test_io_splice.rb8
2 files changed, 14 insertions, 3 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index c97435e..14f7042 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -361,11 +361,14 @@ static void advance_vmsplice_args(struct vmsplice_args *a, long n)
  * See manpage for full documentation:
  * http://kernel.org/doc/man-pages/online/pages/man2/vmsplice.2.html
  */
-static VALUE my_vmsplice(VALUE self, VALUE fd, VALUE data, VALUE flags)
+static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
 {
         long rv = 0;
         ssize_t left;
         struct vmsplice_args a;
+        VALUE fd, data, flags;
+
+        rb_scan_args(argc, argv, "21", &fd, &data, &flags);
 
         switch (TYPE(data)) {
         case T_STRING: {
@@ -386,7 +389,7 @@ static VALUE my_vmsplice(VALUE self, VALUE fd, VALUE data, VALUE flags)
                          rb_obj_classname(data));
         }
         a.fd = my_fileno(fd);
-        a.flags = NUM2UINT(flags);
+        a.flags = NIL_P(flags) ? 0 : NUM2UINT(flags);
 
         for (;;) {
                 long n = (long)nb_io_run(nogvl_vmsplice, &a, a.flags);
@@ -494,7 +497,7 @@ void Init_io_splice_ext(void)
         rb_define_singleton_method(rb_cIO, "trysplice", trysplice, -1);
         rb_define_singleton_method(rb_cIO, "tee", my_tee, -1);
         rb_define_singleton_method(rb_cIO, "trytee", trytee, -1);
-        rb_define_singleton_method(rb_cIO, "vmsplice", my_vmsplice, 3);
+        rb_define_singleton_method(rb_cIO, "vmsplice", my_vmsplice, -1);
 
         /*
          * Attempt to move pages instead of copying.  This is only a hint
diff --git a/test/test_io_splice.rb b/test/test_io_splice.rb
index 1d73f70..eb4faeb 100644
--- a/test/test_io_splice.rb
+++ b/test/test_io_splice.rb
@@ -255,6 +255,14 @@ class Test_IO_Splice < Test::Unit::TestCase
     assert_equal data.join(''), r.readpartial(16384)
   end
 
+  def test_vmsplice_noflags
+    data = %w(hello world how are you today)
+    r, w = IO.pipe
+    n = IO.vmsplice(w, data)
+    assert_equal data.join('').size, n
+    assert_equal data.join(''), r.readpartial(16384)
+  end
+
   def test_vmsplice_string
     r, w = IO.pipe
     assert_equal 5, IO.vmsplice(w, 'hello', 0)