lib/io/splice.rb in io_splice-4.1.0 vs lib/io/splice.rb in io_splice-4.1.1

- old
+ new

@@ -82,29 +82,35 @@ # Either +dst+ or +src+ must be a pipe. +dst+ and +src+ # may BOTH be pipes in Linux 2.6.31 or later. # This will block and wait for IO completion of +len+ # Raises +EOFError+ if end of file is reached. # bytes. Returns the number of bytes actually spliced (always +len+) + # unless +src+ does not have +len+ bytes to read. + # + # Do not use this method to splice a socket +src+ into a pipe +dst+ + # unless there is another process or native thread doing a blocking + # read on the other end of the +dst+ pipe. + # + # This method is safe for splicing a pipe +src+ into any type of +dst+ IO. def self.full(src, dst, len, src_offset) IO.splice(src, src_offset, dst, nil, len, F_MOVE | WAITALL) end # splice up to +len+ bytes from +src+ to +dst+. # Either +dst+ or +src+ must be a pipe. +dst+ and +src+ # may BOTH be pipes in Linux 2.6.31 or later. # Returns the number of bytes actually spliced. # Like IO#readpartial, this never returns Errno::EAGAIN def self.partial(src, dst, len, src_offset) - IO.splice(src, src_offset, dst, nil, len, F_MOVE) - rescue EOFError - nil - rescue Errno::EAGAIN - begin - src.to_io.wait - IO.select(nil, [dst]) - rv = IO.trysplice(src, src_offset, dst, nil, len, F_MOVE) - end while rv == :EAGAIN - rv + case rv = IO.trysplice(src, src_offset, dst, nil, len, F_MOVE) + when :EAGAIN + src.to_io.wait + IO.select(nil, [dst]) + when Integer + return rv + else + return nil + end while true end end if (! defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") && RUBY_VERSION.to_f <= 1.8 require "io/splice/mri_18"