From: <ps...@us...> - 2008-12-06 19:56:54
|
Revision: 1283 http://znc.svn.sourceforge.net/znc/?rev=1283&view=rev Author: psychon Date: 2008-12-06 19:56:38 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Add traffic tracking support to CSocket Now every module that uses CSocket automatically gets its generated traffic counted. Those which use Csock directly should be shot and burried anyway ;) This adds CModule::IsGlobal(). Modified Paths: -------------- trunk/Modules.cpp trunk/Modules.h trunk/modules/schat.cpp trunk/modules/webadmin.cpp Modified: trunk/Modules.cpp =================================================================== --- trunk/Modules.cpp 2008-12-06 16:13:37 UTC (rev 1282) +++ trunk/Modules.cpp 2008-12-06 19:56:38 UTC (rev 1283) @@ -114,7 +114,17 @@ } CSocket::~CSocket() { + CUser *pUser = m_pModule->GetUser(); + m_pModule->UnlinkSocket(this); + + if (!m_pModule->IsGlobal() && pUser) { + pUser->AddBytesWritten(GetBytesWritten()); + pUser->AddBytesRead(GetBytesRead()); + } else { + CZNC::Get().AddBytesWritten(GetBytesWritten()); + CZNC::Get().AddBytesRead(GetBytesRead()); + } } void CSocket::ReachedMaxBuffer() { @@ -181,6 +191,7 @@ CModule::CModule(void* pDLL, CUser* pUser, const CString& sModName, const CString& sDataDir) { m_bFake = false; + m_bGlobal = false; m_pDLL = pDLL; m_pManager = &(CZNC::Get().GetManager());; m_pUser = pUser; @@ -779,6 +790,7 @@ } pModule->SetDescription(GetDesc()); + pModule->SetGlobal(bIsGlobal); push_back(pModule); bool bLoaded; Modified: trunk/Modules.h =================================================================== --- trunk/Modules.h 2008-12-06 16:13:37 UTC (rev 1282) +++ trunk/Modules.h 2008-12-06 19:56:38 UTC (rev 1283) @@ -329,12 +329,14 @@ // Setters void SetFake(bool b) { m_bFake = b; } + void SetGlobal(bool b) { m_bGlobal = b; } void SetDescription(const CString& s) { m_sDescription = s; } void SetArgs(const CString& s) { m_sArgs = s; } // !Setters // Getters bool IsFake() const { return m_bFake; } + bool IsGlobal() const { return m_bGlobal; } const CString& GetDescription() const { return m_sDescription; } const CString& GetArgs() const { return m_sArgs; } CUser* GetUser() { return m_pUser; } @@ -344,6 +346,7 @@ protected: bool m_bFake; + bool m_bGlobal; CString m_sDescription; vector<CTimer*> m_vTimers; vector<CSocket*> m_vSockets; Modified: trunk/modules/schat.cpp =================================================================== --- trunk/modules/schat.cpp 2008-12-06 16:13:37 UTC (rev 1282) +++ trunk/modules/schat.cpp 2008-12-06 19:56:38 UTC (rev 1283) @@ -58,8 +58,6 @@ EnableReadLine(); } - ~CSChatSock(); - virtual Csock *GetSockObj(const CS_STRING & sHostname, u_short iPort) { CSChatSock *p = new CSChatSock(sHostname, iPort); @@ -442,12 +440,6 @@ //////////////////// methods //////////////// -CSChatSock::~CSChatSock() -{ - m_pModule->GetUser()->AddBytesRead(GetBytesRead()); - m_pModule->GetUser()->AddBytesWritten(GetBytesWritten()); -} - void CSChatSock::ReadLine(const CS_STRING & sLine) { if (m_pModule) { Modified: trunk/modules/webadmin.cpp =================================================================== --- trunk/modules/webadmin.cpp 2008-12-06 16:13:37 UTC (rev 1282) +++ trunk/modules/webadmin.cpp 2008-12-06 19:56:38 UTC (rev 1283) @@ -322,9 +322,6 @@ CWebAdminAuth* pAuth = (CWebAdminAuth*) &(*m_spAuth); pAuth->SetWebAdminSock(NULL); } - - CZNC::Get().AddBytesRead(GetBytesRead()); - CZNC::Get().AddBytesWritten(GetBytesWritten()); } bool CWebAdminSock::OnPageRequest(const CString& sURI, CString& sPageRet) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |