Skip to content

Commit d80b432

Browse files
committed
check port manually
1 parent abb6801 commit d80b432

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Cluster.pm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ use TestLib;
88
use Test::More;
99
use Cwd;
1010

11+
use Socket;
12+
13+
sub check_port
14+
{
15+
my ($host, $port) = @_;
16+
my $iaddr = inet_aton($host);
17+
my $paddr = sockaddr_in($port, $iaddr);
18+
my $proto = getprotobyname("tcp");
19+
my $available = 0;
20+
21+
socket(SOCK, PF_INET, SOCK_STREAM, $proto)
22+
or die "socket failed: $!";
23+
24+
if (bind(SOCK, $paddr) && listen(SOCK, SOMAXCONN))
25+
{
26+
$available = 1;
27+
}
28+
29+
close(SOCK);
30+
diag("checking for port $port = $available\n");
31+
return $available;
32+
}
33+
1134
my %allocated_ports = ();
1235
sub allocate_ports
1336
{
@@ -18,8 +41,7 @@ sub allocate_ports
1841
{
1942
my $port = int(rand() * 16384) + 49152;
2043
next if $allocated_ports{$port};
21-
diag("checking for port $port\n");
22-
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
44+
if (check_port($host, $port))
2345
{
2446
$allocated_ports{$port} = 1;
2547
push(@allocated_now, $port);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy