Class: CRuby::IoChannel
- Includes:
- IOT
- Defined in:
- lib/cruby/channel.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(io) ⇒ IoChannel
constructor
A new instance of IoChannel.
-
#input ⇒ Object
入力処理を行う.
-
#output ⇒ Object
出力処理を行う.
-
#recvEvt ⇒ Object
受信イベントを生成する.
-
#sendEvt(msg) ⇒ Object
送信イベントを生成する.
Methods included from IOT
Methods inherited from Channel
Constructor Details
#initialize(io) ⇒ IoChannel
Returns a new instance of IoChannel.
111 112 113 114 |
# File 'lib/cruby/channel.rb', line 111 def initialize io super() @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
109 110 111 |
# File 'lib/cruby/channel.rb', line 109 def io @io end |
Instance Method Details
#input ⇒ Object
入力処理を行う
143 144 145 146 147 148 149 150 |
# File 'lib/cruby/channel.rb', line 143 def input # EOFの処理 msg = @io.readpartial(4096) # チャネルの受信待ちキューのプロセスを取り出す item = @recvQ.dequeue item['flg'][0] = true item['cont'].call(msg) end |
#output ⇒ Object
出力処理を行う
153 154 155 156 157 158 159 |
# File 'lib/cruby/channel.rb', line 153 def output # チャネルの送信待ちキューのプロセスを取り出す item = @sendQ.dequeue item['flg'][0] = true CRuby::Coroutine.enqueue(item['cont']) io.write(item['msg']) end |
#recvEvt ⇒ Object
受信イベントを生成する
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cruby/channel.rb', line 130 def recvEvt pollFn = Proc.new { false } blockFn = Proc.new {|flg,k| if flg[0] == true then CRuby::Coroutine.dispatch end @@inTbl[@io] <<= self @recvQ.enqueue({'flg'=>flg,'cont'=>k}) } CRuby::Event.new([CRuby::Event::BEvt.new(pollFn, nil, blockFn)]) end |
#sendEvt(msg) ⇒ Object
送信イベントを生成する
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cruby/channel.rb', line 117 def sendEvt msg pollFn = Proc.new { false } blockFn = Proc.new {|flg,k| if flg[0] == true then CRuby::Coroutine.dispatch end @@outTbl[@io] <<= self @sendQ.enqueue({'flg'=>flg,'msg'=>msg,'cont'=>k}) } CRuby::Event.new([CRuby::Event::BEvt.new(pollFn, nil, blockFn)]) end |