|
|
@ -103,8 +103,9 @@ mySQL::mySQL(const string _path, const string _username, const string _password, |
|
|
|
|
|
|
|
|
|
|
|
drv = get_mysql_driver_instance(); |
|
|
|
drv = get_mysql_driver_instance(); |
|
|
|
|
|
|
|
|
|
|
|
bot = async(launch::async, [&]{ |
|
|
|
bot = async(launch::async, [&](){ |
|
|
|
while (runBot) { |
|
|
|
while (runBot) { |
|
|
|
|
|
|
|
sleep(1); |
|
|
|
while (available>con.size() && runBot) { |
|
|
|
while (available>con.size() && runBot) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Connection* new_con_ptr = create_con(); |
|
|
|
Connection* new_con_ptr = create_con(); |
|
|
@ -122,9 +123,17 @@ mySQL::mySQL(const string _path, const string _username, const string _password, |
|
|
|
cout << except << endl; |
|
|
|
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; |
|
|
|
return; |
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -297,18 +306,17 @@ void mySQL::getColumns(const string _table, vector<string> &_columns, Connection |
|
|
|
|
|
|
|
|
|
|
|
Connection* mySQL::shift_con() { |
|
|
|
Connection* mySQL::shift_con() { |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
io.lock(); |
|
|
|
while(con.size()) { |
|
|
|
for (int i=0; i<con.size(); i++) { |
|
|
|
io.lock(); |
|
|
|
Connection* con_ptr = con[0]; |
|
|
|
Connection* con_ptr = con[0]; |
|
|
|
con.pop_front(); |
|
|
|
con.pop_front(); |
|
|
|
if (con_ptr->isValid()) { |
|
|
|
if (con_ptr->isValid()) { |
|
|
|
io.unlock(); |
|
|
|
io.unlock(); |
|
|
|
return con_ptr; |
|
|
|
return con_ptr; |
|
|
|
} else { |
|
|
|
|
|
|
|
--i; |
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
io.unlock(); |
|
|
|
usleep(1000); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|