1 # -*- encoding: binary -*-
2 require 'io_splice_ext'
8 # the version of IO::Splice, currently 0.1.0
11 # The maximum capacity of the pipe in bytes.
12 # Under stock Linux, this is 65536 bytes as of 2.6.11, and 4096 before
13 # We detect this at runtime as it is easy to recompile the kernel
14 # and set a new value.
20 n += wr.write_nonblock(buf)
29 # copies the contents of the IO object given by +src+ to +dst+
30 # If len is specified, then only len bytes are copied. Otherwise
31 # the copy will be until EOF is reached on the +src+.
32 # +src+ and +dst+ must be IO objects or respond to +to_io+
33 def self.copy_stream(src, dst, len = nil)
34 src, dst = src.to_io, dst.to_io
36 if src.stat.pipe? || dst.stat.pipe?
39 nr = len > PIPE_CAPA ? PIPE_CAPA : len
40 nr = IO.splice(src, nil, dst, nil, nr, 0)
42 raise EOFError, "unexpected EOF with #{len} bytes left"
49 nr = IO.splice(src, nil, dst, nil, PIPE_CAPA, 0)
60 nr = len > PIPE_CAPA ? PIPE_CAPA : len
61 nr_src = copy_stream(src, w, nr)
63 raise RuntimeError, "short splice from: #{nr_src} != #{nr}"
64 nr_dst = copy_stream(r, dst, nr)
66 raise RuntimeError, "short splice to: #{nr_dst} != #{nr}"
72 nr = IO.splice(src, nil, w, nil, PIPE_CAPA, 0)
75 nr -= IO.splice(r, nil, dst, nil, nr, 0)