Class: DTAS::Watchable::InotifyReadableIter
- Inherits:
-
SleepyPenguin::Inotify
- Object
- SleepyPenguin::Inotify
- DTAS::Watchable::InotifyReadableIter
- Includes:
- InotifyCommon
- Defined in:
- lib/dtas/watchable/fiddle_ino.rb,
lib/dtas/watchable/inotify.rb
Overview
used to restart DTAS::Source::SplitFX processing in dtas-player if the YAML file is edited
Defined Under Namespace
Classes: InotifyEvent
Constant Summary collapse
- Inotify_init =
Fiddle::Function.new(DTAS.libc['inotify_init1'], [ Fiddle::TYPE_INT ], Fiddle::TYPE_INT)
- Inotify_add_watch =
Fiddle::Function.new(DTAS.libc['inotify_add_watch'], [ Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT ], Fiddle::TYPE_INT)
Instance Attribute Summary collapse
-
#to_io ⇒ Object
readonly
IO.select compatibility.
Class Method Summary collapse
Instance Method Summary collapse
- #add_watch(watchdir, flags) ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ InotifyReadableIter
constructor
:nodoc:.
-
#take(nonblock) ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ InotifyReadableIter
:nodoc:
22 23 24 25 26 27 28 |
# File 'lib/dtas/watchable/fiddle_ino.rb', line 22 def initialize # :nodoc: fd = Inotify_init.call(02000000 | 04000) # CLOEXEC | NONBLOCK raise "inotify_init failed: #{Fiddle.last_error}" if fd < 0 @to_io = IO.for_fd(fd) @buf = ''.b @q = [] end |
Instance Attribute Details
#to_io ⇒ Object (readonly)
IO.select compatibility
20 21 22 |
# File 'lib/dtas/watchable/fiddle_ino.rb', line 20 def to_io @to_io end |
Class Method Details
.new ⇒ Object
10 11 12 |
# File 'lib/dtas/watchable/inotify.rb', line 10 def self.new super(:CLOEXEC) end |
Instance Method Details
#add_watch(watchdir, flags) ⇒ Object
69 70 71 72 73 |
# File 'lib/dtas/watchable/fiddle_ino.rb', line 69 def add_watch(watchdir, flags) wd = Inotify_add_watch.call(@to_io.fileno, watchdir, flags) raise "inotify_add_watch failed: #{Fiddle.last_error}" if wd < 0 wd end |
#close ⇒ Object
75 76 77 |
# File 'lib/dtas/watchable/fiddle_ino.rb', line 75 def close @to_io = @to_io.close if @to_io end |
#take(nonblock) ⇒ Object
:nodoc:
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dtas/watchable/fiddle_ino.rb', line 39 def take(nonblock) # :nodoc: event = @q.pop and return event case rv = @to_io.read_nonblock(16384, @buf, exception: false) when :wait_readable, nil return else until rv.empty? hdr = rv.slice!(0,16) name = nil wd, mask, , len = res = hdr.unpack('iIII') wd && mask && && len or raise "bogus inotify_event #{res.inspect} hdr=#{hdr.inspect}" if len > 0 name = rv.slice!(0, len) name.size == len or raise "short name #{name.inspect} != #{len}" name.sub!(/\0+\z/, '') or raise "missing: `\\0', inotify_event.name=#{name.inspect}" name = -name end ie = InotifyEvent.new(wd, mask, , len, name) if event @q << ie else event = ie end end # /until rv.empty? return event end while true end |