Class: NIO::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/nio/monitor.rb,
ext/nio4r/monitor.c,
ext/nio4r/selector.c

Overview

Monitors watch IO objects for specific events

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, interests, selector) ⇒ Object

Methods



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nio/monitor.rb', line 8

def initialize(io, interests, selector)
  unless io.is_a?(IO)
    if IO.respond_to? :try_convert
      io = IO.try_convert(io)
    elsif io.respond_to? :to_io
      io = io.to_io
    end

    fail TypeError, "can't convert #{io.class} into IO" unless io.is_a? IO
  end

  @io        = io
  @interests = interests
  @selector  = selector
  @closed    = false
end

Instance Attribute Details

#interestsObject

Returns the value of attribute interests.



23
24
25
# File 'ext/nio4r/monitor.c', line 23

def interests
  @interests
end

#ioObject (readonly)

Returns the value of attribute io.



22
23
24
# File 'ext/nio4r/monitor.c', line 22

def io
  @io
end

#readinessObject

Returns the value of attribute readiness.



29
30
31
# File 'ext/nio4r/monitor.c', line 29

def readiness
  @readiness
end

#selectorObject (readonly)

Returns the value of attribute selector.



24
25
26
# File 'ext/nio4r/monitor.c', line 24

def selector
  @selector
end

#valueObject

Returns the value of attribute value.



27
28
29
# File 'ext/nio4r/monitor.c', line 27

def value
  @value
end

Instance Method Details

#close(deregister = true) ⇒ Object

Deactivate this monitor



50
51
52
53
# File 'lib/nio/monitor.rb', line 50

def close(deregister = true)
  @closed = true
  @selector.deregister(io) if deregister
end

#closed?Boolean

Is this monitor closed?

Returns:

  • (Boolean)


45
46
47
# File 'lib/nio/monitor.rb', line 45

def closed?
  @closed
end

#readable?Boolean

Is the IO object readable?

Returns:

  • (Boolean)


34
35
36
# File 'lib/nio/monitor.rb', line 34

def readable?
  readiness == :r || readiness == :rw
end

#writable?Boolean Also known as: writeable?

Is the IO object writable?

Returns:

  • (Boolean)


39
40
41
# File 'lib/nio/monitor.rb', line 39

def writable?
  readiness == :w || readiness == :rw
end