This commit is contained in:
2021-04-27 17:27:27 +08:00
parent 33083e706f
commit ebc7ad032b
+29 -29
View File
@@ -7,7 +7,6 @@ namespace HttpServer\Events;
use Exception;
use HttpServer\Abstracts\Callback;
use Snowflake\Event;
use Snowflake\Snowflake;
use Swoole\Server;
/**
@@ -18,36 +17,37 @@ class OnConnect extends Callback
{
/**
* @param Server $server
* @param int $fd
* @param int $reactorId
* @throws Exception
*/
public function onHandler(Server $server, int $fd, int $reactorId)
{
try {
defer(function () {
fire(Event::SYSTEM_RESOURCE_RELEASES);
});
if (($clientInfo = $server->getClientInfo($fd, $reactorId)) === false) {
return;
}
fire($this->getName($clientInfo), [$server, $fd, $reactorId]);
} catch (\Throwable $throwable) {
$this->addError($throwable, 'connect');
}
}
/**
* @param Server $server
* @param int $fd
* @param int $reactorId
* @throws Exception
*/
public function onHandler(Server $server, int $fd, int $reactorId)
{
var_dump($fd, $reactorId);
try {
defer(function () {
fire(Event::SYSTEM_RESOURCE_RELEASES);
});
if (($clientInfo = $server->getClientInfo($fd, $reactorId)) === false) {
return;
}
fire($this->getName($clientInfo), [$server, $fd, $reactorId]);
} catch (\Throwable $throwable) {
$this->addError($throwable, 'connect');
}
}
/**
* @param array $clientInfo
* @return string
*/
private function getName(array $clientInfo): string
{
return 'listen ' . $clientInfo['server_port'] . ' ' . Event::SERVER_CONNECT;
}
/**
* @param array $clientInfo
* @return string
*/
private function getName(array $clientInfo): string
{
return 'listen ' . $clientInfo['server_port'] . ' ' . Event::SERVER_CONNECT;
}
}