diff --git a/Annotation/Loader.php b/Annotation/Loader.php index 80a65dbb..474fec6c 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -155,7 +155,6 @@ class Loader extends BaseObject * @param string $namespace * @return ReflectionClass|null * @throws ReflectionException - * @throws NotFindClassException */ private function getReflect(DirectoryIterator $path, string $namespace): ?ReflectionClass { diff --git a/Server/ApplicationStore.php b/Server/ApplicationStore.php index 892d05a8..97ec1297 100644 --- a/Server/ApplicationStore.php +++ b/Server/ApplicationStore.php @@ -6,6 +6,7 @@ namespace Server; use JetBrains\PhpStorm\Pure; use Swoole\Coroutine\Channel; +use const Grpc\CHANNEL_SHUTDOWN; class ApplicationStore { @@ -22,7 +23,7 @@ class ApplicationStore */ private function __construct() { - $this->lock = new Channel(99999); + $this->lock = new Channel(1); } @@ -41,9 +42,8 @@ class ApplicationStore /** * @return $this */ - public function add(): static + public function instance(): static { - $this->lock->push(1); return $this; } @@ -53,13 +53,20 @@ class ApplicationStore */ public function waite(): void { - if ($this->lock->isEmpty()) { + if ($this->lock->errCode == SWOOLE_CHANNEL_CLOSED) { return; } $this->lock->pop(-1); } + public function close() + { + $this->lock->push(1); + $this->lock->close(); + } + + /** * */ diff --git a/Server/HTTPServerListener.php b/Server/HTTPServerListener.php index 3aea8ca6..85ff1162 100644 --- a/Server/HTTPServerListener.php +++ b/Server/HTTPServerListener.php @@ -52,7 +52,6 @@ class HTTPServerListener extends Abstracts\Server * @param int $mode * @param array|null $settings * @return Server\Port - * @throws NotFindClassException * @throws ReflectionException * @throws Exception */ @@ -71,7 +70,6 @@ class HTTPServerListener extends Abstracts\Server static::$_http->set(array_merge($settings['settings'] ?? [], ['enable_unsafe_event' => false])); static::$_http->on('request', [$reflect, 'onRequest']); static::$_http->on('connect', [$reflect, 'onConnect']); - static::$_http->on('disconnect', [$reflect, 'onDisconnect']); static::$_http->on('close', [$reflect, 'onClose']); return static::$_http; } diff --git a/Server/TCPServerListener.php b/Server/TCPServerListener.php index f3d25150..d06dceec 100644 --- a/Server/TCPServerListener.php +++ b/Server/TCPServerListener.php @@ -43,7 +43,6 @@ class TCPServerListener extends Abstracts\Server /** @var static $reflect */ $reflect = Snowflake::getDi()->getReflect(static::class)?->newInstance(); - $reflect->setEvents(Constant::DISCONNECT, $settings['events'][Constant::DISCONNECT] ?? null); $reflect->setEvents(Constant::CLOSE, $settings['events'][Constant::CLOSE] ?? null); $reflect->setEvents(Constant::RECEIVE, $settings['events'][Constant::RECEIVE] ?? null); $reflect->setEvents(Constant::CONNECT, $settings['events'][Constant::CONNECT] ?? null); @@ -56,25 +55,10 @@ class TCPServerListener extends Abstracts\Server static::$_tcp->on('receive', [$reflect, 'onReceive']); static::$_tcp->on('connect', [$reflect, 'onConnect']); static::$_tcp->on('close', [$reflect, 'onClose']); - static::$_tcp->on('disconnect', [$reflect, 'onDisconnect']); return static::$_tcp; } - /** - * @param Server $server - * @param int $fd - * @param int|null $reactor_id - * @throws Exception - */ - public function onDisconnect(Server $server, int $fd, ?int $reactor_id = null) - { - $this->runEvent(Constant::HANDSHAKE, null, [$server, $fd, $reactor_id]); - - $this->_event->dispatch(Event::SYSTEM_RESOURCE_RELEASES); - } - - /** * @param Server $server * @param int $fd diff --git a/Server/Worker/ServerWorker.php b/Server/Worker/ServerWorker.php index 12cf2c31..53fd542e 100644 --- a/Server/Worker/ServerWorker.php +++ b/Server/Worker/ServerWorker.php @@ -35,7 +35,7 @@ class ServerWorker extends \Server\Abstracts\Server { $this->_setConfigCache($workerId); - $store = ApplicationStore::getStore()->add(); + $store = ApplicationStore::getStore()->instance(); $annotation = Snowflake::app()->getAnnotation(); $annotation->read(APP_PATH . 'app'); @@ -50,7 +50,7 @@ class ServerWorker extends \Server\Abstracts\Server $this->workerInitExecutor($server, $annotation, $workerId); $this->interpretDirectory($annotation); - $store->done(); + $store->close(); }