[svn-commits] trunk r259 - in /trunk: ./ res_config_mysql.c
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Sun Jul 9 22:14:04 MST 2006
Author: tilghman
Date: Mon Jul 10 00:14:04 2006
New Revision: 259
URL: http://svn.digium.com/view/asterisk-addons?rev=259&view=rev
Log:
Merged revisions 257-258 via svnmerge from
https://origsvn.digium.com/svn/asterisk-addons/branches/1.2
........
r257 | tilghman | 2006-07-09 23:13:07 -0500 (Sun, 09 Jul 2006) | 2 lines
Bug 7410 - Fix mysql reconnection on mysql client version > 5.0.3
........
r258 | tilghman | 2006-07-09 23:14:55 -0500 (Sun, 09 Jul 2006) | 2 lines
Revert previous change as it was not ready
........
Modified:
trunk/ (props changed)
trunk/res_config_mysql.c
Propchange: trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jul 10 00:14:04 2006
@@ -1,1 +1,1 @@
-/branches/1.2:1-183,209,211
+/branches/1.2:1-183,209,211,257-258
Modified: trunk/res_config_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/res_config_mysql.c?rev=259&r1=258&r2=259&view=diff
==============================================================================
--- trunk/res_config_mysql.c (original)
+++ trunk/res_config_mysql.c Mon Jul 10 00:14:04 2006
@@ -49,6 +49,7 @@
#include <asterisk/cli.h>
#include <asterisk/utils.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include <mysql/mysql_version.h>
@@ -581,6 +582,9 @@
static int mysql_reconnect(const char *database)
{
char my_database[50];
+#ifdef MYSQL_OPT_RECONNECT
+ my_bool trueval = 1;
+#endif
if(!database || ast_strlen_zero(database))
ast_copy_string(my_database, dbname, sizeof(my_database));
@@ -589,6 +593,7 @@
/* mutex lock should have been locked before calling this function. */
+reconnect_tryagain:
if((!connected) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
if(!mysql_init(&mysql)) {
ast_log(LOG_WARNING, "MySQL RealTime: Insufficient memory to allocate MySQL resource.\n");
@@ -596,29 +601,36 @@
return 0;
}
if(mysql_real_connect(&mysql, dbhost, dbuser, dbpass, my_database, dbport, dbsock, 0)) {
+#ifdef MYSQL_OPT_RECONNECT
+ /* The default is no longer to automatically reconnect on failure,
+ * (as of 5.0.3) so we have to set that option here. */
+ mysql_options(&mysql, MYSQL_OPT_RECONNECT, &trueval);
+#endif
ast_log(LOG_DEBUG, "MySQL RealTime: Successfully connected to database.\n");
connected = 1;
connect_time = time(NULL);
return 1;
} else {
- ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s. Check debug for more info.\n", dbname, dbhost);
- ast_log(LOG_DEBUG, "MySQL RealTime: Cannot Connect: %s\n", mysql_error(&mysql));
+ ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s (err %d). Check debug for more info.\n", dbname, dbhost, mysql_errno(&mysql));
+ ast_log(LOG_DEBUG, "MySQL RealTime: Cannot Connect (%d): %s\n", mysql_errno(&mysql), mysql_error(&mysql));
connected = 0;
return 0;
}
} else {
- if(mysql_ping(&mysql) != 0) {
+ /* MySQL likes to return an error, even if it reconnects successfully.
+ * So the postman pings twice. */
+ if (mysql_ping(&mysql) != 0 && mysql_ping(&mysql) != 0) {
connected = 0;
- ast_log(LOG_ERROR, "MySQL RealTime: Failed to reconnect. Check debug for more info.\n");
- ast_log(LOG_DEBUG, "MySQL RealTime: Server Error: %s\n", mysql_error(&mysql));
- return 0;
+ ast_log(LOG_ERROR, "MySQL RealTime: Ping failed (%d). Trying an explicit reconnect.\n", mysql_errno(&mysql));
+ ast_log(LOG_DEBUG, "MySQL RealTime: Server Error (%d): %s\n", mysql_errno(&mysql), mysql_error(&mysql));
+ goto reconnect_tryagain;
}
connected = 1;
if(mysql_select_db(&mysql, my_database) != 0) {
- ast_log(LOG_WARNING, "MySQL RealTime: Unable to select database: %s. Still Connected.\n", my_database);
- ast_log(LOG_DEBUG, "MySQL RealTime: Database Select Failed: %s\n", mysql_error(&mysql));
+ ast_log(LOG_WARNING, "MySQL RealTime: Unable to select database: %s. Still Connected (%d).\n", my_database, mysql_errno(&mysql));
+ ast_log(LOG_DEBUG, "MySQL RealTime: Database Select Failed (%d): %s\n", mysql_error(&mysql), mysql_errno(&mysql));
return 0;
}
More information about the svn-commits
mailing list