1 # intentionally not changing package to jam the routine herein straight
2 # into the use-ing package. Yes, this is totally a hack.
4 # Code is almost verbatim (bar _check_port -> $_check_port because I'm
5 # polluting people's namespaces already) from Test::TCP 1.07 by
6 # Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt> which is perl licensed.
11 my $_check_port = sub {
14 my $remote = IO::Socket::INET->new(
16 PeerAddr => '127.0.0.1',
32 $p = 19000 unless $p =~ /^[0-9]+$/ && $p < 19000;
35 10000 + int(rand()*1000);
39 while ( $port++ < 20000 ) {
40 next if $_check_port->($port);
41 my $sock = IO::Socket::INET->new(
43 LocalAddr => '127.0.0.1',
46 (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
48 return $port if $sock;
50 die "empty port not found";