From d605b4b218e84d742065ff904a52a49d2878a66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 31 Aug 2021 18:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-helper/Server.php | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/http-helper/Server.php b/http-helper/Server.php index 43e2f604..5af2c4fe 100644 --- a/http-helper/Server.php +++ b/http-helper/Server.php @@ -11,9 +11,8 @@ use Kiri\Abstracts\Config; use Kiri\Error\LoggerProcess; use Kiri\Events\EventDispatch; use Kiri\Exception\ConfigException; -use Kiri\Exception\NotFindClassException; +use Kiri\Rpc\Service; use ReflectionException; -use Server\Constant; use Server\Events\OnShutdown; use Server\ServerManager; use Swoole\Runtime; @@ -78,7 +77,7 @@ class Server extends HttpService $rpcService = Config::get('rpc', []); if (!empty($rpcService)) { - $this->rpcListener($rpcService); + Service::addRpcListener($this->manager, $rpcService); } $processes = array_merge($this->process, Config::get('processes', [])); @@ -91,39 +90,6 @@ class Server extends HttpService } - /** - * @param $rpcService - * @throws ReflectionException - * @throws NotFindClassException - * @throws ConfigException - */ - private function rpcListener($rpcService) - { - if (in_array($rpcService['mode'], [SWOOLE_SOCK_UDP, SWOOLE_UDP, SWOOLE_UDP6, SWOOLE_SOCK_UDP6])) { - $rpcService['events'][Constant::PACKET] = [Service::class, 'onPacket']; - } else { - $rpcService['events'][Constant::RECEIVE] = [Service::class, 'onReceive']; - $rpcService['events'][Constant::CONNECT] = [Service::class, 'onConnect']; - $rpcService['events'][Constant::DISCONNECT] = [Service::class, 'onDisconnect']; - $rpcService['events'][Constant::CLOSE] = [Service::class, 'onClose']; - } - $rpcService['settings']['enable_unsafe_event'] = true; - $this->addRpcListener($rpcService); - } - - - /** - * @param $rpcService - * @throws ConfigException - * @throws NotFindClassException - * @throws ReflectionException - */ - private function addRpcListener($rpcService) - { - $this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService); - } - - /** * @return void *