Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b222feb

Browse files
committed
Merge branch 'PGPROEE9_6_MULTIMASTER' of https://gitlab.postgrespro.ru/pgpro-dev/postgrespro into PGPROEE9_6_MULTIMASTER
2 parents b51abb4 + f51ffbf commit b222feb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

contrib/mmts/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)