src/MysqlPool/MySQLPool.php
public static function initConn(\swoole_server $server, int $fd, string $connName, $tryStep = 0)
    {
        ++self::$initConnCount[$connName];
        $chan = new \Swoole\Coroutine\Channel(1);
        $conn = new MysqlProxy($server, $fd, $chan);
        $serverInfo = self::$connsConfig[$connName]['serverInfo'];
        if (false == strpos($connName, DB_DELIMITER)) {
            $conn->database = 0;
            $conn->model    = $connName;
        } else {
            $conn->database = substr($connName, strpos($connName, DB_DELIMITER) + strlen(DB_DELIMITER));
            $conn->model    = substr($connName, 0, strpos($connName, DB_DELIMITER));
        }

        $conn->account  = $serverInfo['account'];
        $conn->charset  = self::$connsConfig[$connName]['charset'];
        if (false == $conn->connect($serverInfo['host'], $serverInfo['port'], $serverInfo['timeout'] ?? 0.1)) {
            --self::$initConnCount[$connName];
            $message = 'SMProxy@MySQL server has gone away';
            $errMessage = self::writeErrMessage(1, $message, ErrorCode::ER_HAS_GONE_AWAY);
            if ($server->exist($fd)) {
                $server->send($fd, getString($errMessage));
            }
            throw new MySQLException($message);
        }
        $client = self::coPop($chan, $serverInfo['timeout'] * 3);
        if ($client === false) {
            --self::$initConnCount[$connName];
            if ($tryStep < 3) {
                return self::initConn($server, $fd, $connName, ++$tryStep);
            } else {
                $message = 'SMProxy@Connection ' . $serverInfo['host'] . ':' . $serverInfo['port'] .
                    ' waiting timeout, timeout=' . $serverInfo['timeout'];
                $errMessage = self::writeErrMessage(1, $message, ErrorCode::ER_HAS_GONE_AWAY);
                if ($server->exist($fd)) {
                    $server->send($fd, getString($errMessage));
                }
                throw new MySQLException($message);
            }
        }
        $id = spl_object_hash($client);
        self::$connsNameMap[$id] = $connName;
        self::$busyConns[$connName][$id] = $client;
        self::$lastConnsTime[$id] = microtime(true);
        --self::$initConnCount[$connName];
        return $client;
    }
public static function initConn(\swoole_server $server, int $fd, string $connName, $tryStep = 0)
    {
        ++self::$initConnCount[$connName];
        $chan = new \Swoole\Coroutine\Channel(1);
        $conn = new MysqlProxy($server, $fd, $chan);
        $serverInfo = self::$connsConfig[$connName]['serverInfo'];
        if (false == strpos($connName, DB_DELIMITER)) {
            $conn->database = 0;
            $conn->model    = $connName;
        } else {
            $conn->database = substr($connName, strpos($connName, DB_DELIMITER) + strlen(DB_DELIMITER));
            $conn->model    = substr($connName, 0, strpos($connName, DB_DELIMITER));
        }

        $conn->account  = $serverInfo['account'];
        $conn->charset  = self::$connsConfig[$connName]['charset'];
        if (false == $conn->connect($serverInfo['host'], $serverInfo['port'], $serverInfo['timeout'] ?? 0.1)) {
            --self::$initConnCount[$connName];
            $message = 'SMProxy@MySQL server has gone away';
            $errMessage = self::writeErrMessage(1, $message, ErrorCode::ER_HAS_GONE_AWAY);
            if ($server->exist($fd)) {
                $server->send($fd, getString($errMessage));
            }
            throw new MySQLException($message);
        }
        $client = self::coPop($chan, $serverInfo['timeout'] * 3);
        if ($client === false) {
            --self::$initConnCount[$connName];
            if ($tryStep < 3) {
                return self::initConn($server, $fd, $connName, ++$tryStep);
            } else {
                $message = 'SMProxy@Connection ' . $serverInfo['host'] . ':' . $serverInfo['port'] .
                    ' waiting timeout, timeout=' . $serverInfo['timeout'];
                $errMessage = self::writeErrMessage(1, $message, ErrorCode::ER_HAS_GONE_AWAY);
                if ($server->exist($fd)) {
                    $server->send($fd, getString($errMessage));
                }
                throw new MySQLException($message);
            }
        }
        $id = spl_object_hash($client);
        self::$connsNameMap[$id] = $connName;
        self::$busyConns[$connName][$id] = $client;
        self::$lastConnsTime[$id] = microtime(true);
        --self::$initConnCount[$connName];
        return $client;
    }
初始化链接.

@param \swoole_server $server
@param int            $fd
@param string         $connName

@return mixed

@throws MySQLException
@throws \SMProxy\SMProxyException