Skip to content

Commit 08eb917

Browse files
committed
Use ephemeral port in ftp tests
And enable them to run in parallel.
1 parent a876577 commit 08eb917

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

ext/ftp/tests/CONFLICTS

Lines changed: 0 additions & 1 deletion
This file was deleted.

ext/ftp/tests/server.inc

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@ $socket = null;
44
$errno = 0;
55
$context = stream_context_create(array('ssl' => array('local_cert' => dirname(__FILE__).'/cert.pem')));
66

7-
for ($i=0; $i<10 && !$socket; ++$i) {
8-
$port = rand(50000, 65535);
9-
10-
$socket = @stream_socket_server("tcp://127.0.0.1:$port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
11-
}
12-
//set anther random port that is not the same as $port
13-
do{
14-
$pasv_port = rand(50000, 65535);
15-
}while($pasv_port == $port);
16-
7+
$socket = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
178
if (!$socket) {
189
echo "$errstr ($errno)\n";
1910
die("could not start/bind the ftp server\n");
2011
}
2112

13+
$socket_name = stream_socket_get_name($socket, false);
14+
$port = (int) substr($socket_name, strrpos($socket_name, ':') + 1);
15+
2216
$pid = pcntl_fork();
2317

2418
if ($pid) {
@@ -402,25 +396,20 @@ if ($pid) {
402396
$i=0;
403397

404398
if (empty($bug73457)) {
405-
do {
406-
if (!empty($ssl)) {
407-
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
408-
} else {
409-
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port");
410-
}
411-
/* Could bind port, Try another port */
412-
if (!$soc) {
413-
$pasv_port = rand(50000, 65535);
414-
}
415-
$i++;
416-
} while ($i<10 && !$soc);
417-
399+
if (!empty($ssl)) {
400+
$soc = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
401+
} else {
402+
$soc = stream_socket_server("tcp://127.0.0.1:0");
403+
}
418404
if (!$soc) {
419405
echo "$errstr ($errno)\n";
420406
die("could not bind passive port\n");
421407
}
408+
409+
$soc_name = stream_socket_get_name($soc, false);
410+
$pasv_port = (int) substr($socket_name, strrpos($soc_name, ':') + 1);
422411
} else {
423-
$pasv_port=1234;
412+
$pasv_port = 1234;
424413
}
425414

426415
$p2 = $pasv_port % ((int) 1 << 8);

0 commit comments

Comments
 (0)