Mysql: Establish a default timeout

This commit is contained in:
Arkshine 2015-01-29 13:50:13 +01:00
parent 5ca0e5617d
commit f8ec7f94a4
5 changed files with 41 additions and 20 deletions

View File

@ -1,19 +1,22 @@
; Configuration file for AMX Mod X ; Configuration file for AMX Mod X
amxx_logs addons/amxmodx/logs amxx_logs addons/amxmodx/logs
amxx_configsdir addons/amxmodx/configs amxx_configsdir addons/amxmodx/configs
amxx_datadir addons/amxmodx/data amxx_datadir addons/amxmodx/data
amxx_modules addons/amxmodx/configs/modules.ini amxx_modules addons/amxmodx/configs/modules.ini
amxx_plugins addons/amxmodx/configs/plugins.ini amxx_plugins addons/amxmodx/configs/plugins.ini
amxx_pluginsdir addons/amxmodx/plugins amxx_pluginsdir addons/amxmodx/plugins
amxx_modulesdir addons/amxmodx/modules amxx_modulesdir addons/amxmodx/modules
amxx_vault addons/amxmodx/data/vault.ini amxx_vault addons/amxmodx/data/vault.ini
; Logging mode ; Logging mode
; 0 - no logging ; 0 - no logging
; 1 - one logfile / day ; 1 - one logfile / day
; 2 - one logfile / map ; 2 - one logfile / map
; 3 - HL Logs ; 3 - HL Logs
amxx_logging 1 amxx_logging 1
; MySQL default timeout
mysql_timeout 60
; Binary logging level ; Binary logging level
; add these up to get what you want ; add these up to get what you want
@ -24,10 +27,10 @@ amxx_logging 1
; 8 - log all native params ; 8 - log all native params
; 16 - log internal function calls (only in debug mode) ; 16 - log internal function calls (only in debug mode)
; 32 - log line number accesses (only in debug mode) ; 32 - log line number accesses (only in debug mode)
bin_logging 49 bin_logging 49
; Maximum binary log size, in megs ; Maximum binary log size, in megs
max_binlog_size 20 max_binlog_size 20
; Plugin optimization flags - add these up to get what you want ; Plugin optimization flags - add these up to get what you want
; lowering these may stop crashes on very old CPUs ; lowering these may stop crashes on very old CPUs
@ -36,4 +39,4 @@ max_binlog_size 20
; 1 - float arithmetic ; 1 - float arithmetic
; 2 - float comparisons ; 2 - float comparisons
; 4 - float rounding ; 4 - float rounding
optimizer 7 optimizer 7

View File

@ -6,9 +6,10 @@
// *NOTE* amx_sql_type specifies the DEFAULT database type which admin.sma will use. // *NOTE* amx_sql_type specifies the DEFAULT database type which admin.sma will use.
amx_sql_host "127.0.0.1" amx_sql_host "127.0.0.1"
amx_sql_user "root" amx_sql_user "root"
amx_sql_pass "" amx_sql_pass ""
amx_sql_db "amx" amx_sql_db "amx"
amx_sql_table "admins" amx_sql_table "admins"
amx_sql_type "mysql" amx_sql_type "mysql"
amx_sql_timeout "60"

View File

@ -52,11 +52,22 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
return NULL; return NULL;
} }
if (do_timeout && info->max_timeout) decltype(info->max_timeout) timeout = atoi(LOCALINFO("mysql_timeout"));
if (timeout <= 0)
{ {
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&(info->max_timeout)); timeout = 60;
} }
if (do_timeout && info->max_timeout > 0)
{
timeout = info->max_timeout;
}
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&timeout);
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (const char *)&timeout);
mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&timeout);
/** Have MySQL automatically reconnect if it times out or loses connection. /** Have MySQL automatically reconnect if it times out or loses connection.
* This will prevent "MySQL server has gone away" errors after a while. * This will prevent "MySQL server has gone away" errors after a while.
*/ */

View File

@ -73,6 +73,7 @@ public plugin_init()
register_cvar("amx_sql_pass", "", FCVAR_PROTECTED) register_cvar("amx_sql_pass", "", FCVAR_PROTECTED)
register_cvar("amx_sql_db", "amx", FCVAR_PROTECTED) register_cvar("amx_sql_db", "amx", FCVAR_PROTECTED)
register_cvar("amx_sql_type", "mysql", FCVAR_PROTECTED) register_cvar("amx_sql_type", "mysql", FCVAR_PROTECTED)
register_cvar("amx_sql_timeout", "60", FCVAR_PROTECTED)
register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG) register_concmd("amx_reloadadmins", "cmdReload", ADMIN_CFG)
register_concmd("amx_addadmin", "addadminfn", ADMIN_RCON, "<playername|auth> <accessflags> [password] [authtype] - add specified player as an admin to users.ini") register_concmd("amx_addadmin", "addadminfn", ADMIN_RCON, "<playername|auth> <accessflags> [password] [authtype] - add specified player as an admin to users.ini")

View File

@ -394,6 +394,11 @@ stock Handle:SQL_MakeStdTuple(timeout = 0)
get_cvar_string("amx_sql_type", set_type, 11); get_cvar_string("amx_sql_type", set_type, 11);
get_cvar_string("amx_sql_db", db, 127); get_cvar_string("amx_sql_db", db, 127);
if (timeout <= 0)
{
timeout = get_cvar_num("amx_sql_timeout");
}
SQL_GetAffinity(get_type, 12); SQL_GetAffinity(get_type, 12);
if (!equali(get_type, set_type)) if (!equali(get_type, set_type))