40 lines
770 B
C++
40 lines
770 B
C++
//
|
|
// Created by dongl on 23-4-25.
|
|
//
|
|
|
|
|
|
#include "linkDB.h"
|
|
|
|
LinkDB::LinkDB() {}
|
|
|
|
LinkDB::~LinkDB() {
|
|
delete pool;
|
|
}
|
|
|
|
ConnectionPool* LinkDB::pool = nullptr;
|
|
|
|
mysqlpp::Connection* LinkDB::safe_grab() {
|
|
// static std::vector<mysqlpp::Connection*> link;
|
|
|
|
// static std::atomic<int> index;
|
|
if (pool == nullptr) {
|
|
pool = new ConnectionPool("124.221.152.192", "ims", "IMS", "WimTFC8N58kznx2k");
|
|
// index = -1;
|
|
// for (int i = 0; i < 30; ++i) {
|
|
// link.push_back(pool->safe_grab());
|
|
// }
|
|
}
|
|
|
|
// ++index;
|
|
// if (index >= link.size()) {
|
|
// index = 0;
|
|
// }
|
|
// return link[index];
|
|
return pool->safe_grab();
|
|
}
|
|
|
|
void LinkDB::release(mysqlpp::Connection *connection) {
|
|
pool->release(connection);
|
|
}
|
|
|