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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nio/monitor.rb', line 10 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nio/monitor.rb', line 46 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
112 113 114 115 |
# File 'lib/nio/monitor.rb', line 112 def close(deregister = true) @closed = true @selector.deregister(io) if deregister end |
#closed? ⇒ Boolean
Is this monitor closed?
107 108 109 |
# File 'lib/nio/monitor.rb', line 107 def closed? @closed end |
#readable? ⇒ Boolean
Is the IO object readable?
96 97 98 |
# File 'lib/nio/monitor.rb', line 96 def readable? readiness == :r || readiness == :rw end |
#remove_interest(interest) ⇒ self
Remove interests from the existing interest set
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nio/monitor.rb', line 73 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?
101 102 103 |
# File 'lib/nio/monitor.rb', line 101 def writable? readiness == :w || readiness == :rw end |