Class: FFI::Libfuse::FuseBuf

Inherits:
Object
  • Object
show all
Includes:
StructWrapper
Defined in:
lib/ffi/libfuse/fuse_buf.rb

Overview

Single io buffer

Generic io buffer for I/O, extended attributes, etc...Data may be supplied as a memory pointer or as a file descriptor

Instance Attribute Summary collapse

Attributes included from StructWrapper

#native

Instance Method Summary collapse

Methods included from StructWrapper

#[], #[]=, #method_missing

Methods included from StructWrapper::ClassMethods

#by_ref, #by_value

Methods included from Accessors::ClassMethods

#attr_accessor, #attr_reader, #attr_writer, #ffi_attr_accessor, #ffi_attr_reader, #ffi_attr_reader_method, #ffi_attr_readers, #ffi_attr_writer, #ffi_attr_writer_method, #ffi_attr_writers, #ffi_bitflag_accessor, #ffi_bitflag_reader, #ffi_bitflag_writer, #ffi_public_attr_readers, #ffi_public_attr_writers

Methods included from Accessors

#ffi_attr_fill, #ffi_attr_reader_member, #ffi_attr_writer_member, #inspect, #to_h

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FFI::StructWrapper

Instance Attribute Details

#fdInteger (readonly) Also known as: file_descriptor

Returns the file descriptor number.

Returns:

  • (Integer)

    the file descriptor number



44
# File 'lib/ffi/libfuse/fuse_buf.rb', line 44

alias file_descriptor fd

#memFFI::Pointer (readonly) Also known as: memory

Returns the memory in the buffer.

Returns:

  • (FFI::Pointer)

    the memory in the buffer



39
# File 'lib/ffi/libfuse/fuse_buf.rb', line 39

alias memory mem

#sizeInteger

Returns the size of the buffer.

Returns:

  • (Integer)

    the size of the buffer



# File 'lib/ffi/libfuse/fuse_buf.rb', line 46

Instance Method Details

#fd?Boolean Also known as: file_descriptor?

Returns true if this is a file descriptor buffer.

Returns:

  • (Boolean)

    true if this is a file descriptor buffer



55
56
57
# File 'lib/ffi/libfuse/fuse_buf.rb', line 55

def fd?
  self[:flags].include?(:is_fd)
end

#fill(str: ) ⇒ self #fill(size: ) ⇒ self #fill(mem: , size: mem.size) ⇒ self #fill(fd: , fd_retry: false, size: , pos: 0) ⇒ self

Overloads:

  • #fill(str: ) ⇒ self

    Create a memory buffer from str

    Parameters:

    • str (String, #to_s) (defaults to: )
  • #fill(size: ) ⇒ self

    Allocate an empty memory buffer of size bytes

    Parameters:

    • size (Integer) (defaults to: )
  • #fill(mem: , size: mem.size) ⇒ self

    Set the buffer to contain the previously allocated memory

    Parameters:

    • mem (FFI::Pointer) (defaults to: )
    • size (Integer) (defaults to: mem.size)

      <= mem.size

  • #fill(fd: , fd_retry: false, size: , pos: 0) ⇒ self

    Fill as a FileDescriptor buffer

    Parameters:

    • fd (Integer) (defaults to: )

      File descriptor

    • fd_retry (Boolean) (defaults to: false)

      Retry operations on file descriptor

      If this flag is set then retry operation on file descriptor until size bytes have been copied or an error or EOF is detected.

    • size (Integer) (defaults to: )

      number of bytes to read from fd

    • pos (nil, Integer) (defaults to: 0)

      If set then used to seek to the given offset before performing operation on file descriptor.

Returns:

  • (self)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ffi/libfuse/fuse_buf.rb', line 87

def fill(
  str: nil,
  mem: str ? FFI::MemoryPointer.from_string(str.to_s) : FFI::Pointer::NULL, size: mem.null? ? 0 : mem.size,
  fd: -1, fd_retry: false, pos: nil # rubocop:disable Naming/MethodParameterName

)

  # Allocate size bytes if we've been given a null pointer
  mem = FFI::MemoryPointer.new(:char, size, true) if fd == -1 && mem.null? && size.positive?

  mem.autorelease = to_ptr.autorelease? unless mem.null?

  self[:size] = size
  self[:mem] = mem
  self[:fd] = fd
  flags = []
  flags << :is_fd if fd != -1
  flags << :fd_seek if pos
  flags << :fd_retry if fd_retry
  self[:flags] = flags
  self[:pos] = pos || 0
  self
end

#mem?Boolean

Returns true if this a memory buffer.

Returns:

  • (Boolean)

    true if this a memory buffer



50
51
52
# File 'lib/ffi/libfuse/fuse_buf.rb', line 50

def mem?
  !fd?
end