def start
@running = true
@time = {:start => Time.now}
Thread.new do
begin
while @running; input_thread_step; end
rescue SystemCallError, IOError, ProtocolError => e
rt_debug "#{self} (input): #{e.message}, releasing #{@want_blocks.length} claimed blocks and dying"
@running = false
@controller.forget_blocks @want_blocks
end
end
Thread.new do
begin
while @running; output_thread_step; end
rescue SystemCallError, IOError, ProtocolError => e
rt_debug "#{self} (output): #{e.message}, releasing #{@want_blocks.length} claimed blocks and dying"
@running = false
@controller.forget_blocks @want_blocks
end
end
queue_message(:bitfield, {:bitfield => @package.pieces.map { |p| p.complete? }.extend(ArrayToBitstring).to_bitstring})
self
end