diff options
author | ElzorFox <elzorfox@ya.ru> | 2019-02-19 21:25:54 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2019-02-19 21:27:33 +0500 |
commit | c26a815104626be419eeb35669a1824b371839da (patch) | |
tree | 5669dfbbdc74ef18976f2affd1a79cf604a2091b /protocols/VKontakte | |
parent | 842305935dae96495bb70f5976489e4e79a2491d (diff) |
VKontakte: more correct 7d75ffb
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_pollserver.cpp | 20 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 27 |
3 files changed, 38 insertions, 11 deletions
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp index c257bdf08c..80a6b91f8b 100644 --- a/protocols/VKontakte/src/vk_pollserver.cpp +++ b/protocols/VKontakte/src/vk_pollserver.cpp @@ -259,13 +259,20 @@ int CVkProto::PollServer() req.flags = VK_NODUMPHEADERS | NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_SSL;
req.timeout = 30000;
req.nlc = m_pollingConn;
-
+ time_t tLocalPoolThreadTimer;
{
mir_cslock lck(m_csPoolThreadTimer);
- m_tPoolThreadTimer = time(0);
+ tLocalPoolThreadTimer = m_tPoolThreadTimer = time(0);
}
while ((reply = Netlib_HttpTransaction(m_hNetlibUser, &req)) == nullptr) {
+ {
+ mir_cslock lck(m_csPoolThreadTimer);
+ if (m_tPoolThreadTimer != tLocalPoolThreadTimer) {
+ debugLogA("CVkProto::PollServer is living dead => return");
+ return -2;
+ }
+ }
debugLogA("CVkProto::PollServer is dead");
ClosePollingConnection();
if (iPollConnRetry && !m_bTerminated) {
@@ -319,9 +326,14 @@ void CVkProto::PollingThread(void*) {
debugLogA("CVkProto::PollingThread: entering");
- while (!m_bTerminated)
- if (PollServer() == -1 || !m_hPollingThread)
+ while (!m_bTerminated) {
+ int iRetVal = PollServer();
+ if (iRetVal == -2)
+ return;
+
+ if (iRetVal == -1 || !m_hPollingThread)
break;
+ }
ClosePollingConnection();
debugLogA("CVkProto::PollingThread: leaving");
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 876d365853..4d28187caa 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -367,7 +367,7 @@ private: bool IsMessageExist(UINT iMsgId, VKMesType vkType = vkALL);
void InitQueue();
void UninitQueue();
- void ExecuteRequest(AsyncHttpRequest*);
+ bool ExecuteRequest(AsyncHttpRequest*);
void __cdecl WorkerThread(void*);
AsyncHttpRequest* Push(MHttpRequest *pReq, int iTimeout = 10000);
bool RunCaptchaForm(LPCSTR szUrl, CMStringA&);
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index bea360df75..5cbf3a5d08 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -32,7 +32,7 @@ void CVkProto::UninitQueue() /////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq)
+bool CVkProto::ExecuteRequest(AsyncHttpRequest *pReq)
{
CMStringA str;
do {
@@ -57,8 +57,24 @@ void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq) if (m_bTerminated)
break;
+ time_t tLocalWorkThreadTimer = 0;
+ {
+ mir_cslock lck(m_csWorkThreadTimer);
+ tLocalWorkThreadTimer = m_tWorkThreadTimer = time(0);
+ }
+
debugLogA("CVkProto::ExecuteRequest \n====\n%s\n====\n", pReq->szUrl);
NETLIBHTTPREQUEST *reply = Netlib_HttpTransaction(m_hNetlibUser, pReq);
+
+ {
+ mir_cslock lck(m_csWorkThreadTimer);
+ if (tLocalWorkThreadTimer != m_tWorkThreadTimer) {
+ debugLogA("CVkProto::WorkerThread is living Dead => return");
+ delete pReq;
+ return false;
+ }
+ }
+
if (reply != nullptr) {
if (pReq->m_pFunc != nullptr)
(this->*(pReq->m_pFunc))(reply, pReq); // may be set pReq->bNeedsRestart
@@ -89,6 +105,7 @@ void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq) } while (pReq->bNeedsRestart && !m_bTerminated);
delete pReq;
+ return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -191,11 +208,9 @@ void CVkProto::WorkerThread(void*) // There can be maximum 3 requests to API methods per second from a client
// see https://vk.com/dev/api_requests
}
- {
- mir_cslock lck(m_csWorkThreadTimer);
- m_tWorkThreadTimer = time(0);
- }
- ExecuteRequest(pReq);
+
+ if (!ExecuteRequest(pReq))
+ return;
}
}
|