execute($server, $fd); } catch (\Throwable $exception) { $this->addError($exception); } finally { fire(Event::SYSTEM_RESOURCE_RELEASES); logger()->insert(); } } /** * @param Server $server * @param int $fd * @throws ComponentException * @throws Exception */ private function execute(Server $server, int $fd): void { if (!$this->isWebsocket($server, $fd)) { $client = $server->getClientInfo($fd); fire($this->name($client['server_port']), [$server, $fd]); } else { $this->loadNode($server, $fd); } } /** * @param $server_port * @return string */ private function name($server_port): string { return 'listen ' . $server_port . ' ' . Event::SERVER_CLIENT_CLOSE; } /** * @param $server * @param $fd * @return bool */ private function isWebsocket($server, $fd): bool { return $server instanceof WebsocketServer && $server->isEstablished($fd); } /** * @param $server * @param $fd * @return mixed * @throws ComponentException * @throws ConfigException * @throws NotFindClassException * @throws Exception */ private function loadNode($server, $fd): mixed { $query = Request::socketQuery((object)['fd' => $fd], Socket::CLOSE); if (($node = router()->find_path($query)) !== null) { return $node->dispatch($server, $fd); } return null; } }