Class: Pwrake::NBIO::Selector
- Inherits:
-
Object
- Object
- Pwrake::NBIO::Selector
- Defined in:
- lib/pwrake/nbio.rb
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #add_reader(hdl) ⇒ Object
- #add_writer(hdl) ⇒ Object
- #clear ⇒ Object
- #delete_reader(hdl) ⇒ Object
- #delete_writer(hdl) ⇒ Object
- #empty? ⇒ Boolean
-
#get_host(io) ⇒ Object
used to print an error message.
- #halt ⇒ Object
-
#initialize(io_class = IO) ⇒ Selector
constructor
A new instance of Selector.
- #run(timeout = nil) ⇒ Object
Constructor Details
#initialize(io_class = IO) ⇒ Selector
Returns a new instance of Selector.
13 14 15 16 17 18 |
# File 'lib/pwrake/nbio.rb', line 13 def initialize(io_class=IO) @reader = {} @writer = {} @running = false @io_class = io_class end |
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
20 21 22 |
# File 'lib/pwrake/nbio.rb', line 20 def reader @reader end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
20 21 22 |
# File 'lib/pwrake/nbio.rb', line 20 def writer @writer end |
Instance Method Details
#add_reader(hdl) ⇒ Object
22 23 24 |
# File 'lib/pwrake/nbio.rb', line 22 def add_reader(hdl) @reader[hdl.io] = hdl end |
#add_writer(hdl) ⇒ Object
30 31 32 |
# File 'lib/pwrake/nbio.rb', line 30 def add_writer(hdl) @writer[hdl.io] = hdl end |
#clear ⇒ Object
42 43 44 45 |
# File 'lib/pwrake/nbio.rb', line 42 def clear @reader.clear @writer.clear end |
#delete_reader(hdl) ⇒ Object
26 27 28 |
# File 'lib/pwrake/nbio.rb', line 26 def delete_reader(hdl) @reader.delete(hdl.io) end |
#delete_writer(hdl) ⇒ Object
34 35 36 |
# File 'lib/pwrake/nbio.rb', line 34 def delete_writer(hdl) @writer.delete(hdl.io) end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/pwrake/nbio.rb', line 38 def empty? @reader.empty? && @writer.empty? end |
#get_host(io) ⇒ Object
used to print an error message
54 55 56 57 |
# File 'lib/pwrake/nbio.rb', line 54 def get_host(io) hdl = @reader[io] || @writer[io] hdl.respond_to?(:host) ? hdl.host : nil end |
#halt ⇒ Object
47 48 49 50 51 |
# File 'lib/pwrake/nbio.rb', line 47 def halt @running = false @writer.each_value{|w| w.halt} @reader.each_value{|r| r.halt} end |
#run(timeout = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pwrake/nbio.rb', line 59 def run(timeout=nil) @running = true init_heartbeat if timeout while @running && !empty? if $debug && defined? Log rd_insp = @reader.map{|k,v| "%s=>%s,%s" % [k.inspect,v.class.inspect,v.waiter.inspect] }.join(",") Log.debug "Selector#run:\n "+caller[0..1].join("\n ")+ "\n @reader={#{rd_insp}}\n @writer.size=#{@writer.size}" $stderr.puts "Selector#run: "+caller[0] end run_select(timeout) end ensure @running = false @hb_time = nil end |