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