From 5f7a63a2c0f9c3949e95e2c7412cd783524ccd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 25 Aug 2023 09:37:59 +0800 Subject: [PATCH] qqq --- Pool.php | 9 ++++++--- PoolItem.php | 10 ++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Pool.php b/Pool.php index c23cdf4..f516da6 100644 --- a/Pool.php +++ b/Pool.php @@ -26,6 +26,10 @@ class Pool implements PoolInterface public function flush($name, $retain_number): void { if ($this->hasChannel($name)) { + if ($retain_number == 0) { + $this->close($name); + return; + } $this->channel($name)->tailor($retain_number); } } @@ -65,7 +69,7 @@ class Pool implements PoolInterface throw new Exception('Channel is not exists.'); } $channel = $this->_connections[$name]; - if ($channel->isClose()) { + if ($channel == null || $channel->isClose()) { $channel->reconnect(); } return $channel; @@ -189,8 +193,7 @@ class Pool implements PoolInterface if ($channel === null) { return; } - $channel->tailor(0); - $channel->close(); + $this->_connections[$name] = null; } diff --git a/PoolItem.php b/PoolItem.php index d2e7d72..7e22a19 100644 --- a/PoolItem.php +++ b/PoolItem.php @@ -32,11 +32,7 @@ class PoolItem */ public function __construct(readonly public int $maxCreated, readonly public Closure|array $callback) { - if (Coroutine::getCid() > -1) { - $this->_items = new Channel($this->maxCreated); - } else { - $this->_items = new SplQueue($this->maxCreated); - } + $this->reconnect(); } @@ -57,8 +53,10 @@ class PoolItem */ public function reconnect(): void { - if ($this->_items instanceof Channel && $this->_items->errCode == SWOOLE_CHANNEL_CLOSED) { + if (Coroutine::getCid() > -1) { $this->_items = new Channel($this->maxCreated); + } else { + $this->_items = new SplQueue($this->maxCreated); } }