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
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
-
#add_interest(interest) ⇒ self
Add new interests to the existing interest set.
-
#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?.
-
#remove_interest(interest) ⇒ self
Remove interests from the existing interest set.
-
#writable? ⇒ Boolean
(also: #writeable?)
Is the IO object writable?.
Constructor Details
#initialize(io, interests, selector) ⇒ Object
Methods
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nio/monitor.rb', line 17 def initialize(io, interests, selector) unless defined?(::OpenSSL) && io.is_a?(::OpenSSL::SSL::SSLSocket) 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 end @io = io @interests = interests @selector = selector @closed = false end |
Instance Attribute Details
#interests ⇒ Object
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.
31 32 33 |
# File 'ext/nio4r/monitor.c', line 31 def readiness @readiness end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
26 27 28 |
# File 'ext/nio4r/monitor.c', line 26 def selector @selector end |
#value ⇒ Object
Returns the value of attribute value.
29 30 31 |
# File 'ext/nio4r/monitor.c', line 29 def value @value end |
Instance Method Details
#add_interest(interest) ⇒ self
Add new interests to the existing interest set
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nio/monitor.rb', line 53 def add_interest(interest) case interest when :r case @interests when :r then @interests = :r when :w then @interests = :rw when :rw then @interests = :rw when nil then @interests = :r end when :w case @interests when :r then @interests = :rw when :w then @interests = :w when :rw then @interests = :rw when nil then @interests = :w end when :rw @interests = :rw else raise ArgumentError, "bad interests: #{interest}" end end |
#close(deregister = true) ⇒ Object
Deactivate this monitor
119 120 121 122 |
# File 'lib/nio/monitor.rb', line 119 def close(deregister = true) @closed = true @selector.deregister(io) if deregister end |
#closed? ⇒ Boolean
Is this monitor closed?
114 115 116 |
# File 'lib/nio/monitor.rb', line 114 def closed? @closed end |
#readable? ⇒ Boolean
Is the IO object readable?
103 104 105 |
# File 'lib/nio/monitor.rb', line 103 def readable? readiness == :r || readiness == :rw end |
#remove_interest(interest) ⇒ self
Remove interests from the existing interest set
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nio/monitor.rb', line 80 def remove_interest(interest) case interest when :r case @interests when :r then @interests = nil when :w then @interests = :w when :rw then @interests = :w when nil then @interests = nil end when :w case @interests when :r then @interests = :r when :w then @interests = nil when :rw then @interests = :r when nil then @interests = nil end when :rw @interests = nil else raise ArgumentError, "bad interests: #{interest}" end end |
#writable? ⇒ Boolean Also known as: writeable?
Is the IO object writable?
108 109 110 |
# File 'lib/nio/monitor.rb', line 108 def writable? readiness == :w || readiness == :rw end |