diff options
author | George Hazan <ghazan@miranda.im> | 2021-06-12 18:32:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-06-12 18:32:37 +0300 |
commit | b1994b49c2eefeba8472eb46418b961422640f18 (patch) | |
tree | f1ca6a4918d759796aa198bd72b38770346a4c0d | |
parent | 8752dc000c86f3115fe85c1d2ee08a21862b943e (diff) |
minus another stupid thread in Jabber
-rw-r--r-- | protocols/JabberG/src/jabber_iq.cpp | 65 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq.h | 10 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.cpp | 3 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.h | 2 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_thread.cpp | 6 |
5 files changed, 16 insertions, 70 deletions
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<CJabberIqInfo> m_arIqs;
OBJLIST<CJabberIqPermanentInfo> 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<CJabberProto>, 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();
}
/////////////////////////////////////////////////////////////////////////////////////////
|