Class: Baykit::BayServer::Util::NioSelector
- Defined in:
- lib/baykit/bayserver/util/nio_selector.rb
Constant Summary
Constants inherited from Selector
Selector::OP_READ, Selector::OP_WRITE
Instance Attribute Summary collapse
-
#io_monitor_map ⇒ Object
readonly
Returns the value of attribute io_monitor_map.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Attributes inherited from Selector
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize ⇒ NioSelector
constructor
A new instance of NioSelector.
- #select(timeout_sec = nil) ⇒ Object
Methods inherited from Selector
#get_op, #modify, #register, #unregister, #validate_channel
Constructor Details
#initialize ⇒ NioSelector
Returns a new instance of NioSelector.
13 14 15 16 17 18 |
# File 'lib/baykit/bayserver/util/nio_selector.rb', line 13 def initialize super @selector = NIO::Selector.new @io_monitor_map = {} # io -> monitor(:r) end |
Instance Attribute Details
#io_monitor_map ⇒ Object (readonly)
Returns the value of attribute io_monitor_map.
11 12 13 |
# File 'lib/baykit/bayserver/util/nio_selector.rb', line 11 def io_monitor_map @io_monitor_map end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
10 11 12 |
# File 'lib/baykit/bayserver/util/nio_selector.rb', line 10 def selector @selector end |
Instance Method Details
#count ⇒ Object
38 39 40 |
# File 'lib/baykit/bayserver/util/nio_selector.rb', line 38 def count @lock.synchronize { @ops.length } end |
#select(timeout_sec = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/baykit/bayserver/util/nio_selector.rb', line 19 def select(timeout_sec=nil) timeout_sec = 0 if timeout_sec.nil? ready_mon_list = @selector.select(timeout_sec) result = {} if ready_mon_list ready_mon_list.each do |mon| io = mon.io if mon.readable? register_read(io, result) end if mon.writable? register_write(io, result) end end end result end |