From 9b23ee60b8e3c0e284609efda4f01e28567d9780 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 7 May 2013 20:59:38 +0200 Subject: [PATCH] Debug: Only print queued lines if they are really just queued Previously, every line that was forwarded to the IRCd was printed twice in debug mode. Once when it got added to the send queue and a second time when it was actually sent. However, most of the time this queue is empty and thus the two events happened at approximately the same time. Thus, this patch now changes the debug output. Lines are only printed extra if they really have to wait in the queue for a while before they can be sent out. This has the positive effect of making the debug output more readable, because it is shorter and less repetitive and it makes it more obvious when znc actively throttles the traffic that is sent out. Signed-off-by: Uli Schlachter --- src/IRCSock.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index 9a6ae1fd..9f92c399 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -1016,19 +1016,26 @@ bool CIRCSock::OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage) { } void CIRCSock::PutIRC(const CString& sLine) { - DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued)"); + // Only print if the line won't get sent immediately (same condition as in TrySend()!) + if (m_bFloodProtection && m_iSendsAllowed <= 0) { + DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued)"); + } m_vsSendQueue.push_back(sLine); TrySend(); } void CIRCSock::PutIRCQuick(const CString& sLine) { - DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued to front)"); + // Only print if the line won't get sent immediately (same condition as in TrySend()!) + if (m_bFloodProtection && m_iSendsAllowed <= 0) { + DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued to front)"); + } m_vsSendQueue.push_front(sLine); TrySend(); } void CIRCSock::TrySend() { - while (!m_vsSendQueue.empty() && (m_iSendsAllowed > 0 || !m_bFloodProtection)) { + // This condition must be the same as in PutIRC() and PutIRCQuick()! + while (!m_vsSendQueue.empty() && (!m_bFloodProtection || m_iSendsAllowed > 0)) { m_iSendsAllowed--; DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << m_vsSendQueue.front() << "]"); Write(m_vsSendQueue.front() + "\r\n");