[svn-commits] tilghman: branch 1.4 r475 - /branches/1.4/cdr_addon_mysql.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Oct 26 09:40:33 CDT 2007


Author: tilghman
Date: Fri Oct 26 09:40:32 2007
New Revision: 475

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=475
Log:
Auto reconnect database on connection failure (fixes missing CDRs)
Reported by ys.
Fixed by ys.
Closes issue #11092

Modified:
    branches/1.4/cdr_addon_mysql.c

Modified: branches/1.4/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/branches/1.4/cdr_addon_mysql.c?view=diff&rev=475&r1=474&r2=475
==============================================================================
--- branches/1.4/cdr_addon_mysql.c (original)
+++ branches/1.4/cdr_addon_mysql.c Fri Oct 26 09:40:32 2007
@@ -124,6 +124,9 @@
 #ifdef MYSQL_LOGUNIQUEID
 	char *uniqueid = NULL;
 #endif
+#if MYSQL_VERSION_ID >= 50013
+	my_bool my_bool_true = 1;
+#endif
 
 	ast_mutex_lock(&mysql_lock);
 
@@ -140,6 +143,12 @@
 		if (timeout && mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&timeout)!=0) {
 			ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
 		}
+#if MYSQL_VERSION_ID >= 50013
+		/* Add option for automatic reconnection */
+		if (mysql_options(&mysql, MYSQL_OPT_RECONNECT, &my_bool_true) != 0) {
+			ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+		}
+#endif
 		if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
 			connected = 1;
 			connect_time = time(NULL);
@@ -296,6 +305,9 @@
 	struct ast_config *cfg;
 	struct ast_variable *var;
 	const char *tmp;
+#if MYSQL_VERSION_ID >= 50013
+	my_bool my_bool_true = 1;
+#endif
 
 	cfg = ast_config_load(config);
 	if (!cfg) {
@@ -442,6 +454,13 @@
 		ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
 	}
 
+#if MYSQL_VERSION_ID >= 50013
+	/* Add option for automatic reconnection */
+	if (mysql_options(&mysql, MYSQL_OPT_RECONNECT, &my_bool_true) != 0) {
+		ast_log(LOG_ERROR, "cdr_mysql: mysql_options returned (%d) %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+	}
+#endif
+
 	if (!mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
 		ast_log(LOG_ERROR, "Failed to connect to mysql database %s on %s.\n", dbname, hostname);
 		connected = 0;




More information about the svn-commits mailing list