mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
* ext/socket/lib/socket.rb (Socket.tcp_server_sockets_port0): new
private function for allocating same port both IPv4 and IPv6. (Socket.tcp_server_sockets): use tcp_server_sockets_port0 for port 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
260d0d0399
commit
24eafe8376
3 changed files with 110 additions and 20 deletions
|
@ -111,6 +111,21 @@ class TestSocket < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_tcp_server_sockets_port0
|
||||
sockets = Socket.tcp_server_sockets(0)
|
||||
ports = sockets.map {|s| s.local_address.ip_port }
|
||||
the_port = ports.first
|
||||
ports.each {|port|
|
||||
assert_equal(the_port, port)
|
||||
}
|
||||
ensure
|
||||
if sockets
|
||||
sockets.each {|s|
|
||||
s.close
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if defined? UNIXSocket
|
||||
def test_unix
|
||||
Dir.mktmpdir {|tmpdir|
|
||||
|
@ -144,7 +159,7 @@ class TestSocket < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_accept_loop
|
||||
def test_accept_loop_with_unix
|
||||
Dir.mktmpdir {|tmpdir|
|
||||
tcp_servers = []
|
||||
clients = []
|
||||
|
@ -171,4 +186,25 @@ class TestSocket < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_accept_loop
|
||||
servers = []
|
||||
begin
|
||||
servers = Socket.tcp_server_sockets(0)
|
||||
port = servers[0].local_address.ip_port
|
||||
Socket.tcp("localhost", port) {|s1|
|
||||
Socket.accept_loop(servers) {|s2, client_ai|
|
||||
begin
|
||||
assert_equal(s1.local_address.ip_unpack, client_ai.ip_unpack)
|
||||
ensure
|
||||
s2.close
|
||||
end
|
||||
break
|
||||
}
|
||||
}
|
||||
ensure
|
||||
servers.each {|s| s.close if !s.closed? }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end if defined?(Socket)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue