Project

General

Profile

Backport #670 ยป test_select_hangs_windows.rb

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

 
1
# 
2
#
3
# 
4
# If run in linux with ulimit -n 2000 crashes it
5
# 
6
# 
7

    
8
require 'socket'
9

    
10
class TCPSocket
11
 attr_accessor :wrote
12
end
13

    
14
no_files = 0
15

    
16
server_ports = []
17
clients = []
18

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

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

    
40
number_returned = 0
41
while number_returned < clients.length
42
 r,w,e = select(server_ports, nil, nil, nil)
43
 for readable in r
44
   read = readable.recv 1024
45
   readable.write read
46
   number_returned += 1
47
 end
48
end
49

    
50

    
51
print 'herey'
52
for client in clients
53
 received = client.recv(1024)
54
 raise 'got back weird data' unless received == client.wrote
55
end
56
print 'success'
57