Class: KQueue::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-kqueue/watcher.rb,
lib/rb-kqueue/watcher/file.rb,
lib/rb-kqueue/watcher/timer.rb,
lib/rb-kqueue/watcher/signal.rb,
lib/rb-kqueue/watcher/process.rb,
lib/rb-kqueue/watcher/read_write.rb,
lib/rb-kqueue/watcher/socket_read_write.rb

Overview

Watchers monitor for a single sort of event, specified by the specific subclass and its parameters. A watcher is usually created via one of the watch_* methods on Queue.

One Queue may have many Watchers. The Queue actually takes care of the checking for events, via #run or #process.

Watcher objects themselves have several useful capabilities. Each subclass keeps track of its own specific information. In addition, all Watchers can be deleted from the queue, added back in, disabled, and enabled.

Direct Known Subclasses

File, Process, ReadWrite, Signal, Timer

Defined Under Namespace

Classes: File, Process, ReadWrite, Signal, SocketReadWrite, Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#queueQueue (readonly)

The Queue that created this Watcher.

Returns:



19
20
21
# File 'lib/rb-kqueue/watcher.rb', line 19

def queue
  @queue
end

Instance Method Details

#add!

This method returns an undefined value.

Adds this Watcher to its Queue. Note that this is done automatically when the Watcher is created.

Raises:

  • (SystemCallError)

    If something goes wrong when adding this Watcher.



48
49
50
51
# File 'lib/rb-kqueue/watcher.rb', line 48

def add!
  kevent! :add, :clear # TODO: Don't always enable :clear
  @queue.watchers[[@filter, @ident]] = self
end

#delete!

This method returns an undefined value.

Removes this Watcher from its Queue. This means that events won't be fired or even checked for.

Raises:

  • (SystemCallError)

    If something goes wrong when deleting this Watcher.



59
60
61
62
# File 'lib/rb-kqueue/watcher.rb', line 59

def delete!
  kevent! :delete
  @queue.watchers.delete([@filter, @ident])
end

#disable!

This method returns an undefined value.

Disables this Watcher. This means that events won't be fired, but they'll still be checked for.

Raises:

  • (SystemCallError)

    If something goes wrong when enabling this Watcher.



80
81
82
# File 'lib/rb-kqueue/watcher.rb', line 80

def disable!
  kevent! :disable
end

#enable!

This method returns an undefined value.

Enables this Watcher. Note that this is done automatically when the Watcher is created, as well as whenever #add! is called.

Raises:

  • (SystemCallError)

    If something goes wrong when enabling this Watcher.



70
71
72
# File 'lib/rb-kqueue/watcher.rb', line 70

def enable!
  kevent! :enable
end