This commit is contained in:
Marcel Pociot
2020-09-07 21:35:42 +02:00
parent e857de8498
commit 3a3dc85e72
2 changed files with 30 additions and 1 deletions

View File

@@ -82,7 +82,20 @@ class ConnectionManager implements ConnectionManagerContract
protected function getSharedTcpServer(): Server
{
return new Server(0, $this->loop);
$portRange = [50000, 62000];
$port = $portRange[0];
do {
try {
$portFound = true;
$server = new Server('127.0.0.1:'.$port, $this->loop);
} catch (\RuntimeException $exception) {
$portFound = false;
$port++;
}
} while(! $portFound);
return $server;
}
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection
@@ -107,6 +120,16 @@ class ConnectionManager implements ConnectionManagerContract
if (isset($connection->client_id)) {
$clientId = $connection->client_id;
$controlConnection = collect($this->connections)->first(function ($connection) use ($clientId) {
return $connection->client_id == $clientId;
});
if ($controlConnection instanceof TcpControlConnection) {
$controlConnection->stop();
$controlConnection = null;
}
$this->connections = collect($this->connections)->reject(function ($connection) use ($clientId) {
return $connection->client_id == $clientId;
})->toArray();

View File

@@ -60,6 +60,12 @@ class TcpControlConnection extends ControlConnection
]));
}
public function stop()
{
$this->shared_server->close();
$this->shared_server = null;
}
public function close()
{
$this->socket->close();