module KQueue::Native::Flags

A module containing all the C-level integer flags that are used with kqueue.

@private

Constants

EVFILT_AIO
EVFILT_FS
EVFILT_MACHPORT
EVFILT_PROC
EVFILT_READ

Filters

EVFILT_SESSION
EVFILT_SIGNAL
EVFILT_TIMER
EVFILT_USER
EVFILT_VNODE
EVFILT_WRITE
EV_ADD

Actions

EV_CLEAR
EV_DELETE
EV_DISABLE
EV_DISPATCH
EV_ENABLE
EV_EOF

Returned values

EV_ERROR
EV_ONESHOT

Flags

EV_RECEIPT
NOTE_PROC_CHILD
NOTE_PROC_EXEC
NOTE_PROC_EXIT

For `EVFILT_PROC`

NOTE_PROC_FORK
NOTE_PROC_REAP
NOTE_PROC_SIGNAL
NOTE_PROC_TRACK
NOTE_PROC_TRACKERR
NOTE_READ_LOWAT

For `EVFILT_{READ,WRITE}`

NOTE_TIMER_ABSOLUTE
NOTE_TIMER_NSECONDS
NOTE_TIMER_SECONDS

For `EVFILT_TIMER`

NOTE_TIMER_USECONDS
NOTE_VNODE_ATTRIB
NOTE_VNODE_DELETE

For `EVFILT_VNODE`

NOTE_VNODE_EXTEND
NOTE_VNODE_RENAME
NOTE_VNODE_REVOKE
NOTE_VNODE_WRITE

Public Class Methods

from_flag(prefix, flag) click to toggle source

Converts an integer from the C API into a flag.

@param prefix [String] The prefix for the C names of the flags @param flag [Fixnum] @return [Symbol]

# File lib/rb-kqueue/native/flags.rb, line 106
def self.from_flag(prefix, flag)
  re = /^#{Regexp.quote prefix}_/
  constants.each do |sym|
    c = sym.to_s
    next unless c =~ re
    return c.to_s.sub("#{prefix}_", "").downcase.to_sym if const_get(c) == flag
  end
end
from_mask(prefix, mask) click to toggle source

Converts a bitmask from the C API into a list of flags.

@param prefix [String] The prefix for the C names of the flags @param mask [Fixnum] @return [Array<Symbol>]

# File lib/rb-kqueue/native/flags.rb, line 83
def self.from_mask(prefix, mask)
  re = /^#{Regexp.quote prefix}_/
  constants.select do |sym|
    c = sym.to_s
    next false unless c =~ re
    const_get(c) & mask != 0
  end.map {|c| c.to_s.sub("#{prefix}_", "").downcase.to_sym}
end
to_flag(prefix, flag) click to toggle source

Converts a flag to the integer that the C API expects.

@param prefix [String] The prefix for the C names of the flags @param flag [Symbol] @return [Fixnum]

# File lib/rb-kqueue/native/flags.rb, line 97
def self.to_flag(prefix, flag)
  const_get("#{prefix}_#{flag.to_s.upcase}")
end
to_mask(prefix, flags) click to toggle source

Converts a list of flags to the bitmask that the C API expects.

@param prefix [String] The prefix for the C names of the flags @param flags [Array<Symbol>] @return [Fixnum]

# File lib/rb-kqueue/native/flags.rb, line 73
def self.to_mask(prefix, flags)
  flags.map {|flag| const_get("#{prefix}_#{flag.to_s.upcase}")}.
    inject(0) {|mask, flag| mask | flag}
end