summaryrefslogtreecommitdiff
path: root/protocols/VKontakte
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-10-13 09:15:49 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-10-13 09:15:49 +0000
commitb245e6b6c7111c34302d73ccef60ebef8f248ce4 (patch)
tree1ac732c7290539d2f85efba6e904f0abb11a5fa0 /protocols/VKontakte
parent06976a2f446e21dd5189bdb253ec4f80602738f8 (diff)
- fixed multiple working thread creation;
- set contacts to offline upon disconnect git-svn-id: http://svn.miranda-ng.org/main/trunk@6479 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp3
-rw-r--r--protocols/VKontakte/src/vk_proto.h1
-rw-r--r--protocols/VKontakte/src/vk_queue.cpp4
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp14
4 files changed, 17 insertions, 5 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index 47bc8171d1..b2f8326b9a 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -191,7 +191,8 @@ int CVkProto::SetStatus(int iNewStatus)
else if ( !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) {
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL);
+ if (m_hWorkerThread == NULL)
+ m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL);
}
else if ( IsOnline())
SetServerStatus(iNewStatus);
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 9a48d0d0e9..5ce0b55980 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -165,6 +165,7 @@ private:
UINT_PTR m_timer;
ptrA m_pollingServer, m_pollingKey, m_pollingTs;
+ HANDLE m_pollingConn;
ULONG m_msgId;
LIST<void> m_sendIds;
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp
index 8ccb048df3..e1574141c4 100644
--- a/protocols/VKontakte/src/vk_queue.cpp
+++ b/protocols/VKontakte/src/vk_queue.cpp
@@ -87,6 +87,7 @@ bool CVkProto::PushAsyncHttpRequest(AsyncHttpRequest *pReq, int iTimeout)
void CVkProto::WorkerThread(void*)
{
+ debugLogA("CVkProto::WorkerThread: entering");
m_bTerminated = false;
m_szAccessToken = getStringA("AccessToken");
if (m_szAccessToken != NULL)
@@ -121,5 +122,6 @@ void CVkProto::WorkerThread(void*)
}
}
- OnLoggedOut();
+ m_hWorkerThread = 0;
+ debugLogA("CVkProto::WorkerThread: leaving");
}
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 71b572e903..373233f3b6 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -55,19 +55,20 @@ void CVkProto::OnLoggedIn()
HttpParam param = { "access_token", m_szAccessToken };
PushAsyncHttpRequest(REQUEST_GET, "/method/getUserInfoEx.json", true, &CVkProto::OnReceiveMyInfo, 1, &param);
-
- SetAllContactStatuses(ID_STATUS_OFFLINE);
}
void CVkProto::OnLoggedOut()
{
- m_hWorkerThread = 0;
m_bOnline = false;
+ if (m_pollingConn)
+ CallService(MS_NETLIB_SHUTDOWN, (WPARAM)m_pollingConn, 0);
+
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
KillTimer(NULL, m_timer);
+ SetAllContactStatuses(ID_STATUS_OFFLINE);
}
int CVkProto::SetServerStatus(int iStatus)
@@ -509,13 +510,20 @@ int CVkProto::PollServer()
else retVal = 0;
}
+ m_pollingConn = reply->nlc;
+
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
return retVal;
}
void CVkProto::PollingThread(void*)
{
+ debugLogA("CVkProto::PollingThread: entering");
+
while (!m_bTerminated)
if (PollServer() == -1)
break;
+
+ m_pollingConn = 0;
+ debugLogA("CVkProto::PollingThread: leaving");
}