Project

General

Profile

Backport #670 » test_select_hangs_windows.rb

rogerdpack (Roger Pack), 10/21/2008 08:01 AM

 
#
#
#
# If run in linux with ulimit -n 2000 crashes it
#
#

require 'socket'

class TCPSocket
attr_accessor :wrote
end

no_files = 0

server_ports = []
clients = []

deplete_fds = []
#2000.times { deplete_fds << File.new('abc', 'r')}
#print 'got', deplete_fds.length
begin
while true
another_server = TCPServer.new 'localhost', nil
port = another_server.addr[1]
clients << TCPSocket.new('localhost', port)
server_ports << another_server.accept
end
rescue Exception => e
print 'got', clients.length, e
end
print 'continuing'

for client in clients
what_to_write = rand(100000).to_s
client.write what_to_write
client.wrote = what_to_write
end

number_returned = 0
while number_returned < clients.length
r,w,e = select(server_ports, nil, nil, nil)
for readable in r
read = readable.recv 1024
readable.write read
number_returned += 1
end
end


print 'herey'
for client in clients
received = client.recv(1024)
raise 'got back weird data' unless received == client.wrote
end
print 'success'

(4-4/5)