Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit ec93011

Browse files
committed
Try to pick first unoccupied port only if port is not specified
1 parent ae21d87 commit ec93011

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

hyper-run

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ function startListener($master, $listener)
8585
} catch (React\Socket\ConnectionException $exception) {
8686
$reason = 'Address already in use';
8787

88-
if (strpos($exception->getMessage(), $reason) === false) {
88+
$isPortSpecified = $listener[4];
89+
90+
if ($isPortSpecified || strpos($exception->getMessage(), $reason) === false) {
8991
throw $exception;
9092
}
9193

@@ -119,8 +121,17 @@ try {
119121

120122
$listeners = [];
121123
foreach ([$servers, $secures] as $type => $group) {
124+
$isSecure = $type === 1;
122125
foreach ($group as $i => $server) {
123126
list($host, $port) = explode(':', $server, 2) + [1 => ''];
127+
128+
if ($port === '') {
129+
$port = $isSecure ? '44300' : '8000';
130+
$isPortSpecified = false;
131+
} else {
132+
$isPortSpecified = true;
133+
}
134+
124135
$ip = filter_var(gethostbyname($host), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
125136
$regex = '/\A(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])\z/';
126137
if ($ip === false || !preg_match($regex, $port)) {
@@ -129,7 +140,7 @@ try {
129140
if (isset($listeners[$server])) {
130141
throw new \RuntimeException("Duplicated entry: $server");
131142
}
132-
$listeners[$server] = [$host, $port, $type === 1, $cert];
143+
$listeners[$server] = [$host, $port, $isSecure, $cert, $isPortSpecified];
133144
}
134145
}
135146

0 commit comments

Comments
 (0)