Merge pull request #188 from Arkshine/feature/mysql-rw-and-default-timeout
Establish a default timeout for MySQL connectivity
This commit is contained in:
commit
6319331a33
|
@ -15,6 +15,9 @@ amxx_vault addons/amxmodx/data/vault.ini
|
||||||
; 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
|
||||||
; these only work with bin logging binaries
|
; these only work with bin logging binaries
|
||||||
|
|
|
@ -12,3 +12,4 @@ 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"
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user