Module: IOT
- Included in:
- CRuby::IoChannel, CRuby::TcpServerChannel, CRuby::TimerChannel
- Defined in:
- lib/cruby/channel.rb
Overview
入出力とタイマー処理
Constant Summary collapse
- @@inTbl =
入力IOをキーとするテーブル
Hash.new {[]}
- @@outTbl =
出力IOをキーとするテーブル
Hash.new {[]}
- @@timerQ =
[]
Class Method Summary collapse
Class Method Details
.exec ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cruby/channel.rb', line 72 def IOT.exec tm = nil # IOキューを調べる rds = @@inTbl.keys wds = @@outTbl.keys nxt = @@timerQ.first # どちらも空の場合 if rds.empty? && wds.empty? && nxt == nil then return nil end if nxt then tm = nxt[:time] - Time.now if tm < 0 then tm = 0 end end CRuby::Coroutine.interruptible true # 割り込み可能にセット ds = select(rds,wds,nil,tm) CRuby::Coroutine.interruptible false # もとに戻す if (ds == nil) @@timerQ.shift nxt[:chan].timeout else # 入力処理 ds[0].each {|io| input(io) } # 出力処理 ds[1].each {|io| output(io) } end CRuby::Coroutine.dispatch end |
.input(io) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cruby/channel.rb', line 52 def IOT.input io # IOキューから入力チャネルを一つ取り出す ich = @@inTbl[io].shift # キューが空になればエントリを削除 if @@inTbl[io].empty? then @@inTbl.delete(io) end ich.input end |
.output(io) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/cruby/channel.rb', line 62 def IOT.output io # IOキューから出力チャネルを一つ取り出す och = @@outTbl[io].shift # キューが空になればエントリを削除 if @@outTbl[io].empty? then @@outTbl.delete(io) end och.output end |