mirror of
https://github.com/znc/znc.git
synced 2026-08-06 08:52:57 +02:00
Less magic numbers for timeout settings
Currently the connection timeout handling of znc uses three magic numbers, each of which is at least repeated in two unrelated places. This commits defines the numbers in CIRCNetwork and makes the other places just use this number. This also renames PING_TIMEOUT to PING_FREQUENCY because I feel that describes this constant better. I am not really happy about the name NO_TRAFFIC_TIMEOUT that is used for the real timeout, but I couldn't think of a better name. PING_TIMEOUT isn't good because that sounds like the time between sending a PING and the resulting timeout. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -44,7 +44,14 @@ public:
|
||||
~CIRCNetwork();
|
||||
|
||||
enum {
|
||||
PING_TIMEOUT = 270
|
||||
/** How long must an IRC connection be idle before ZNC sends a ping */
|
||||
PING_FREQUENCY = 270,
|
||||
/** Time between checks if PINGs need to be sent */
|
||||
PING_SLACK = 30,
|
||||
/** Timeout after which IRC connections are closed. Must
|
||||
* obviously be smaller than PING_FREQUENCY + PING_SLACK.
|
||||
*/
|
||||
NO_TRAFFIC_TIMEOUT = 540
|
||||
};
|
||||
|
||||
void Clone(const CIRCNetwork& Network, bool bCloneName = true);
|
||||
|
||||
+1
-1
@@ -671,7 +671,7 @@ void CClient::AcceptLogin(CUser& User) {
|
||||
|
||||
// Set our proper timeout and set back our proper timeout mode
|
||||
// (constructor set a different timeout and mode)
|
||||
SetTimeout(540, TMO_READ);
|
||||
SetTimeout(CIRCNetwork::NO_TRAFFIC_TIMEOUT, TMO_READ);
|
||||
|
||||
SetSockName("USR::" + m_pUser->GetUserName());
|
||||
SetEncoding(m_pUser->GetClientEncoding());
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ public:
|
||||
CIRCNetworkPingTimer(CIRCNetwork *pNetwork) : CCron() {
|
||||
m_pNetwork = pNetwork;
|
||||
SetName("CIRCNetworkPingTimer::" + m_pNetwork->GetUser()->GetUserName() + "::" + m_pNetwork->GetName());
|
||||
Start(30);
|
||||
Start(CIRCNetwork::PING_SLACK);
|
||||
}
|
||||
|
||||
virtual ~CIRCNetworkPingTimer() {}
|
||||
@@ -39,7 +39,7 @@ protected:
|
||||
virtual void RunJob() {
|
||||
CIRCSock* pIRCSock = m_pNetwork->GetIRCSock();
|
||||
|
||||
if (pIRCSock && pIRCSock->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_TIMEOUT) {
|
||||
if (pIRCSock && pIRCSock->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_FREQUENCY) {
|
||||
pIRCSock->PutIRC("PING :ZNC");
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ protected:
|
||||
for (size_t b = 0; b < vClients.size(); b++) {
|
||||
CClient* pClient = vClients[b];
|
||||
|
||||
if (pClient->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_TIMEOUT) {
|
||||
if (pClient->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_FREQUENCY) {
|
||||
pClient->PutClient("PING :ZNC");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
}
|
||||
|
||||
m_pNetwork->SetIRCServer(sServer);
|
||||
SetTimeout(540, TMO_READ); // Now that we are connected, let nature take its course
|
||||
SetTimeout(CIRCNetwork::NO_TRAFFIC_TIMEOUT, TMO_READ); // Now that we are connected, let nature take its course
|
||||
PutIRC("WHO " + sNick);
|
||||
|
||||
m_bAuthed = true;
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ public:
|
||||
CUserTimer(CUser* pUser) : CCron() {
|
||||
m_pUser = pUser;
|
||||
SetName("CUserTimer::" + m_pUser->GetUserName());
|
||||
Start(30);
|
||||
Start(CIRCNetwork::PING_SLACK);
|
||||
}
|
||||
virtual ~CUserTimer() {}
|
||||
|
||||
@@ -40,7 +40,7 @@ protected:
|
||||
for (size_t c = 0; c < vUserClients.size(); ++c) {
|
||||
CClient* pUserClient = vUserClients[c];
|
||||
|
||||
if (pUserClient->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_TIMEOUT) {
|
||||
if (pUserClient->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_FREQUENCY) {
|
||||
pUserClient->PutClient("PING :ZNC");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user