librelist archives

« back to archive

[RFC] try* interfaces in io_splice 2.2.0.18.g3025

[RFC] try* interfaces in io_splice 2.2.0.18.g3025

From:
Eric Wong
Date:
2011-02-28 @ 01:19
$ gem install --pre io_splice

It's also up at git://bogomips.org/ruby_io_splice.git in master.

This adds IO.trytee and IO.trysplice which behave like their
non-trying counterparts with the following exceptions:

1) IO::Splice::F_NONBLOCK is implied/forced.
   IO.trysplice may still block if the non-pipe descriptor blocks, so
   users should always set non-blocking on that descriptor.

2) Unlike the established Kgio, this returns :EAGAIN instead
   of :wait_readable or :wait_writable.  This is because only
   the user of the code can tell which descriptor is actually
   full/empty.

There is no IO.tryvmsplice, I haven't figured out if IO.vmsplice is
useful or not and non-blocking I/O with iovecs is so painful to deal
with it's not worth it.

The flags argument of all these interfaces is now optional and will
default to zero (and IO::Splice::F_NONBLOCK for IO.try{splice,tee}).

-- 
Eric Wong

Re: [ruby.io.splice] [RFC] try* interfaces in io_splice 2.2.0.18.g3025

From:
Eric Wong
Date:
2011-02-28 @ 01:25
Eric Wong <normalperson@yhbt.net> wrote:
> There is no IO.tryvmsplice, I haven't figured out if IO.vmsplice is
> useful or not and non-blocking I/O with iovecs is so painful to deal
> with it's not worth it.

Just pushed this out, too:

diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index dc1e74d..a0ba381 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -394,7 +394,14 @@ static void advance_vmsplice_args(struct 
vmsplice_args *a, long n)
  * +fd+ must be the writable end of a pipe.
  *
  * This may allow the kernel to avoid data copies in some cases.
- * but is (probably) of limited usefulness in Ruby.
+ * but is (probably) of limited usefulness in Ruby.  If you have
+ * use cases or ideas for making this more useful for Ruby users,
+ * please tell us at ruby.io.splice@librelist.com!
+ *
+ * Also consider the "sendfile" RubyGem or IO.copy_stream in Ruby 1.9
+ * if you want to do zero-copy file transfers to pipes or sockets.  As
+ * of Linux 2.6.33, sendfile(2) can copy to any output descriptor,
+ * not just sockets.
  *
  * See manpage for full documentation:
  * http://kernel.org/doc/man-pages/online/pages/man2/vmsplice.2.html
-- 
Eric Wong