From c32ddca888259c391e126154ff62fdcdb2e3759c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Feb 2011 16:47:40 -0800 Subject: [PATCH] trysplice implies SPLICE_F_NONBLOCK for flags It makes more sense this way if non-blocking I/O is expected. --- ext/io_splice/io_splice_ext.c | 8 ++++---- test/test_io_splice.rb | 7 +++++++ 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') -- 2.11.4.GIT