Преглед на файлове

ping_interval parameter implemented, the module calls mysql_ping if the
connection has been inactive for >= ping_interval.

Jan Janak преди 21 години
родител
ревизия
a041800f53
променени са 5 файла, в които са добавени 78 реда и са изтрити 7 реда
  1. 17 6
      modules/db_mysql/db_mod.c
  2. 41 0
      modules/db_mysql/db_mod.h
  3. 13 0
      modules/db_mysql/dbase.c
  4. 3 0
      modules/db_mysql/my_con.c
  5. 4 1
      modules/db_mysql/my_con.h

+ 17 - 6
modules/db_mysql/db_mod.c

@@ -35,7 +35,9 @@
 
 #include "../../sr_module.h"
 #include "dbase.h"
+#include "db_mod.h"
 
+int ping_interval = 5 * 60; /* Default is 5 minutes */
 
 MODULE_VERSION
 
@@ -57,13 +59,22 @@ static cmd_export_t cmds[] = {
 };
 
 
+/*
+ * Exported parameters
+ */
+static param_export_t params[] = {
+	{"ping_interval", INT_PARAM },
+	{0, 0, 0}
+};
+
+
 struct module_exports exports = {	
 	"mysql",
 	cmds,
-	0,   /*  module paramers */
-	0,   /* module initialization function */
-	0,   /* response function*/
-	0,   /* destroy function */
-	0,   /* oncancel function */
-	0    /* per-child init function */
+	params, /*  module paramers */
+	0,      /* module initialization function */
+	0,      /* response function*/
+	0,      /* destroy function */
+	0,      /* oncancel function */
+	0       /* per-child init function */
 };

+ 41 - 0
modules/db_mysql/db_mod.h

@@ -0,0 +1,41 @@
+/* 
+ * $Id$ 
+ *
+ * MySQL module interface
+ *
+ * Copyright (C) 2001-2003 Fhg Fokus
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-11  updated to the new module exports interface (andrei)
+ *  2003-03-16  flags export parameter added (janakj)
+ */
+
+#ifndef DB_MOD_H
+#define DB_MOD_H
+
+extern int ping_interval;
+
+#endif /* DB_MOD_H */

+ 13 - 0
modules/db_mysql/dbase.c

@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <time.h>
 #include <mysql/mysql.h>
 #include "../../mem/mem.h"
 #include "../../dprint.h"
@@ -38,6 +39,7 @@
 #include "my_con.h"
 #include "my_pool.h"
 #include "res.h"
+#include "db_mod.h"
 #include "dbase.h"
 
 
@@ -51,11 +53,22 @@ static char sql_buf[SQL_BUF_LEN];
  */
 static int submit_query(db_con_t* _h, const char* _s)
 {	
+	time_t t;
+
 	if ((!_h) || (!_s)) {
 		LOG(L_ERR, "submit_query(): Invalid parameter value\n");
 		return -1;
 	}
 
+	t = time(0);
+	if ((t - CON_TIMESTAMP(_h)) > ping_interval) {
+		if (mysql_ping(CON_CONNECTION(_h))) {
+			LOG(L_ERR, "submit_query(): mysql_ping failed\n");
+		} else {
+			CON_TIMESTAMP(_h) = t;
+		}
+	}
+
 	/* screws up the terminal when the query contains a BLOB :-( (by bogdan)
 	 * DBG("submit_query(): %s\n", _s);
 	 */

+ 3 - 0
modules/db_mysql/my_con.c

@@ -27,6 +27,7 @@
  */
 
 #include <string.h>
+#include <time.h>
 #include "my_con.h"
 #include "../../mem/mem.h"
 #include "../../dprint.h"
@@ -69,6 +70,8 @@ struct my_con* new_connection(struct my_id* id)
 		goto err;
 	}
 
+	ptr->timestamp = time(0);
+
 	ptr->id = id;
 	return ptr;
 

+ 4 - 1
modules/db_mysql/my_con.h

@@ -29,15 +29,17 @@
 #ifndef MY_CON_H
 #define MY_CON_H
 
+#include <time.h>
 #include <mysql/mysql.h>
 #include "my_id.h"
 
 struct my_con {
-	struct my_id* id;     /* Connection identifier */
+	struct my_id* id;    /* Connection identifier */
 	int ref;             /* Reference count */
 	MYSQL_RES* res;      /* Actual result */
 	MYSQL* con;          /* Connection representation */
 	MYSQL_ROW row;       /* Actual row in the result */
+	time_t timestamp;    /* Timestamp of last query */
 	struct my_con* next; /* Next connection in the pool */
 };
 
@@ -48,6 +50,7 @@ struct my_con {
 #define CON_RESULT(db_con)     (((struct my_con*)((db_con)->tail))->res)
 #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con)
 #define CON_ROW(db_con)        (((struct my_con*)((db_con)->tail))->row)
+#define CON_TIMESTAMP(db_con)  (((struct my_con*)((db_con)->tail))->timestamp)
 
 
 /*