mysqlxx: added timeouts.

This commit is contained in:
Alexey Milovidov 2011-05-13 16:58:53 +00:00
parent 4c8f946f70
commit b45adb47fc
2 changed files with 8 additions and 0 deletions

View File

@ -9,6 +9,8 @@
#include <mysqlxx/Query.h> #include <mysqlxx/Query.h>
#define MYSQLXX_TIMEOUT 60
namespace mysqlxx namespace mysqlxx
{ {

View File

@ -41,6 +41,12 @@ void Connection::connect(const char* db,
if (!mysql_init(&driver)) if (!mysql_init(&driver))
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver)); throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
/// Установим таймауты
unsigned int timeout = MYSQLXX_TIMEOUT;
if (!mysql_options(&driver, MYSQL_OPT_CONNECT_TIMEOUT, &timeout)
|| !mysql_options(&driver, MYSQL_OPT_READ_TIMEOUT, &timeout))
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
if (!mysql_real_connect(&driver, server, user, password, db, port, NULL, driver.client_flag)) if (!mysql_real_connect(&driver, server, user, password, db, port, NULL, driver.client_flag))
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver)); throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));