Index: test/socket/test_socket.rb =================================================================== --- test/socket/test_socket.rb (revision 26621) +++ test/socket/test_socket.rb (working copy) @@ -4,6 +4,8 @@ rescue LoadError end +require 'timeout' + class TestBasicSocket < Test::Unit::TestCase def inet_stream sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) @@ -71,6 +73,47 @@ } end end + + def test_use_all_available + + no_files = 0 + + server_ports = [] + clients = [] + + deplete_fds = [] + begin + Timeout::timeout(20) do + begin + while true + another_server = TCPServer.new 'localhost', nil + port = another_server.addr[1] + client = TCPSocket.new('localhost', port) + server_ports << another_server.accept + clients << client + client.write clients.length + end + rescue Exception => e + # expected + 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 + + clients.each_with_index{|client, idx| + received = client.recv(1024) + assert_equal(received, (idx + 1).to_s) + } + end + end + end end if defined?(Socket) class TestSocket < Test::Unit::TestCase Index: win32/win32.h =================================================================== --- win32/win32.h (revision 26621) +++ win32/win32.h (working copy) @@ -23,6 +23,9 @@ #ifdef __BORLANDC__ #define USE_WINSOCK2 #endif +#ifndef FD_SETSIZE +# define FD_SETSIZE 256 // larger default +#endif #ifdef USE_WINSOCK2 #include #include