From 0c160c0720746e504b5d654802171f7c0f2de718 Mon Sep 17 00:00:00 2001 From: psychon Date: Thu, 10 Sep 2009 10:45:35 +0000 Subject: [PATCH] Remove the dedicated new-client-timeout timer We used to start a dedicated timer for a new client socket that would make sure the client is disconnected if it didn't successfully log in after 60 seconds. This is now replaced by using Csocket's built-in timeout support. When a new client connects we SetTimeout(60, 0); which means that Timeout() will be called in 60 seconds, no matter what. The second argument is a bitmask which says on which events the timeout should be reset (TMO_READ, TMO_WRITE, TMO_ACCEPT, TMO_ALL). Once the client logs in successfully, CClient::AcceptLogin() now sets back the proper timeout (SetTimeout(240, TMO_READ);) which was set in Connected() before. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1622 726aef4b-f618-498e-8847-2d620e286838 --- Client.cpp | 28 ++++------------------------ Client.h | 12 +++++------- Timers.h | 20 -------------------- 3 files changed, 9 insertions(+), 51 deletions(-) diff --git a/Client.cpp b/Client.cpp index 648a1a8d..b882699f 100644 --- a/Client.cpp +++ b/Client.cpp @@ -55,9 +55,6 @@ CClient::~CClient() { m_pUser->AddBytesRead(GetBytesRead()); m_pUser->AddBytesWritten(GetBytesWritten()); } - if (m_pTimeout) { - CZNC::Get().GetManager().DelCronByAddr(m_pTimeout); - } } void CClient::ReadLine(const CString& sData) { @@ -658,11 +655,6 @@ void CAuthBase::RefuseLogin(const CString& sReason) { } void CClient::RefuseLogin(const CString& sReason) { - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } - PutStatus("Bad username and/or password."); PutClient(":irc.znc.in 464 " + GetNick() + " :" + sReason); Close(Csock::CLT_AFTERWRITE); @@ -678,10 +670,9 @@ void CClient::AcceptLogin(CUser& User) { m_sPass = ""; m_pUser = &User; - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } + // Set our proper timeout and set back our proper timeout mode + // (constructor set a different timeout and mode) + SetTimeout(240, TMO_READ); SetSockName("USR::" + m_pUser->GetUserName()); @@ -693,23 +684,12 @@ void CClient::AcceptLogin(CUser& User) { MODULECALL(OnClientLogin(), m_pUser, this, ); } -void CClient::StartLoginTimeout() { - m_pTimeout = new CClientTimeout(this); - CZNC::Get().GetManager().AddCron(m_pTimeout); -} - -void CClient::LoginTimeout() { +void CClient::Timeout() { PutClient("ERROR :Closing link [Timeout]"); - Close(Csock::CLT_AFTERWRITE); - if (m_pTimeout) { - m_pTimeout->Stop(); - m_pTimeout = NULL; - } } void CClient::Connected() { DEBUG(GetSockName() << " == Connected();"); - SetTimeout(240, TMO_READ); // Now that we are connected, let nature take its course } void CClient::ConnectionRefused() { diff --git a/Client.h b/Client.h index 0e0e880d..7e5c46f6 100644 --- a/Client.h +++ b/Client.h @@ -18,7 +18,6 @@ class CZNC; class CUser; class CIRCSock; class CClient; -class CClientTimeout; // !Forward Declarations class CAuthBase { @@ -70,9 +69,8 @@ protected: class CClient : public CZNCSock { public: - CClient(const CString& sHostname, unsigned short uPort, int iTimeout = 60) : CZNCSock(sHostname, uPort, iTimeout) { + CClient(const CString& sHostname, unsigned short uPort) : CZNCSock(sHostname, uPort) { m_pUser = NULL; - m_pTimeout = NULL; m_pIRCSock = NULL; m_bGotPass = false; m_bGotNick = false; @@ -84,7 +82,9 @@ public: // a little more gentle ;) SetMaxBufferThreshold(1024); - StartLoginTimeout(); + // Disable all timeout types. The socket will now time out in 60 + // seconds, no matter what. AcceptLogin() fixes this up. + SetTimeout(60, 0); SetNick("unknown-nick"); } @@ -93,8 +93,6 @@ public: void AcceptLogin(CUser& User); void RefuseLogin(const CString& sReason); - void StartLoginTimeout(); - void LoginTimeout(); CString GetNick(bool bAllowIRCNick = true) const; CString GetNickMask() const; @@ -121,6 +119,7 @@ public: void HelpUser(); void AuthUser(); virtual void Connected(); + virtual void Timeout(); virtual void Disconnected(); virtual void ConnectionRefused(); virtual void ReachedMaxBuffer(); @@ -141,7 +140,6 @@ protected: CString m_sUser; CIRCSock* m_pIRCSock; CSmartPtr m_spAuth; - CClientTimeout* m_pTimeout; }; #endif // !_CLIENT_H diff --git a/Timers.h b/Timers.h index db00c34a..429fa15e 100644 --- a/Timers.h +++ b/Timers.h @@ -64,24 +64,4 @@ protected: CUser* m_pUser; }; -class CClientTimeout : public CCron { -public: - CClientTimeout(CClient* pClient) : CCron() { - m_pClient = pClient; - SetName("CClientTimeout::UNKNOWN"); - StartMaxCycles(60, 1); - } - virtual ~CClientTimeout() {} - -protected: - virtual void RunJob() { - if (m_pClient) { - m_pClient->LoginTimeout(); - m_pClient = NULL; - } - } - - CClient* m_pClient; -}; - #endif // !_TIMERS_H