diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-02-08 23:26:00 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-02-08 23:26:00 +0000 |
commit | 5eaad65d1b39258928f49f6dcd98a08800e01444 (patch) | |
tree | a761dd0c4f544dcfa07bdac250deab3abfad6a28 /src/map | |
parent | 655384295651f8611b0caa2022cbceac073c1b4d (diff) | |
download | hercules-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/map')
-rw-r--r-- | src/map/map.c | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/src/map/map.c b/src/map/map.c index 5f6421a66..af3f48ad0 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -74,7 +74,6 @@ char map_server_pw[32] = "ragnarok"; char map_server_db[32] = "ragnarok"; char default_codepage[32] = ""; //Feature by irmin. int db_use_sqldbs = 0; -int connection_ping_interval = 0; char item_db_db[32] = "item_db"; char item_db2_db[32] = "item_db2"; @@ -3489,8 +3488,6 @@ int inter_config_read(char *cfgName) } else if(strcmpi(w1,"use_sql_db")==0){ db_use_sqldbs = battle_config_switch(w2); ShowStatus ("Using SQL dbs: %s\n",w2); - } else if(strcmpi(w1,"connection_ping_interval")==0) { - connection_ping_interval = battle_config_switch(w2); }else if(strcmpi(w1, "char_server_ip") == 0){ strcpy(charsql_host, w2); }else if(strcmpi(w1, "char_server_port") == 0){ @@ -3543,9 +3540,7 @@ int inter_config_read(char *cfgName) #ifndef TXT_ONLY /*======================================= * MySQL Init - *--------------------------------------- - */ - + *---------------------------------------*/ int map_sql_init(void){ mysql_init(&mmysql_handle); @@ -3578,6 +3573,7 @@ int map_sql_init(void){ } } } + if( strlen(default_codepage) > 0 ) { sprintf( tmp_sql, "SET NAMES %s", default_codepage ); if (mysql_query(&mmysql_handle, tmp_sql)) { @@ -3585,6 +3581,7 @@ int map_sql_init(void){ ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } + return 0; } @@ -3624,6 +3621,46 @@ int log_sql_init(void){ } return 0; } + +/*============================================= + * Does a mysql_ping to all connection handles + *---------------------------------------------*/ +int map_sql_ping(int tid, unsigned int tick, int id, int data) +{ + ShowInfo("Pinging SQL server to keep connection alive...\n"); + mysql_ping(&mmysql_handle); + if (log_config.sql_logs) + mysql_ping(&logmysql_handle); + if(mail_server_enable) + mysql_ping(&mail_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(&mmysql_handle, "SHOW VARIABLES LIKE 'wait_timeout'") + && (sql_res = mysql_store_result(&mmysql_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(map_sql_ping, "map_sql_ping"); + add_timer_interval(gettick() + connection_ping_interval*1000, map_sql_ping, 0, 0, connection_ping_interval*1000); + + return 0; +} #endif /* not TXT_ONLY */ int map_db_final(DBKey k,void *d,va_list ap) @@ -3809,24 +3846,6 @@ void map_versionscreen(int flag) { if (flag) exit(1); } - -#ifndef TXT_ONLY -/*====================================================== - * Does a mysql_ping to all connection handles. [Skotlex] - *------------------------------------------------------ - */ -int map_sql_ping(int tid, unsigned int tick, int id, int data) -{ - ShowInfo("Pinging SQL server to keep connection alive...\n"); - mysql_ping(&mmysql_handle); - if (log_config.sql_logs) - mysql_ping(&logmysql_handle); - if(mail_server_enable) - mysql_ping(&mail_handle); - return 0; -} -#endif - /*====================================================== * Map-Server Init and Command-line Arguments [Valaris] *------------------------------------------------------ @@ -3965,12 +3984,8 @@ int do_init(int argc, char *argv[]) { if (log_config.sql_logs) log_sql_init(); - - if (connection_ping_interval) { - add_timer_func_list(map_sql_ping, "map_sql_ping"); - add_timer_interval(gettick()+connection_ping_interval*60*60*1000, - map_sql_ping, 0, 0, connection_ping_interval*60*60*1000); - } + + sql_ping_init(); #endif /* not TXT_ONLY */ npc_event_do_oninit(); // npcのOnInitイベント?行 |