Class: HotCell::Descriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/hot_cell/descriptors.rb

Overview

A descriptor, not a path. The cold side opens the file and passes the open descriptor, so no path a hot side chooses is ever opened by the cold side, and no path the cold side chose is ever visible to a tool.

These verify rather than merely tag, and both sides verify. An access mode is fixed at open and cannot be narrowed afterward, so a cell handed a read-write descriptor as an input cannot correct it — it can only decline the request.

Direct Known Subclasses

Input, Output

Constant Summary collapse

MODES =
{
  Fcntl::O_RDONLY => "read-only",
  Fcntl::O_WRONLY => "write-only",
  Fcntl::O_RDWR   => "read-write",
}.freeze
F_GETPATH =

sys/fcntl.h; Ruby's Fcntl module does not carry it

50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, scratch: nil) ⇒ Descriptor

Returns a new instance of Descriptor.



22
23
24
25
26
27
28
# File 'lib/hot_cell/descriptors.rb', line 22

def initialize(io, scratch: nil)
  @io = io
  @scratch = scratch
  verify_regular_file!
  verify_access_mode!
  verify_position!
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



20
21
22
# File 'lib/hot_cell/descriptors.rb', line 20

def io
  @io
end

Instance Method Details

#closeObject



68
69
70
# File 'lib/hot_cell/descriptors.rb', line 68

def close
  io.close unless io.closed?
end

#fd_pathObject



57
58
59
60
61
# File 'lib/hot_cell/descriptors.rb', line 57

def fd_path
  buffer = "\0" * 1024 # F_GETPATH writes the path into a buffer the caller supplies, MAXPATHLEN wide
  io.fcntl F_GETPATH, buffer
  buffer[/\A[^\0]+/]
end

#staged?Boolean

Whether this descriptor has been given a filename on the worker's own scratch.

Returns:

  • (Boolean)


73
74
75
# File 'lib/hot_cell/descriptors.rb', line 73

def staged?
  !@path.nil?
end

#to_ioObject



30
31
32
# File 'lib/hot_cell/descriptors.rb', line 30

def to_io
  io
end