From c8f7a7dcb2d105a3cdbe8a6fd49c31b6c5034c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 16 Aug 2023 00:39:55 +0800 Subject: [PATCH] qqq --- Pool.php | 6 +++++- PoolItem.php | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Pool.php b/Pool.php index 9e80831..5567ee6 100644 --- a/Pool.php +++ b/Pool.php @@ -64,7 +64,11 @@ class Pool implements PoolInterface if (!isset($this->_connections[$name])) { throw new Exception('Channel is not exists.'); } - return $this->_connections[$name]; + $channel = $this->_connections[$name]; + if ($channel->isClose()) { + $channel->reconnect(); + } + return $channel; } diff --git a/PoolItem.php b/PoolItem.php index 5990dbd..673e501 100644 --- a/PoolItem.php +++ b/PoolItem.php @@ -37,6 +37,29 @@ class PoolItem } + /** + * @return bool + */ + public function isClose(): bool + { + if ($this->_items instanceof Channel) { + return $this->_items->errCode == SWOOLE_CHANNEL_CLOSED; + } + return false; + } + + + /** + * @return void + */ + public function reconnect(): void + { + if ($this->_items instanceof Channel && $this->_items->errCode == SWOOLE_CHANNEL_CLOSED) { + $this->_items = new Channel($this->maxCreated); + } + } + + /** * @param Channel|SplQueue $items */