Permalink
Browse files

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 <psychon@znc.in>
  • Loading branch information...
1 parent f73d766 commit 9b23ee60b8e3c0e284609efda4f01e28567d9780 @psychon psychon committed May 7, 2013
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/IRCSock.cpp
View
@@ -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");

0 comments on commit 9b23ee6

Please sign in to comment.