diff --git a/DCCBounce.cpp b/DCCBounce.cpp index 644211c9..e6a54ac8 100644 --- a/DCCBounce.cpp +++ b/DCCBounce.cpp @@ -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"; diff --git a/DCCBounce.h b/DCCBounce.h index b949c315..d9237b9a 100644 --- a/DCCBounce.h +++ b/DCCBounce.h @@ -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