From b1994b49c2eefeba8472eb46418b961422640f18 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 12 Jun 2021 18:32:37 +0300 Subject: minus another stupid thread in Jabber --- protocols/JabberG/src/jabber_iq.cpp | 65 ++++----------------------------- protocols/JabberG/src/jabber_iq.h | 10 +---- protocols/JabberG/src/jabber_proto.cpp | 3 -- protocols/JabberG/src/jabber_proto.h | 2 - protocols/JabberG/src/jabber_thread.cpp | 6 +++ 5 files changed, 16 insertions(+), 70 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index 7b82b374a7..77c71e282c 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -44,13 +44,10 @@ static int ComparePermanent(const CJabberIqPermanentInfo *p1, const CJabberIqPer // CJabberIqManager class CJabberIqManager::CJabberIqManager(CJabberProto *proto) : + ppro(proto), m_arIqs(10, CompareIqs), - m_arHandlers(10, ComparePermanent), - m_bExpirerThreadShutdownRequest(false) + m_arHandlers(10, ComparePermanent) { - m_dwLastUsedHandle = 0; - m_hExpirerThread = nullptr; - ppro = proto; } CJabberIqManager::~CJabberIqManager() @@ -58,30 +55,6 @@ CJabberIqManager::~CJabberIqManager() ExpireAll(); } -bool CJabberIqManager::Start() -{ - if (m_hExpirerThread || m_bExpirerThreadShutdownRequest) - return false; - - m_hExpirerThread = ppro->ForkThreadEx(&CJabberProto::ExpirerThread, this, nullptr); - if (!m_hExpirerThread) - return false; - - return true; -} - -void CJabberIqManager::Shutdown() -{ - if (m_bExpirerThreadShutdownRequest || !m_hExpirerThread) - return; - - m_bExpirerThreadShutdownRequest = true; - - WaitForSingleObject(m_hExpirerThread, INFINITE); - CloseHandle(m_hExpirerThread); - m_hExpirerThread = nullptr; -} - void CJabberIqManager::FillPermanentHandlers() { // version requests (XEP-0092) @@ -133,34 +106,6 @@ void CJabberIqManager::FillPermanentHandlers() AddPermanentHandler(&CJabberProto::FtHandleCidRequest, JABBER_IQ_TYPE_GET, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_TO | JABBER_IQ_PARSE_ID_STR | JABBER_IQ_PARSE_CHILD_TAG_NODE, JABBER_FEAT_BITS, FALSE, "data"); } -void __cdecl CJabberProto::ExpirerThread(void* pParam) -{ - Thread_SetName("Jabber: ExpirerThread"); - CJabberIqManager *pManager = (CJabberIqManager *)pParam; - pManager->ExpirerThread(); -} - -void CJabberIqManager::ExpirerThread() -{ - while (!m_bExpirerThreadShutdownRequest) { - CJabberIqInfo *pInfo = DetachExpired(); - if (!pInfo) { - for (int i = 0; !m_bExpirerThreadShutdownRequest && (i < 10); i++) - Sleep(50); - - // -1 thread :) - ppro->m_adhocManager.ExpireSessions(); - continue; - } - ExpireInfo(pInfo); - } - - if (!m_bExpirerThreadShutdownRequest) { - CloseHandle(m_hExpirerThread); - m_hExpirerThread = nullptr; - } -} - void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo) { if (!pInfo) @@ -179,6 +124,12 @@ void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo) delete pInfo; } +void CJabberIqManager::CheckExpired() +{ + while (auto *pInfo = DetachExpired()) + ExpireInfo(pInfo); +} + void CJabberIqManager::ExpireIq(int nIqId) { while (CJabberIqInfo *pInfo = DetachInfo(nIqId)) diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h index f260d4256e..fcc4a042da 100644 --- a/protocols/JabberG/src/jabber_iq.h +++ b/protocols/JabberG/src/jabber_iq.h @@ -141,10 +141,7 @@ protected: CJabberProto *ppro; mir_cs m_cs; - DWORD m_dwLastUsedHandle; - - HANDLE m_hExpirerThread; - BOOL m_bExpirerThreadShutdownRequest; + DWORD m_dwLastUsedHandle = 0; LIST m_arIqs; OBJLIST m_arHandlers; @@ -160,9 +157,6 @@ public: CJabberIqManager(CJabberProto *proto); ~CJabberIqManager(); - bool Start(); - void Shutdown(); - // fucking params, maybe just return CJabberIqRequestInfo pointer ? CJabberIqInfo* AddHandler(JABBER_IQ_HANDLER pHandler, int nIqType, const char *szReceiver, void *pUserData, int iPriority); CJabberIqPermanentInfo* AddPermanentHandler(JABBER_PERMANENT_IQ_HANDLER pHandler, int nIqTypes, DWORD dwParamsToParse, const char *szXmlns, BOOL bAllowPartialNs, const char *szTag, void *pUserData = nullptr, IQ_USER_DATA_FREE_FUNC pUserDataFree = nullptr, int iPriority = JH_PRIORITY_DEFAULT); @@ -174,8 +168,8 @@ public: bool HandleIq(int nIqId, const TiXmlElement *pNode); bool HandleIqPermanent(const TiXmlElement *pNode); + void CheckExpired(void); void ExpireIq(int nIqId); - void ExpirerThread(void); bool ExpireByUserData(void *pUserData); void ExpireAll(); void FillPermanentHandlers(); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index b3350947f0..35725cea26 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -283,8 +283,6 @@ void CJabberProto::OnModulesLoaded() XStatusInit(); m_pepServices.InitGui(); - m_iqManager.Start(); - InitInfoFrame(); StatusIconData sid = {}; @@ -350,7 +348,6 @@ void CJabberProto::OnShutdown() MucShutdown(); m_iqManager.ExpireAll(); - m_iqManager.Shutdown(); ConsoleUninit(); Srmm_RemoveIcon(m_szModuleName, 0); diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 762660e459..46b388d267 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -539,8 +539,6 @@ struct CJabberProto : public PROTO, public IJabberInterface return m_iqManager.AddHandler(pHandler, nIqType, szReceiver, pUserData, iPriority); } - void __cdecl ExpirerThread(void*); - void OnIqResultBind(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); void OnIqResultDiscoBookmarks(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); void OnIqResultEntityTime(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 5b6877dc97..d8a7614df6 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -155,6 +155,12 @@ void CJabberProto::CheckKeepAlive() if (m_bEnableStreamMgmt) m_StrmMgmt.RequestAck(); + + // check expired iq requests + m_iqManager.CheckExpired(); + + // check expired ad-hoc requests + m_adhocManager.ExpireSessions(); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3