DCC bouncing: Throttle the receiving side if we can't bounce the data fast enough

It could happen that ZNC was killed by the OOM killer. This was caused by
DCC bouncing receiving as fast as possible and caching everything in memory.

This throttles the receiving side via PauseRead() and UnPauseRead().


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1069 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-05-24 17:16:29 +00:00
parent d265fc85ae
commit 4fd07208ab
2 changed files with 25 additions and 1 deletions
+20
View File
@@ -9,6 +9,11 @@
#include "DCCBounce.h"
#include "User.h"
// If we buffer more than this in memory, we will throttle the receiving side
const unsigned int CDCCBounce::m_uiMaxDCCBuffer = 10 * 1024;
// If less than this is in the buffer, the receiving side continues
const unsigned int CDCCBounce::m_uiMinDCCBuffer = 2 * 1024;
void CDCCBounce::ReadLine(const CString& sData) {
CString sLine = sData;
@@ -22,11 +27,26 @@ void CDCCBounce::ReadLine(const CString& sData) {
}
void CDCCBounce::ReadData(const char* data, int len) {
size_t BufLen;
if (m_pPeer) {
m_pPeer->Write(data, len);
BufLen = m_pPeer->GetInternalWriteBuffer().length();
if (BufLen >= m_uiMaxDCCBuffer) {
DEBUG_ONLY(cout << GetSockName() << " The send buffer is over the "
"limit (" << BufLen <<"), throttling" << endl);
PauseRead();
}
}
}
void CDCCBounce::ReadPaused() {
if (!m_pPeer || m_pPeer->GetInternalWriteBuffer().length() <= m_uiMinDCCBuffer)
UnPauseRead();
}
void CDCCBounce::Timeout() {
DEBUG_ONLY(cout << GetSockName() << " == Timeout()" << endl);
CString sType = (m_bIsChat) ? "Chat" : "Xfer";
+5 -1
View File
@@ -55,6 +55,7 @@ public:
void ReadLine(const CString& sData);
virtual void ReadData(const char* data, int len);
virtual void ReadPaused();
virtual void Timeout();
virtual void ConnectionRefused();
virtual void SockError(int iErrno);
@@ -90,9 +91,12 @@ protected:
CString m_sFileName;
CUser* m_pUser;
CDCCBounce* m_pPeer;
unsigned short m_uRemotePort;
unsigned short m_uRemotePort;
bool m_bIsChat;
bool m_bIsRemote;
static const unsigned int m_uiMaxDCCBuffer;
static const unsigned int m_uiMinDCCBuffer;
};
#endif // !_DCCBOUNCE_H