Project

General

Profile

Backport #670 ยป test_select_hangs_on_linux.rb

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

 
1
# to run this one
2
# touch abc
3
# then
4
# ulimit -n 2000
5

    
6
require 'socket'
7

    
8
class TCPSocket
9
 attr_accessor :wrote
10
end
11

    
12
no_files = 0
13

    
14
server_ports = []
15
clients = []
16

    
17
deplete_fds = []
18
begin
19
#loop { deplete_fds << File.new('abc', 'r')}
20
rescue Exception
21
end
22
print 'got', deplete_fds.length
23
begin
24
while true
25
  another_server = TCPServer.new 'localhost', nil
26
  port = another_server.addr[1]
27
  clients << TCPSocket.new('localhost', port)
28
  server_ports << another_server.accept
29
end
30
rescue Exception => e
31
 print 'got', clients.length, e
32
end
33
print 'continuing'
34

    
35
for client in clients
36
 what_to_write = rand(100000).to_s
37
 client.write what_to_write
38
 client.wrote = what_to_write
39
end
40

    
41
count = 0
42
for server_port in server_ports
43
  print 'accepting, receiving', count
44
count += 1
45
  received = server_port.recv 1024
46
  server_port.write received
47
end
48
print 'herey'
49
for client in clients
50
 received = client.recv(1024)
51
 raise 'got back weird data' unless received == client.wrote
52
end
53
print 'success for ', clients.length
54