diff options
author | ElzorFox <elzorfox@ya.ru> | 2017-03-19 15:46:52 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2017-03-19 15:46:52 +0500 |
commit | fbe3739da349afbb2e42bc6c1ce5a20b657289ac (patch) | |
tree | 32839dc042b540c01b1cd10274a464ecb2dfb635 /protocols/VKontakte/src/vk_queue.cpp | |
parent | 71a8b0d202f89ae3a53fa3978b2588e79511da1b (diff) |
VKontakte:
fix sending API requests (maximum 3 requests to API methods per second)
fix sending long and uint parameters as signed int
version bump
Diffstat (limited to 'protocols/VKontakte/src/vk_queue.cpp')
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index d23c68e995..ba844d1436 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -151,7 +151,9 @@ void CVkProto::WorkerThread(void*) break;
AsyncHttpRequest *pReq;
- bool need_sleep = false;
+ ULONG uTime[3] = { 0, 0, 0 };
+ long lWaitingTime = 0;
+
while (true) {
{
mir_cslock lck(m_csRequestsQueue);
@@ -160,15 +162,30 @@ void CVkProto::WorkerThread(void*) pReq = m_arRequestsQueue[0];
m_arRequestsQueue.remove(0);
- need_sleep = (m_arRequestsQueue.getCount() > 1) && (pReq->m_bApiReq); // more than two to not gather
+
+ ULONG utime = GetTickCount();
+ lWaitingTime = (utime - uTime[0]) > 1000 ? 0 : 1100 - (utime - uTime[0]);
+
+ if (!(pReq->m_bApiReq) || lWaitingTime < 0)
+ lWaitingTime = 0;
}
+
if (m_bTerminated)
break;
- ExecuteRequest(pReq);
- if (need_sleep) { // There can be maximum 3 requests to API methods per second from a client
- Sleep(800); // (c) https://vk.com/dev/api_requests
- debugLogA("CVkProto::WorkerThread: need sleep");
+
+ if (lWaitingTime) {
+ debugLogA("CVkProto::WorkerThread: need sleep %d msec", lWaitingTime);
+ Sleep(lWaitingTime);
+ }
+
+ if (pReq->m_bApiReq) {
+ uTime[0] = uTime[1];
+ uTime[1] = uTime[2];
+ uTime[2] = GetTickCount();
+ // There can be maximum 3 requests to API methods per second from a client
+ // see https://vk.com/dev/api_requests
}
+ ExecuteRequest(pReq);
}
}
@@ -190,7 +207,7 @@ AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const INT_PARAM ¶m) CMStringA &s = pReq->m_szParam;
if (!s.IsEmpty())
s.AppendChar('&');
- s.AppendFormat("%s=%i", param.szName, param.iValue);
+ s.AppendFormat("%s=%ld", param.szName, param.iValue);
return pReq;
}
|