From 50b57be5af2e232ba1b02ea145af54db858d9d99 Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 24 Dec 2010 22:06:13 +0000 Subject: [PATCH] listsockets: Ignore dereferenced sockets When someone connects to ZNC, this connection is first handled by an instance of CIncomingConnection. Once we determined if this is a HTTP or an IRC connection, the connection is handed of to the appropriate class. The CIncomingConnection instance that was used first will still linger around for the next event loop iteration and then be destroyed. Since this socket isn't a "real" connection anymore (another instance of Csock took over for this one), listsockets should ignore all sockets in state CLT_DEREFERENCE. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2213 726aef4b-f618-498e-8847-2d620e286838 --- modules/extra/listsockets.cpp | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/extra/listsockets.cpp b/modules/extra/listsockets.cpp index e7c534d6..697612db 100644 --- a/modules/extra/listsockets.cpp +++ b/modules/extra/listsockets.cpp @@ -72,21 +72,34 @@ public: return true; } + std::priority_queue GetSockets() { + CSockManager& m = CZNC::Get().GetManager(); + std::priority_queue ret; + + for (unsigned int a = 0; a < m.size(); a++) { + Csock* pSock = m[a]; + // These sockets went through SwapSockByAddr. That means + // another socket took over the connection from this + // socket. So ignore this to avoid listing the + // connection twice. + if (pSock->GetCloseType() == Csock::CLT_DEREFERENCE) + continue; + ret.push(pSock); + } + + return ret; + } + virtual bool WebRequiresAdmin() { return true; } virtual CString GetWebMenuTitle() { return "List sockets"; } virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { if (sPageName.empty() || sPageName == "index") { - CSockManager& m = CZNC::Get().GetManager(); - if (!m.size()) { + if (CZNC::Get().GetManager().empty()) { return false; } - std::priority_queue socks; - - for (unsigned int a = 0; a < m.size(); a++) { - socks.push(m[a]); - } + std::priority_queue socks = GetSockets(); while (!socks.empty()) { Csock* pSocket = socks.top().GetSock(); @@ -187,17 +200,12 @@ public: } void ShowSocks(bool bShowHosts) { - CSockManager& m = CZNC::Get().GetManager(); - if (!m.size()) { + if (CZNC::Get().GetManager().empty()) { PutStatus("You have no open sockets."); return; } - std::priority_queue socks; - - for (unsigned int a = 0; a < m.size(); a++) { - socks.push(m[a]); - } + std::priority_queue socks = GetSockets(); CTable Table; Table.AddColumn("Name");