This commit is contained in:
as2252258@163.com
2021-04-27 02:17:55 +08:00
parent 4608a20232
commit cbd2fed3eb
+17 -11
View File
@@ -26,22 +26,28 @@ class OnConnect extends Callback
*/ */
public function onHandler(Server $server, int $fd, int $reactorId) public function onHandler(Server $server, int $fd, int $reactorId)
{ {
defer(function () {
fire(Event::SYSTEM_RESOURCE_RELEASES);
});
$event = Snowflake::app()->getEvent();
$clientInfo = $server->getClientInfo($fd);
try { try {
$name = 'listen ' . $clientInfo['server_port'] . ' ' . Event::SERVER_CONNECT; defer(function () {
fire(Event::SYSTEM_RESOURCE_RELEASES);
$event->trigger($name, [$server, $fd, $reactorId]); });
if (($clientInfo = $server->getClientInfo($fd, $reactorId)) === false) {
return;
}
fire($this->getName($clientInfo), [$server, $fd, $reactorId]);
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$this->addError($throwable, 'connect'); $this->addError($throwable, 'connect');
} }
} }
/**
* @param array $clientInfo
* @return string
*/
private function getName(array $clientInfo): string
{
return 'listen ' . $clientInfo['server_port'] . ' ' . Event::SERVER_CONNECT;
}
} }