summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2015-03-21 16:20:52 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2015-03-21 16:20:52 +0000
commit1b05ca00694530f1ec25fae6f7bf850895748b30 (patch)
treec4f5ceeb39334423a108ae60f189fa5fbd308736 /protocols/VKontakte/src
parent7f657fce5090d089d0600d815a6db93050562f12 (diff)
VKontakte:
m_arRequestsQueue as queue with priority set high priority for sending and receiving messages version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@12471 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r--protocols/VKontakte/src/misc.cpp6
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp4
-rw-r--r--protocols/VKontakte/src/vk_files.cpp2
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp8
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp2
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp11
-rw-r--r--protocols/VKontakte/src/vk_proto.h6
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp2
9 files changed, 29 insertions, 14 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 1be32e9de0..043c92acaa 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -156,9 +156,11 @@ AsyncHttpRequest::AsyncHttpRequest()
bIsMainConn = false;
m_pFunc = NULL;
bExpUrlEncode = false;
+ m_time = time(NULL);
+ m_priority = rpLow;
}
-AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc)
+AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc, RequestPriority rpPriority)
{
cbSize = sizeof(NETLIBHTTPREQUEST);
m_bApiReq = true;
@@ -186,6 +188,8 @@ AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url
pUserInfo = NULL;
m_iRetry = MAX_RETRIES;
bNeedsRestart = false;
+ m_time = time(NULL);
+ m_priority = rpPriority;
}
AsyncHttpRequest::~AsyncHttpRequest()
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index 3f543d71c8..b153785e9c 100644
--- a/protocols/VKontakte/src/version.h
+++ b/protocols/VKontakte/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 51
+#define __BUILD_NUM 52
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 327f07df55..0988fafa5d 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -374,7 +374,7 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam)
TCHAR *buf = NEWTSTR_ALLOCA(gch->ptszText);
rtrimt(buf);
UnEscapeChatTags(buf);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg)
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg, AsyncHttpRequest::rpHigh)
<< INT_PARAM("chat_id", cc->m_chatid)
<< CHAR_PARAM("message", mir_utf8encodeT(buf))
<< VER_API;
@@ -515,7 +515,7 @@ INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM)
if (chat_id == -1)
return 1;
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg)
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg, AsyncHttpRequest::rpHigh)
<< INT_PARAM("chat_id", chat_id)
<< TCHAR_PARAM("message", TranslateT("I'm back"))
<< VER_API;
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp
index 51ac03888c..5758f2b429 100644
--- a/protocols/VKontakte/src/vk_files.cpp
+++ b/protocols/VKontakte/src/vk_files.cpp
@@ -368,7 +368,7 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
return;
}
- AsyncHttpRequest *pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage)
+ AsyncHttpRequest *pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh)
<< INT_PARAM("user_id", userID)
<< TCHAR_PARAM("message", fup->Desc)
<< TCHAR_PARAM("attachment", Attachment.GetBuffer())
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 80002277ac..57f25817af 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -60,7 +60,7 @@ int CVkProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
ptrA retMsg(GetStickerId(szMsg, StickerId));
ULONG msgId = ::InterlockedIncrement(&m_msgId);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage)
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh)
<< INT_PARAM("user_id", userID)
<< VER_API;
@@ -142,7 +142,7 @@ void CVkProto::MarkMessagesRead(const CMStringA &mids)
if (mids.IsEmpty())
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
<< CHAR_PARAM("message_ids", mids)
<< VER_API);
}
@@ -156,7 +156,7 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact)
if (userID == -1 || userID == VK_FEED_USER)
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
<< INT_PARAM("peer_id", userID)
<< VER_API);
}
@@ -169,7 +169,7 @@ void CVkProto::RetrieveMessagesByIds(const CMStringA &mids)
if (mids.IsEmpty())
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getById.json", true, &CVkProto::OnReceiveMessages)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getById.json", true, &CVkProto::OnReceiveMessages, AsyncHttpRequest::rpHigh)
<< CHAR_PARAM("message_ids", mids)
<< VER_API);
}
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp
index e4ea16302f..92c5d2d0d7 100644
--- a/protocols/VKontakte/src/vk_pollserver.cpp
+++ b/protocols/VKontakte/src/vk_pollserver.cpp
@@ -22,7 +22,7 @@ void CVkProto::RetrievePollingInfo()
debugLogA("CVkProto::RetrievePollingInfo");
if (!IsOnline())
return;
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo, AsyncHttpRequest::rpHigh)
<< INT_PARAM("use_ssl", 1)
<< VER_API);
}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index 16a3fc1c64..a3dc5f01c8 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -22,12 +22,19 @@ static int sttCompareProtocols(const CVkProto *p1, const CVkProto *p2)
return mir_tstrcmp(p1->m_tszUserName, p2->m_tszUserName);
}
+static int sttCompareAsyncHttpRequest(const AsyncHttpRequest *p1, const AsyncHttpRequest *p2)
+{
+ if (p1->m_priority == p2->m_priority)
+ return (int)p1->m_time - (int)p2->m_time;
+ return (int)p2->m_priority - (int)p1->m_priority;
+}
+
LIST<CVkProto> vk_Instances(1, sttCompareProtocols);
static COLORREF sttColors[] = { 0, 1, 2, 3, 4, 5, 6 };
CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
PROTO<CVkProto>(szModuleName, ptszUserName),
- m_arRequestsQueue(10),
+ m_arRequestsQueue(10, sttCompareAsyncHttpRequest),
m_sendIds(3, PtrKeySortT),
m_incIds(3, PtrKeySortT),
m_cookies(5),
@@ -595,7 +602,7 @@ int CVkProto::UserIsTyping(MCONTACT hContact, int type)
if (m_iMarkMessageReadOn == markOnTyping)
MarkMessagesRead(hContact);
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.setActivity.json", true, &CVkProto::OnReceiveSmth)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.setActivity.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
<< INT_PARAM("user_id", userID)
<< CHAR_PARAM("type", "typing")
<< VER_API);
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 63647070a7..17c922a266 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -41,8 +41,10 @@ typedef void (CVkProto::*VK_REQUEST_HANDLER)(NETLIBHTTPREQUEST*, struct AsyncHtt
struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
{
+ enum RequestPriority { rpLow, rpMedium, rpHigh };
+
AsyncHttpRequest();
- AsyncHttpRequest(CVkProto*, int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc);
+ AsyncHttpRequest(CVkProto*, int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, RequestPriority rpPriority = rpMedium);
~AsyncHttpRequest();
void AddHeader(LPCSTR, LPCSTR);
@@ -53,6 +55,8 @@ struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
VK_REQUEST_HANDLER m_pFunc;
void *pUserInfo;
int m_iRetry;
+ RequestPriority m_priority;
+ time_t m_time;
bool m_bApiReq;
bool bExpUrlEncode;
bool bNeedsRestart, bIsMainConn;
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index cd02bc11e1..977f00bea3 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -199,7 +199,7 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
void CVkProto::RetrieveMyInfo()
{
debugLogA("CVkProto::RetrieveMyInfo");
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnReceiveMyInfo)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnReceiveMyInfo,AsyncHttpRequest::rpHigh)
<< VER_API);
}