Project

General

Profile

Backport #670 ยป socket.diff

rogerdpack (Roger Pack), 02/08/2010 11:13 PM

View differences:

test/socket/test_socket.rb (working copy)
4 4
rescue LoadError
5 5
end
6 6

  
7
require 'timeout'
8

  
7 9
class TestBasicSocket < Test::Unit::TestCase
8 10
  def inet_stream
9 11
    sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
......
71 73
      }
72 74
    end
73 75
  end
76

  
77
  def test_use_all_available
78

  
79
    no_files = 0
80

  
81
    server_ports = []
82
    clients = []
83

  
84
    deplete_fds = []
85
    begin
86
      Timeout::timeout(20) do
87
        begin
88
          while true
89
            another_server = TCPServer.new 'localhost', nil
90
            port = another_server.addr[1]
91
            client = TCPSocket.new('localhost', port)
92
            server_ports << another_server.accept
93
            clients << client
94
            client.write clients.length
95
          end
96
        rescue Exception => e
97
          # expected
98
        end
99

  
100
        number_returned = 0
101
        while number_returned < clients.length
102
          r,w,e = select(server_ports, nil, nil, nil)
103
          for readable in r
104
            read = readable.recv 1024
105
            readable.write read
106
            number_returned += 1
107
          end
108
        end
109

  
110
        clients.each_with_index{|client, idx|
111
          received = client.recv(1024)
112
          assert_equal(received, (idx + 1).to_s)
113
        }
114
      end
115
    end
116
  end
74 117
end if defined?(Socket)
75 118

  
76 119
class TestSocket < Test::Unit::TestCase
win32/win32.h (working copy)
23 23
#ifdef __BORLANDC__
24 24
#define USE_WINSOCK2
25 25
#endif
26
#ifndef FD_SETSIZE
27
# define FD_SETSIZE 256 // larger default
28
#endif
26 29
#ifdef USE_WINSOCK2
27 30
#include <winsock2.h>
28 31
#include <ws2tcpip.h>