Brian Candler wrote:
> Oh, and there is also IO.pipe, which is unidirectional under most Unix 
> flavours.

I've tried pipes, but it seems to always think there's data to be read. 
Here's the code I was testing it with:



pipeAA, pipeAB = IO.pipe()
pipeBA, pipeBB = IO.pipe()

Thread.new() do
  loop do
    sleep(1)
    pipeAB.puts("1 sec")
  end
end

Thread.new() do
  loop do
    sleep(5)
    pipeBB.puts("5 sec")
  end
end

loop do
  # Should wait for one (or both) to have data, right?
  ready = select([pipeAA,pipeBA])
  next if(ready == nil)

  # But it ALWAYS thinks there's data to be read...
  for i in ready[0]
    if(i == pipeAA)
      puts("AA:")
      puts(pipeAA.gets()) # ...meaning this locks the program up!
    elsif(i == pipeBA)
      puts("BA:")
      puts(pipeBA.gets())
    end
  end
end



The output of that is a single line, "AA:", which is just before it 
attempts to get the data from pipeAA. It doesn't continue, because it's 
waiting for data from pipeAA, but it shouldn't have gotten to that step 
if there wasn't data ready in the first place.
-- 
Posted via http://www.ruby-forum.com/.