diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-02-02 16:54:07 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-02-02 16:54:07 -0800 |
commit | e597e594ad88dc02d70f7d3521d0d3bdc23739bb (patch) | |
tree | 5bdd94b8adb9f3954d7542c820795a306de3a118 /t/bin | |
parent | 314680327b95c0dc5e11be45a6343ca2a18ee447 (diff) | |
download | unicorn-e597e594ad88dc02d70f7d3521d0d3bdc23739bb.tar.gz |
Duh...
Diffstat (limited to 't/bin')
-rwxr-xr-x | t/bin/unused_listen | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/t/bin/unused_listen b/t/bin/unused_listen index b638f54..cd536f1 100755 --- a/t/bin/unused_listen +++ b/t/bin/unused_listen @@ -7,24 +7,11 @@ require 'tmpdir' default_port = 8080 addr = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1' -retries = 100 -base = 5000 port = sock = lock_path = nil begin - begin - port = base + rand(32768 - base) - while port == default_port - port = base + rand(32768 - base) - end - - sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) - sock.bind(Socket.pack_sockaddr_in(port, addr)) - sock.listen(5) - rescue Errno::EADDRINUSE, Errno::EACCES - sock.close rescue nil - retry if (retries -= 1) >= 0 - end + sock = TCPServer.new(addr, 0) + port = sock.addr[1] # since we'll end up closing the random port we just got, there's a race # condition could allow the random port we just chose to reselect itself |