Parent

Class Index [+]

Quicksearch

Ramaze::Reloader::WatchInotify

TODO:

  * There seems to be a problem somewhere that I couldn't identify yet, a
    file has to be modified twice initially to make it show up as
    modified here, subsequent changes work just fine.
    The only workaround I could find right now would be to read/write
    every single file, but that would be unexpected, irresponsible, and
    error-prone.

NOTE:

  * I have changed from using a Mutex to using a Queue, which uses a
    Mutex internally.

Constants

POLL_INTERVAL
NOTIFY_MASK

Public Class Methods

new() click to toggle source
    # File lib/ramaze/reloader/watch_inotify.rb, line 19
19:       def initialize
20:         @watcher = RInotify.new
21:         @changed = Queue.new
22:         @watcher_thread = start_watcher
23:       end

Public Instance Methods

call(cooldown) click to toggle source
    # File lib/ramaze/reloader/watch_inotify.rb, line 25
25:       def call(cooldown)
26:         yield
27:       end
changed_files() click to toggle source

NOTE:

  We have to add the changed file again after we got a notification, I
  have no idea why, but using IN_ONESHOT should make sure that there is
  no memory leak in the C level even if we add a file again.
  There is a memory leak however in the watch_descriptors hash, since
  rinotify won't synchronize the contents properly and will only add to
  the hash, so we have to clean up ourselves.
    # File lib/ramaze/reloader/watch_inotify.rb, line 74
74:       def changed_files
75:         until @changed.empty?
76:           descriptor = @changed.shift
77:           file = @watcher.watch_descriptors.delete(descriptor)
78:           watch(file)
79:           yield(file)
80:         end
81:       end
close() click to toggle source
    # File lib/ramaze/reloader/watch_inotify.rb, line 61
61:       def close
62:         @watcher_thread.terminate
63:         @watcher.close
64:         true
65:       end
remove_watch(file) click to toggle source

FIXME:

  Seems like this won't work due to some bug in the rinotify library.
  Would be cool if someone could make a FFI version.
    # File lib/ramaze/reloader/watch_inotify.rb, line 57
57:       def remove_watch(file)
58:         @watcher.rm_watch(file)
59:       end
start_watcher() click to toggle source

TODO: define a finalizer to cleanup? — reloader never calls #

    # File lib/ramaze/reloader/watch_inotify.rb, line 31
31:       def start_watcher
32:         Thread.new{ loop{ watcher_cycle }}
33:       end
watch(file) click to toggle source
    # File lib/ramaze/reloader/watch_inotify.rb, line 45
45:       def watch(file)
46:         return if @watcher.watch_descriptors.has_value?(file)
47:         return unless File.exist?(file)
48: 
49:         @watcher.add_watch(file, NOTIFY_MASK)
50:       rescue Errno::ENOENT
51:         retry
52:       end
watcher_cycle() click to toggle source

Not much work here, we just have to empty the event queue and push the descriptors for reloading on next request.

    # File lib/ramaze/reloader/watch_inotify.rb, line 37
37:       def watcher_cycle
38:         return unless @watcher.wait_for_events(POLL_INTERVAL)
39: 
40:         @watcher.each_event do |event|
41:           @changed.push(event.watch_descriptor)
42:         end
43:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.