about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-01 16:08:46 -0700
committerEric Wong <normalperson@yhbt.net>2010-06-01 16:08:46 -0700
commit5b34f7048cae6161c5180f57074272d558373133 (patch)
tree0b607cf9c02901003bc7ec0d23b18f4e0f2cb8fb
parentecb5f27598a6f53b6e02817bb0c1644fc4c75f09 (diff)
downloadruby_io_splice-5b34f7048cae6161c5180f57074272d558373133.tar.gz
-rwxr-xr-x[-rw-r--r--]examples/splice-cp.rb8
-rwxr-xr-xexamples/splice-tee.rb8
2 files changed, 5 insertions, 11 deletions
diff --git a/examples/splice-cp.rb b/examples/splice-cp.rb
index c630ff5..e629c59 100644..100755
--- a/examples/splice-cp.rb
+++ b/examples/splice-cp.rb
@@ -13,24 +13,22 @@ dest = ARGV.shift or abort usage
 
 source = File.open(source, 'rb')
 dest = File.open(dest, 'wb')
-source_fd, dest_fd = source.fileno, dest.fileno
 
 # We use a pipe as a ring buffer in kernel space.
 # pipes may store up to IO::Splice::PIPE_CAPA bytes
-pipe = IO.pipe
-rfd, wfd = pipe.map { |io| io.fileno }
+rio, wio = pipe = IO.pipe
 
 begin
   nread = begin
     # first pull as many bytes as possible into the pipe
-    IO.splice(source_fd, nil, wfd, nil, IO::Splice::PIPE_CAPA, 0)
+    IO.splice(source, nil, wio, nil, IO::Splice::PIPE_CAPA, 0)
   rescue EOFError
     break
   end
 
   # now move the contents of the pipe buffer into the destination file
   # the copied data never enters userspace
-  nwritten = IO.splice(rfd, nil, dest_fd, nil, nread, 0)
+  nwritten = IO.splice(rio, nil, dest, nil, nread, 0)
 
   nwritten == nread or
     abort "short splice to destination file: #{nwritten} != #{nread}"
diff --git a/examples/splice-tee.rb b/examples/splice-tee.rb
index d8479c4..0d40780 100755
--- a/examples/splice-tee.rb
+++ b/examples/splice-tee.rb
@@ -11,21 +11,17 @@ $stdin.stat.pipe? or abort "stdin must be a pipe"
 $stdout.stat.pipe? or abort "stdout must be a pipe"
 
 dest = File.open(dest, 'wb')
-out_fd = dest.fileno
-
-stdin_fd = $stdin.fileno
-stdout_fd = $stdout.fileno
 
 begin
   nread = begin
     # "copy" data from stdin to stdout, without consuming stdin
-    IO.tee(stdin_fd, stdout_fd, IO::Splice::PIPE_CAPA, 0)
+    IO.tee($stdin, $stdout, IO::Splice::PIPE_CAPA, 0)
   rescue EOFError
     break
   end
 
   # sends data to the file, consumes stdin
-  nwritten = IO.splice(stdin_fd, nil, out_fd, nil, nread, 0)
+  nwritten = IO.splice($stdin, nil, dest, nil, nread, 0)
 
   nwritten == nread or
     abort "short splice to file: #{nwritten} != #{nread}"