#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/res_odbc.h"
+#include "asterisk/time.h"
struct odbc_class
{
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;
};
*/
ast_odbc_sanity_check(obj);
continue;
- }
+ } else
+ obj->last_used = ast_tvnow();
break;
} else if (attempt == 0)
ast_odbc_sanity_check(obj);
odbc_obj_connect(obj);
res = SQLExecute(stmt);
#endif
- }
+ } else
+ obj->last_used = ast_tvnow();
return res;
}
char *cat;
const char *dsn, *username, *password, *sanitysql;
int enabled, pooling, limit, bse;
+ unsigned int idlecheck;
int connect = 0, res = 0;
struct ast_flags config_flags = { 0 };
/* Reset all to defaults for each class of odbc connections */
dsn = username = password = sanitysql = NULL;
enabled = 1;
- connect = 0;
+ connect = idlecheck = 0;
pooling = 0;
limit = 0;
bse = 1;
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")) {
}
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);
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;
}
} 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);
char *cat;
const char *dsn, *username, *password, *sanitysql;
int enabled, pooling, limit, bse;
+ unsigned int idlecheck;
int connect = 0, res = 0;
struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
/* Reset all to defaults for each class of odbc connections */
dsn = username = password = sanitysql = NULL;
enabled = 1;
- connect = 0;
+ connect = idlecheck = 0;
pooling = 0;
limit = 0;
bse = 1;
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")) {
}
new->backslash_is_escape = bse;
+ new->idlecheck = idlecheck;
if (class) {
ast_log(LOG_NOTICE, "Refreshing ODBC class '%s' dsn->[%s]\n", cat, dsn);