Maybe this will help.

class TCPSocket
  def off?
    begin
      eof
    rescue
      Kernel.puts "#{__FILE__}:#{__LINE__} #{$!.inspect}"
      true
    end
  end
end

def loop
  until connection.off?
    ...
  end
end
-- 
Posted via http://www.ruby-forum.com/.