mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
连接池支持最大连接数设置
This commit is contained in:
parent
f13afe26ea
commit
5a29b47c6c
@ -35,7 +35,7 @@ public:
|
||||
* @param maxIdleConnect 运行的最大空闲连接数,为 0 表示不限制
|
||||
*/
|
||||
explicit ConnectPool(const Parameter ¶m, size_t maxConnect = 0, size_t maxIdleConnect = 0)
|
||||
: m_maxConnectSize(0),
|
||||
: m_maxConnectSize(maxConnect),
|
||||
m_maxIdelSize(maxIdleConnect),
|
||||
m_count(0),
|
||||
m_param(param),
|
||||
@ -60,10 +60,10 @@ public:
|
||||
/** 获取可用连接,如超出允许的最大连接数将返回空指针 */
|
||||
ConnectPtr getConnect() noexcept {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_maxConnectSize > 0 && m_count > m_maxConnectSize) {
|
||||
return ConnectPtr();
|
||||
}
|
||||
if (m_connectList.empty()) {
|
||||
if (m_maxConnectSize > 0 && m_count >= m_maxConnectSize) {
|
||||
return ConnectPtr();
|
||||
}
|
||||
m_count++;
|
||||
return ConnectPtr(new ConnectType(m_param), m_closer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user