From 3244c819204245aefe2d177914ca625ee6a0fd80 Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 20 Jan 2008 16:20:19 +0000 Subject: [PATCH] Make CListener clean up after itself (Remove the listing socket when destroyed) git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@932 726aef4b-f618-498e-8847-2d620e286838 --- znc.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/znc.h b/znc.h index 62c0970d..c9bccfc7 100644 --- a/znc.h +++ b/znc.h @@ -212,9 +212,13 @@ public: m_sBindHost = sBindHost; m_bSSL = bSSL; m_bIPV6 = bIPV6; + m_pClient = NULL; } - virtual ~CListener() {} + virtual ~CListener() { + if (m_pClient) + CZNC::Get().GetManager().DelSockByAddr(m_pClient); + } // Setters void SetSSL(bool b) { m_bSSL = b; } @@ -230,22 +234,22 @@ public: const CString& GetBindHost() const { return m_sBindHost; } // !Getters - bool Listen() const { - if (!m_uPort) { + bool Listen() { + if (!m_uPort || m_pClient) { return false; } - CClient* pClient = new CClient; + m_pClient = new CClient; bool bSSL = false; #ifdef HAVE_LIBSSL if (IsSSL()) { bSSL = true; - pClient->SetPemLocation(CZNC::Get().GetPemLocation()); + m_pClient->SetPemLocation(CZNC::Get().GetPemLocation()); } #endif - return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, pClient, 0, m_bIPV6); + return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, m_pClient, 0, m_bIPV6); } private: protected: @@ -253,6 +257,7 @@ protected: bool m_bIPV6; unsigned short m_uPort; CString m_sBindHost; + CClient* m_pClient; }; #endif // !_ZNC_H