From b45adb47fc01e45ada66bc9b8cddd5adf84ec992 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 13 May 2011 16:58:53 +0000 Subject: [PATCH] mysqlxx: added timeouts. --- libs/libmysqlxx/include/mysqlxx/Connection.h | 2 ++ libs/libmysqlxx/src/Connection.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/libs/libmysqlxx/include/mysqlxx/Connection.h b/libs/libmysqlxx/include/mysqlxx/Connection.h index 4da097fade9..79d6250832e 100644 --- a/libs/libmysqlxx/include/mysqlxx/Connection.h +++ b/libs/libmysqlxx/include/mysqlxx/Connection.h @@ -9,6 +9,8 @@ #include +#define MYSQLXX_TIMEOUT 60 + namespace mysqlxx { diff --git a/libs/libmysqlxx/src/Connection.cpp b/libs/libmysqlxx/src/Connection.cpp index 0c5ee1438f9..e6f6d61768a 100644 --- a/libs/libmysqlxx/src/Connection.cpp +++ b/libs/libmysqlxx/src/Connection.cpp @@ -41,6 +41,12 @@ void Connection::connect(const char* db, if (!mysql_init(&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)) throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));