Class: NIO::Monitor
- Inherits:
-
Object
- Object
- NIO::Monitor
- 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
-
#interests ⇒ Object
readonly
Returns the value of attribute interests.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#readiness ⇒ Object
Returns the value of attribute readiness.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#close(deregister = true) ⇒ Object
Deactivate this monitor.
-
#closed? ⇒ Boolean
Is this monitor closed?.
-
#initialize(io, interests, selector) ⇒ Object
constructor
Methods.
-
#readable? ⇒ Boolean
Is the IO object readable?.
-
#writable? ⇒ Boolean
(also: #writeable?)
Is the IO object writable?.
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
#interests ⇒ Object (readonly)
Returns the value of attribute interests.
22 23 24 |
# File 'ext/nio4r/monitor.c', line 22 def interests @interests end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
21 22 23 |
# File 'ext/nio4r/monitor.c', line 21 def io @io end |
#readiness ⇒ Object
Returns the value of attribute readiness.
28 29 30 |
# File 'ext/nio4r/monitor.c', line 28 def readiness @readiness end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
23 24 25 |
# File 'ext/nio4r/monitor.c', line 23 def selector @selector end |
#value ⇒ Object
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?
35 |
# File 'lib/nio/monitor.rb', line 35 def closed?; @closed; end |
#readable? ⇒ Boolean
Is the IO object readable?
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?
29 30 31 |
# File 'lib/nio/monitor.rb', line 29 def writable? readiness == :w || readiness == :rw end |