mirror of
https://github.com/znc/znc.git
synced 2026-08-06 17:03:14 +02:00
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
This commit is contained in:
+4
-24
@@ -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() {
|
||||
|
||||
@@ -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<CAuthBase> m_spAuth;
|
||||
CClientTimeout* m_pTimeout;
|
||||
};
|
||||
|
||||
#endif // !_CLIENT_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
|
||||
|
||||
Reference in New Issue
Block a user