|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
#include "../lib/mysql.hpp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
marcelb::mysql::MySQL::MySQL(const string _path, const string _username, const string _password, const string _db, const uint32_t _available, const time_loop_type _engine_type) { |
|
|
|
|
path = _path; |
|
|
|
|
username = _username; |
|
|
|
@ -30,7 +29,6 @@ Connection* marcelb::mysql::MySQL::create_connection() { |
|
|
|
|
uint32_t trys = 0; |
|
|
|
|
bool status = true; |
|
|
|
|
Connection* new_con = NULL; |
|
|
|
|
|
|
|
|
|
while (connect_trys == unlimited ? status : (trys <= connect_trys && status)) { |
|
|
|
|
try { |
|
|
|
|
Connection* con_can = drv->connect(path, username, password); |
|
|
|
@ -99,19 +97,33 @@ void marcelb::mysql::MySQL::_tloop() { |
|
|
|
|
if (!run_tloop) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
lock_guard<mutex> lock(io); |
|
|
|
|
for (size_t i=0; i<connection_pool.size(); i++) { |
|
|
|
|
try { |
|
|
|
|
Connection *conn = connection_pool.front(); |
|
|
|
|
connection_pool.pop(); |
|
|
|
|
Connection *conn = nullptr; |
|
|
|
|
{ |
|
|
|
|
lock_guard<mutex> lock(io); |
|
|
|
|
conn = connection_pool.front(); |
|
|
|
|
connection_pool.pop(); |
|
|
|
|
} |
|
|
|
|
if (conn->isValid()) { |
|
|
|
|
cout << "Validno----" << endl; |
|
|
|
|
connection_pool.push(conn); |
|
|
|
|
condition.notify_one(); |
|
|
|
|
} else { |
|
|
|
|
cout << "Nije validno----" << endl; |
|
|
|
|
if (!conn->isClosed()){ |
|
|
|
|
cout << "Zatvori----" << endl; |
|
|
|
|
|
|
|
|
|
conn->close(); |
|
|
|
|
} |
|
|
|
|
Connection *n_conn = create_connection(); |
|
|
|
|
release_connection(n_conn); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
lock_guard<mutex> lock(io); |
|
|
|
|
connection_pool.push(n_conn); |
|
|
|
|
condition.notify_one(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} catch (const SQLException &error) { |
|
|
|
|
if (on_error) { |
|
|
|
|