|
|
|
@ -103,8 +103,9 @@ mySQL::mySQL(const string _path, const string _username, const string _password, |
|
|
|
|
|
|
|
|
|
drv = get_mysql_driver_instance(); |
|
|
|
|
|
|
|
|
|
bot = async(launch::async, [&]{ |
|
|
|
|
bot = async(launch::async, [&](){ |
|
|
|
|
while (runBot) { |
|
|
|
|
sleep(1); |
|
|
|
|
while (available>con.size() && runBot) { |
|
|
|
|
try { |
|
|
|
|
Connection* new_con_ptr = create_con(); |
|
|
|
@ -122,9 +123,17 @@ mySQL::mySQL(const string _path, const string _username, const string _password, |
|
|
|
|
cout << except << endl; |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
usleep(1000); // za smanjenje zauzeća procesora
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i=0; i<con.size() && runBot; i++) { |
|
|
|
|
if (!con[i]->isValid()) { |
|
|
|
|
cout << "Connection is not valid, remove it from pool!" << endl; |
|
|
|
|
io.lock(); |
|
|
|
|
con.erase(con.begin()+i); |
|
|
|
|
io.unlock(); |
|
|
|
|
i--; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -297,19 +306,18 @@ void mySQL::getColumns(const string _table, vector<string> &_columns, Connection |
|
|
|
|
|
|
|
|
|
Connection* mySQL::shift_con() { |
|
|
|
|
while (true) { |
|
|
|
|
while(con.size()) { |
|
|
|
|
io.lock(); |
|
|
|
|
for (int i=0; i<con.size(); i++) { |
|
|
|
|
Connection* con_ptr = con[0]; |
|
|
|
|
con.pop_front(); |
|
|
|
|
if (con_ptr->isValid()) { |
|
|
|
|
io.unlock(); |
|
|
|
|
return con_ptr; |
|
|
|
|
} else { |
|
|
|
|
--i; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
io.unlock(); |
|
|
|
|
} |
|
|
|
|
usleep(1000); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mySQL::~mySQL() { |
|
|
|
|