Sha256: fb1ab6a619938fae19ed312b385926bbdc9b00897ef966d85ec8feb2f148731a

Contents?: true

Size: 808 Bytes

Versions: 8

Compression:

Stored size: 808 Bytes

Contents

# :enddoc:
require "io/nonblock"
module IO::Splice
  class << self
    remove_method :full
    remove_method :partial
  end
  def self.full(src, dst, len, src_offset)
    dst.to_io.nonblock = src.to_io.nonblock = true
    spliced = 0
    case n = IO.trysplice(src, src_offset, dst, nil, len, IO::Splice::F_MOVE)
    when :EAGAIN
      src.to_io.wait
      IO.select(nil, [dst])
    when Integer
      spliced += n
      len -= n
      src_offset += n if src_offset
    when nil
      break
    end while len > 0
    spliced
  end

  def self.partial(src, dst, len, src_offset)
    dst.to_io.nonblock = src.to_io.nonblock = true
    begin
      src.to_io.wait
      IO.select(nil, [dst])
      rv = IO.trysplice(src, src_offset, dst, nil, len, IO::Splice::F_MOVE)
    end while rv == :EAGAIN
    rv
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
io_splice-4.4.2 lib/io/splice/mri_18.rb
io_splice-4.4.1 lib/io/splice/mri_18.rb
io_splice-4.4.0 lib/io/splice/mri_18.rb
io_splice-4.3.0 lib/io/splice/mri_18.rb
io_splice-4.2.0 lib/io/splice/mri_18.rb
io_splice-4.1.1 lib/io/splice/mri_18.rb
io_splice-4.1.0 lib/io/splice/mri_18.rb
io_splice-4.0.0 lib/io/splice/mri_18.rb