Limit the maximal read buffer space that is used for every socket

CSocket caches the data read from a socket and then looks for lines in there.
If there is no line end, this buffer can grow quite large. This patch now
closes sockets if they get a huge read buffer.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1233 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-09-30 14:43:51 +00:00
parent f40b3e78d7
commit 18ce52e32d
10 changed files with 52 additions and 0 deletions

View File

@@ -103,18 +103,26 @@ CSocket::CSocket(CModule* pModule) : Csock() {
m_pModule = pModule;
m_pModule->AddSocket(this);
EnableReadLine();
SetMaxBufferThreshold(10240);
}
CSocket::CSocket(CModule* pModule, const CString& sHostname, unsigned short uPort, int iTimeout) : Csock(sHostname, uPort, iTimeout) {
m_pModule = pModule;
m_pModule->AddSocket(this);
EnableReadLine();
SetMaxBufferThreshold(10240);
}
CSocket::~CSocket() {
m_pModule->UnlinkSocket(this);
}
void CSocket::ReachedMaxBuffer() {
DEBUG_ONLY(cout << GetSockName() << " == ReachedMaxBuffer()" << endl);
PutModule("Some socket reached its max buffer limit and was closed!");
Close();
}
bool CSocket::Connect(const CString& sHostname, unsigned short uPort, bool bSSL, unsigned int uTimeout) {
CUser* pUser = m_pModule->GetUser();
CString sSockName = "MOD::C::" + m_pModule->GetModName();