CWB-CQI
view release on metacpan or search on metacpan
lib/CWB/CQI/Server.pm view on Meta::CPAN
croak "CQPserver is not installed on this machine"
unless cqi_server_available();
# generate temporary user list file for CQPserver
my $passfile = "/tmp/CQI::Server.$$";
my $fh = new FileHandle "> $passfile";
croak "Can't create temporary user list file. Aborting."
unless defined $fh;
print $fh "user $user \"$passwd\";\n";
$fh->close;
chmod 0600, $passfile; # so no one can spy on us
# scan for free port (using rand() so two servers invoked at the same time won't collide)
my $port = 10000 + int rand(2000);
my %in_use =
map {$_ => 1}
map {(/\*\.([0-9]+)/) ? $1 : 0}
`netstat -a -n | grep LISTEN`;
while ($port < 60000 and $in_use{$port}) {
$port += rand(20); # jump randomly to avoid collisions
}
( run in 0.238 second using v1.01-cache-2.11-cpan-8d75d55dd25 )