Module: FFI::IO

Defined in:
lib/ffi/io.rb

Overview

This module implements a couple of class methods to play with IO.

Class Method Summary collapse

Class Method Details

.for_fd(fd, mode = "r") ⇒ ::IO

Synonym for IO::for_fd.

Parameters:

  • fd (Integer)

    file decriptor

  • mode (String) (defaults to: "r")

    mode string

Returns:

  • (::IO)


39
40
41
# File 'lib/ffi/io.rb', line 39

def self.for_fd(fd, mode = "r")
  ::IO.for_fd(fd, mode)
end

.native_read(io, buf, len) ⇒ Numeric

A version of IO#read that reads data from an IO and put then into a native buffer.

This will be optimized at some future time to eliminate the double copy.

Parameters:

  • io (#read)

    io to read from

  • buf (AbstractMemory)

    destination for data read from io

  • len (nil, Numeric)

    maximul number of bytes to read from io. If nil, read until end of file.

Returns:

  • (Numeric)

    length really read, in bytes



53
54
55
56
57
58
# File 'lib/ffi/io.rb', line 53

def self.native_read(io, buf, len)
  tmp = io.read(len)
  return -1 unless tmp
  buf.put_bytes(0, tmp)
  tmp.length
end