Fix a bug in the DbClientLockFree class

This commit is contained in:
an-tao 2019-02-18 23:27:30 +08:00
parent 358e45598b
commit 5629efa910
2 changed files with 8 additions and 3 deletions

View File

@ -46,11 +46,15 @@ DbClientLockFree::DbClientLockFree(const std::string &connInfo, trantor::EventLo
LOG_TRACE << "type=" << (int)type;
if (type == ClientType::PostgreSQL)
{
newConnection();
_loop->runInLoop([this](){
_connectionHolder=newConnection();
});
}
else if (type == ClientType::Mysql)
{
newConnection();
_loop->runInLoop([this](){
_connectionHolder=newConnection();
});
}
else
{
@ -207,7 +211,7 @@ DbConnectionPtr DbClientLockFree::newConnection()
auto thisPtr = weakPtr.lock();
if (!thisPtr)
return;
thisPtr->newConnection();
thisPtr->_connectionHolder=thisPtr->newConnection();
});
});
connPtr->setOkCallback([weakPtr](const DbConnectionPtr &okConnPtr) {

View File

@ -60,6 +60,7 @@ class DbClientLockFree : public DbClient, public std::enable_shared_from_this<Db
DbConnectionPtr newConnection();
DbConnectionPtr _connection;
DbConnectionPtr _connectionHolder;
struct SqlCmd
{