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
# 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

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

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

Instance Attribute Details

#interestsObject (readonly)

Returns the value of attribute interests.



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

def interests
  @interests
end

#ioObject (readonly)

Returns the value of attribute io.



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

def io
  @io
end

#readinessObject

Returns the value of attribute readiness.



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

def readiness
  @readiness
end

#selectorObject (readonly)

Returns the value of attribute selector.



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

def selector
  @selector
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#close(deregister = true) ⇒ Object

Deactivate this monitor



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

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

#closed?Boolean

Is this monitor closed?

Returns:

  • (Boolean)


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

def closed?; @closed; end

#readable?Boolean

Is the IO object readable?

Returns:

  • (Boolean)


24
25
26
# File 'lib/nio/monitor.rb', line 24

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

#writable?Boolean Also known as: writeable?

Is the IO object writable?

Returns:

  • (Boolean)


29
30
31
# File 'lib/nio/monitor.rb', line 29

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