diff options
author | George Hazan <george.hazan@gmail.com> | 2024-08-16 20:15:38 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-08-16 20:15:38 +0300 |
commit | 70452ae985e7109b1eb9a66e39c039dacf0e2ecd (patch) | |
tree | 018feed7c9fb6afd893a5f3403de10f7d2f60e5f | |
parent | 9f1e3442e5d25a6a1bd271d0e8e91f0f0f1a57fa (diff) |
fixes #4568 (Skypeweb: может впадать в ступор после спячки)
-rw-r--r-- | protocols/SkypeWeb/src/request_queue.cpp | 7 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/poll.h | 1 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_polling.cpp | 50 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 7 |
6 files changed, 34 insertions, 38 deletions
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp index e4cf75669c..580658d4b6 100644 --- a/protocols/SkypeWeb/src/request_queue.cpp +++ b/protocols/SkypeWeb/src/request_queue.cpp @@ -59,12 +59,15 @@ void CSkypeProto::StartQueue() void CSkypeProto::StopQueue()
{
m_isTerminated = true;
+ m_iPollingId = -1;
if (m_hRequestQueueThread)
m_hRequestQueueEvent.Set();
- if (m_hPollingThread)
- m_hPollingEvent.Set();
+ if (m_hPollingConn) {
+ Netlib_Shutdown(m_hPollingConn);
+ m_hPollingConn = 0;
+ }
}
void CSkypeProto::PushRequest(AsyncHttpRequest *request)
diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h index 20f260fb64..b0ea4de52a 100644 --- a/protocols/SkypeWeb/src/requests/poll.h +++ b/protocols/SkypeWeb/src/requests/poll.h @@ -23,6 +23,7 @@ struct PollRequest : public AsyncHttpRequest PollRequest(CSkypeProto *ppro) :
AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/users/ME/endpoints/" + mir_urlEncode(ppro->m_szId) + "/subscriptions/0/poll")
{
+ flags |= NLHRF_PERSISTENT;
timeout = 120000;
if (ppro->m_iPollingId != -1)
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 83ad944745..406f484278 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -218,6 +218,9 @@ void CSkypeProto::OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest*) }
}
+ if (m_szId && m_hPollingThread == nullptr)
+ ForkThread(&CSkypeProto::PollingThread);
+
PushRequest(new CreateSubscriptionsRequest());
}
@@ -274,8 +277,6 @@ void CSkypeProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest FreeList(skypenames);
skypenames.destroy();
- m_hPollingEvent.Set();
-
PushRequest(new GetContactListRequest());
PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl")), 0));
PushRequest(new SyncConversations());
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index e1d51e49a5..20b65abd60 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -21,44 +21,38 @@ void CSkypeProto::PollingThread(void *) {
debugLogA(__FUNCTION__ ": entering");
+ int nErrors = 0;
+ m_iPollingId = -1;
+
while (true) {
- m_hPollingEvent.Wait();
- if (m_isTerminated)
+ if (m_isTerminated || m_szId == nullptr)
break;
- int nErrors = 0;
- m_iPollingId = -1;
+ std::unique_ptr<PollRequest> request(new PollRequest(this));
+ request->nlc = m_hPollingConn;
+ NLHR_PTR response(DoSend(request.get()));
+ if (m_isTerminated || m_szId == nullptr)
+ break;
- while ((nErrors < POLLING_ERRORS_LIMIT) && m_iStatus != ID_STATUS_OFFLINE) {
- std::unique_ptr<PollRequest> request(new PollRequest(this));
- NLHR_PTR response(DoSend(request.get()));
- if (response == nullptr) {
+ if (response == nullptr || response->resultCode != 200) {
+ if (nErrors < POLLING_ERRORS_LIMIT) {
nErrors++;
continue;
}
-
- if (response->resultCode == 200) {
- nErrors = 0;
- if (!response->body.IsEmpty())
- ParsePollData(response->body);
- }
- else {
- nErrors++;
-
- if (!response->body.IsEmpty()) {
- JSONNode root = JSONNode::parse(response->body);
- const JSONNode &error = root["errorCode"];
- if (error && error.as_int() == 729)
- break;
- }
- }
+ break;
}
- if (m_iStatus != ID_STATUS_OFFLINE) {
- debugLogA(__FUNCTION__ ": unexpected termination; switching protocol to offline");
- SetStatus(ID_STATUS_OFFLINE);
- }
+ m_hPollingConn = response->nlc;
+ if (!response->body.IsEmpty())
+ ParsePollData(response->body);
}
+
+ if (!m_isTerminated) {
+ debugLogA(__FUNCTION__ ": unexpected termination; switching protocol to offline");
+ SetStatus(ID_STATUS_OFFLINE);
+ }
+
+ m_hPollingConn = nullptr;
m_hPollingThread = nullptr;
debugLogA(__FUNCTION__ ": leaving");
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 1b4bc415c5..9cee58b515 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -58,8 +58,6 @@ CSkypeProto::CSkypeProto(const char* protoName, const wchar_t* userName) : g_plugin.addSound("skype_inc_call", L"SkypeWeb", LPGENW("Incoming call"));
g_plugin.addSound("skype_call_canceled", L"SkypeWeb", LPGENW("Incoming call canceled"));
- m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, NULL, NULL);
-
CheckConvert();
InitGroupChatModule();
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 32c634f3c6..b242ad4142 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -176,8 +176,6 @@ private: std::map<std::string, std::string> cookies;
static std::map<std::wstring, std::wstring> languages;
- HANDLE m_hPollingThread;
-
LIST<void> m_PopupClasses;
LIST<void> m_OutMessages;
@@ -186,8 +184,9 @@ private: mir_cs messageSyncLock;
mir_cs m_StatusLock;
- EventHandle m_hPollingEvent;
-
+ HANDLE m_hPollingThread;
+ HNETLIBCONN m_hPollingConn;
+
INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM);
|