[asterisk-commits] tilghman: branch 1.4 r99341 - in /branches/1.4: configs/ include/asterisk/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 10:39:38 CST 2008


Author: tilghman
Date: Mon Jan 21 12:11:07 2008
New Revision: 99341

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99341
Log:
Permit the user to specify number of seconds that a connection may remain idle,
which fixes a crash on reconnect with the MyODBC driver.
(closes issue #11798)
 Reported by: Corydon76
 Patches: 
       20080119__res_odbc__idlecheck.diff.txt uploaded by Corydon76 (license 14)
 Tested by: mvanbaak

Modified:
    branches/1.4/configs/res_odbc.conf.sample
    branches/1.4/include/asterisk/res_odbc.h
    branches/1.4/res/res_odbc.c

Change Statistics:
 branches/1.4/configs/res_odbc.conf.sample |    5 +++
 branches/1.4/include/asterisk/res_odbc.h  |    1 
 branches/1.4/res/res_odbc.c               |   25 ++++++++++++++----
 3 files changed, 26 insertions(+), 5 deletions(-)

Modified: branches/1.4/configs/res_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/branches/1.4/configs/res_odbc.conf.sample?view=diff&rev=99341&r1=99340&r2=99341
==============================================================================
--- branches/1.4/configs/res_odbc.conf.sample (original)
+++ branches/1.4/configs/res_odbc.conf.sample Mon Jan 21 12:11:07 2008
@@ -23,6 +23,11 @@
 username => myuser
 password => mypass
 pre-connect => yes
+;
+; On some databases, the connection times out and a reconnection will be
+; necessary.  This setting configures the amount of time a connection
+; may sit idle (in seconds) before a reconnection will be attempted.
+;idlecheck => 3600
 
 ; Certain servers, such as MS SQL Server and Sybase use the TDS protocol, which
 ; limits the number of active queries per connection to 1.  By setting up pools

Modified: branches/1.4/include/asterisk/res_odbc.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/res_odbc.h?view=diff&rev=99341&r1=99340&r2=99341
==============================================================================
--- branches/1.4/include/asterisk/res_odbc.h (original)
+++ branches/1.4/include/asterisk/res_odbc.h Mon Jan 21 12:11:07 2008
@@ -37,6 +37,7 @@
 	ast_mutex_t lock;
 	SQLHDBC  con;                   /* ODBC Connection Handle */
 	struct odbc_class *parent;      /* Information about the connection is protected */
+	struct timeval last_used;
 	unsigned int used:1;
 	unsigned int up:1;
 	AST_LIST_ENTRY(odbc_obj) list;

Modified: branches/1.4/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/res/res_odbc.c?view=diff&rev=99341&r1=99340&r2=99341
==============================================================================
--- branches/1.4/res/res_odbc.c (original)
+++ branches/1.4/res/res_odbc.c Mon Jan 21 12:11:07 2008
@@ -53,6 +53,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/lock.h"
 #include "asterisk/res_odbc.h"
+#include "asterisk/time.h"
 
 struct odbc_class
 {
@@ -67,6 +68,7 @@
 	unsigned int count:10;          /* Running count of pooled connections */
 	unsigned int delme:1;			/* Purge the class */
 	unsigned int backslash_is_escape:1;	/* On this database, the backslash is a native escape sequence */
+	unsigned int idlecheck;			/* Recheck the connection if it is idle for this long */
 	AST_LIST_HEAD(, odbc_obj) odbc_obj;
 };
 
@@ -121,7 +123,8 @@
 				odbc_obj_disconnect(obj);
 				odbc_obj_connect(obj);
 				continue;
-			}
+			} else
+				obj->last_used = ast_tvnow();
 			break;
 		} else {
 			ast_log(LOG_WARNING, "SQL Prepare failed.  Attempting a reconnect...\n");
@@ -169,7 +172,8 @@
 		odbc_obj_connect(obj);
 		res = SQLExecute(stmt);
 #endif
-	}
+	} else
+		obj->last_used = ast_tvnow();
 	
 	return res;
 }
@@ -214,6 +218,7 @@
 	struct ast_variable *v;
 	char *cat, *dsn, *username, *password;
 	int enabled, pooling, limit, bse;
+	unsigned int idlecheck;
 	int connect = 0, res = 0;
 
 	struct odbc_class *new;
@@ -233,7 +238,7 @@
 			/* Reset all to defaults for each class of odbc connections */
 			dsn = username = password = NULL;
 			enabled = 1;
-			connect = 0;
+			connect = idlecheck = 0;
 			pooling = 0;
 			limit = 0;
 			bse = 1;
@@ -251,6 +256,8 @@
 						enabled = 0;
 						break;
 					}
+				} else if (!strcasecmp(v->name, "idlecheck")) {
+					sscanf(v->value, "%d", &idlecheck);
 				} else if (!strcasecmp(v->name, "enabled")) {
 					enabled = ast_true(v->value);
 				} else if (!strcasecmp(v->name, "pre-connect")) {
@@ -303,6 +310,7 @@
 				}
 
 				new->backslash_is_escape = bse ? 1 : 0;
+				new->idlecheck = idlecheck;
 
 				odbc_register_class(new, connect);
 				ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
@@ -465,7 +473,9 @@
 
 	if (obj && check) {
 		ast_odbc_sanity_check(obj);
-	}
+	} else if (obj->parent->idlecheck > 0 && ast_tvdiff_ms(ast_tvnow(), obj->last_used) / 1000 > obj->parent->idlecheck)
+		odbc_obj_connect(obj);
+
 	return obj;
 }
 
@@ -533,6 +543,7 @@
 	} else {
 		ast_log(LOG_NOTICE, "res_odbc: Connected to %s [%s]\n", obj->parent->name, obj->parent->dsn);
 		obj->up = 1;
+		obj->last_used = ast_tvnow();
 	}
 
 	ast_mutex_unlock(&obj->lock);
@@ -546,6 +557,7 @@
 	struct ast_variable *v;
 	char *cat, *dsn, *username, *password;
 	int enabled, pooling, limit, bse;
+	unsigned int idlecheck;
 	int connect = 0, res = 0;
 
 	struct odbc_class *new, *class;
@@ -569,7 +581,7 @@
 				/* Reset all to defaults for each class of odbc connections */
 				dsn = username = password = NULL;
 				enabled = 1;
-				connect = 0;
+				connect = idlecheck = 0;
 				pooling = 0;
 				limit = 0;
 				bse = 1;
@@ -586,6 +598,8 @@
 							enabled = 0;
 							break;
 						}
+					} else if (!strcasecmp(v->name, "idlecheck")) {
+						sscanf(v->value, "%ud", &idlecheck);
 					} else if (!strcasecmp(v->name, "enabled")) {
 						enabled = ast_true(v->value);
 					} else if (!strcasecmp(v->name, "pre-connect")) {
@@ -653,6 +667,7 @@
 					}
 
 					new->backslash_is_escape = bse;
+					new->idlecheck = idlecheck;
 
 					if (class) {
 						ast_log(LOG_NOTICE, "Refreshing ODBC class '%s' dsn->[%s]\n", cat, dsn);




More information about the asterisk-commits mailing list