summaryrefslogtreecommitdiff
path: root/src/char_sql
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-02-08 23:26:00 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-02-08 23:26:00 +0000
commit5eaad65d1b39258928f49f6dcd98a08800e01444 (patch)
treea761dd0c4f544dcfa07bdac250deab3abfad6a28 /src/char_sql
parent655384295651f8611b0caa2022cbceac073c1b4d (diff)
downloadhercules-5eaad65d1b39258928f49f6dcd98a08800e01444.tar.gz
hercules-5eaad65d1b39258928f49f6dcd98a08800e01444.tar.bz2
hercules-5eaad65d1b39258928f49f6dcd98a08800e01444.tar.xz
hercules-5eaad65d1b39258928f49f6dcd98a08800e01444.zip
- Added code for SQL that will automatically detect the ping interval at startup, and copy-pasted it around the code
- Removed the conf setting as it is not needed anymore git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9830 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char_sql')
-rw-r--r--src/char_sql/char.c3
-rw-r--r--src/char_sql/char.h1
-rw-r--r--src/char_sql/inter.c41
3 files changed, 32 insertions, 13 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index d71ea3483..f81f03cad 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -64,7 +64,6 @@ int save_log = 0; //Have the logs be off by default when converting
#else
int save_log = 1;
int db_use_sqldbs;
-int connection_ping_interval = 0;
char login_db[256] = "login";
char login_db_account_id[32] = "account_id";
@@ -4033,8 +4032,6 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
strcpy(item_db_db,w2);
}else if(strcmpi(w1,"item_db2_db")==0){
strcpy(item_db2_db,w2);
- } else if(strcmpi(w1,"connection_ping_interval")==0) {
- connection_ping_interval = config_switch(w2);
#endif
//support the import command, just like any other config
}else if(strcmpi(w1,"import")==0){
diff --git a/src/char_sql/char.h b/src/char_sql/char.h
index 1ad48fc9b..4a95fd0f8 100644
--- a/src/char_sql/char.h
+++ b/src/char_sql/char.h
@@ -90,7 +90,6 @@ extern char party_db[256];
extern char pet_db[256];
extern int db_use_sqldbs; // added for sql item_db read for char server [Valaris]
-extern int connection_ping_interval;
extern char login_db_level[32];
extern char login_db_account_id[32];
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 326bd2ca1..052316e0a 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -297,10 +297,9 @@ int inter_log(char *fmt,...)
return 0;
}
-/*======================================================
- * Does a mysql_ping to all connection handles. [Skotlex]
- *------------------------------------------------------
- */
+/*=============================================
+ * Does a mysql_ping to all connection handles
+ *---------------------------------------------*/
int inter_sql_ping(int tid, unsigned int tick, int id, int data)
{
ShowInfo("Pinging SQL server to keep connection alive...\n");
@@ -309,6 +308,34 @@ int inter_sql_ping(int tid, unsigned int tick, int id, int data)
mysql_ping(&lmysql_handle);
return 0;
}
+
+
+int sql_ping_init(void)
+{
+ int connection_timeout, connection_ping_interval;
+
+ // set a default value first
+ connection_timeout = 28800; // 8 hours
+
+ // ask the mysql server for the timeout value
+ if (!mysql_query(&mysql_handle, "SHOW VARIABLES LIKE 'wait_timeout'")
+ && (sql_res = mysql_store_result(&mysql_handle)) != NULL) {
+ sql_row = mysql_fetch_row(sql_res);
+ if (sql_row)
+ connection_timeout = atoi(sql_row[1]);
+ if (connection_timeout < 60)
+ connection_timeout = 60;
+ mysql_free_result(sql_res);
+ }
+
+ // establish keepalive
+ connection_ping_interval = connection_timeout - 30; // 30-second reserve
+ add_timer_func_list(inter_sql_ping, "inter_sql_ping");
+ add_timer_interval(gettick() + connection_ping_interval*1000, inter_sql_ping, 0, 0, connection_ping_interval*1000);
+
+ return 0;
+}
+
#endif //TXT_SQL_CONVERT
// initialize
@@ -370,11 +397,7 @@ int inter_init_sql(const char *file)
inter_homunculus_sql_init(); // albator
inter_accreg_sql_init();
- if (connection_ping_interval) {
- add_timer_func_list(inter_sql_ping, "inter_sql_ping");
- add_timer_interval(gettick()+connection_ping_interval*60*60*1000,
- inter_sql_ping, 0, 0, connection_ping_interval*60*60*1000);
- }
+ sql_ping_init();
#endif //TXT_SQL_CONVERT
return 0;
}