Class: HotCell::Descriptor
- Inherits:
-
Object
- Object
- HotCell::Descriptor
- 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.
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
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #close ⇒ Object
- #fd_path ⇒ Object
-
#initialize(io, scratch: nil) ⇒ Descriptor
constructor
A new instance of Descriptor.
-
#staged? ⇒ Boolean
Whether this descriptor has been given a filename on the worker's own scratch.
- #to_io ⇒ Object
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
#io ⇒ Object (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
#close ⇒ Object
68 69 70 |
# File 'lib/hot_cell/descriptors.rb', line 68 def close io.close unless io.closed? end |
#fd_path ⇒ Object
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.
73 74 75 |
# File 'lib/hot_cell/descriptors.rb', line 73 def staged? !@path.nil? end |
#to_io ⇒ Object
30 31 32 |
# File 'lib/hot_cell/descriptors.rb', line 30 def to_io io end |