class KQueue::Event

An event produced by kqueue. Each {Watcher} can fire many events, which are passed to that Watcher’s callback.

Attributes

data[R]

Some integer data, the interpretation of which is specific to each individual {Watcher}. For specifics, see the individual Watcher subclasses.

‘data` is not meaningful for all events. For example, file-change notifications do not set `data`.

@return [Fixnum]

filter[R]

The name of the kqueue filter that created this event, e.g. ‘:vnode` or `:read`.

@private @return [Symbol]

Public Class Methods

new(native, queue) click to toggle source

Creates a new event from a native event structure.

@private @param native [Native::Event] The native event structure

from which to construct this event

@param queue [Queue] The queue that produced this event @raise [SystemCallError] If this event signals an error

# File lib/rb-kqueue/event.rb, line 68
def initialize(native, queue)
  @native = native
  @queue = queue
  @data = @native[:data]
  begin
    @filter = KQueue::Native::Flags.from_flag("EVFILT", @native[:filter])
  rescue Native::Flags::FlagNotFound
    raise UnexpectedEvent
  end
  @flags = Native::Flags.from_mask("EV", @native[:flags])

  KQueue.handle_error @native[:data] if @flags.include?(:error)
end

Public Instance Methods

callback!() click to toggle source

Runs the callback for this event. This callback is associated with the {Watcher} that produced the event.

@private @return [void]

# File lib/rb-kqueue/event.rb, line 88
def callback!
  watcher.callback! self
end
eof?() click to toggle source

Returns whether the end-of-file flag has been set for this event. The interpretation of this is specific to each individual {Watcher}.

‘eof?` is not meaningful for all events. For example, file-change notifications don’t set ‘eof?`.

@return [Boolean]

# File lib/rb-kqueue/event.rb, line 57
def eof?
  @flags.include?(:eof)
end
flags() click to toggle source

An array of flags, the interpretation of which is specific to each individual {Watcher}.

If the Watcher watches for different sorts of events, this is usually the specific events that actually occurred. For example, for file-change notifications this could be ‘[:delete]`.

‘flags` is not meaningful for all events. For example, readability notifications do not set `flags`.

@return [Array<Symbol>]

# File lib/rb-kqueue/event.rb, line 46
def flags
  @fflags ||= Native::Flags.from_mask("NOTE_#{filter.to_s.upcase}", @native[:fflags])
end
watcher() click to toggle source

The {Watcher} that produced this event.

@return [Watcher]

# File lib/rb-kqueue/event.rb, line 31
def watcher
  @watcher ||= @queue.watchers[[filter, @native[:ident]]]
end