From b2c2e5c5b1eefa07a3aff95930cae6c9d1b6bc52 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sun, 23 Aug 2015 12:41:40 +0000 Subject: SkypeWeb: more login fixes. git-svn-id: http://svn.miranda-ng.org/main/trunk@15017 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_trouter.cpp | 61 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'protocols/SkypeWeb/src/skype_trouter.cpp') diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index e3ee811fa3..1525b6b19a 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -103,10 +103,9 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) int iStart = 0; CMStringA szToken = data.Tokenize(":", iStart).Trim(); TRouter.sessId = szToken.GetString(); - if (!m_hTrouterThread) - m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); - else - SetEvent(m_hTrouterEvent); + + SetEvent(m_hTrouterEvent); + SetEvent(m_hTrouterHealthEvent); if ((time(NULL) - TRouter.lastRegistrationTime) >= 3600) { @@ -134,41 +133,45 @@ void CSkypeProto::TRouterThread(void*) int errors = 0; - while (!isTerminated && errors < POLLING_ERRORS_LIMIT) + while (!m_bThreadsTerminated) { - TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId); - request->nlc = m_TrouterConnection; - NLHR_PTR response(request->Send(m_hNetlibUser)); - if (response == NULL) + WaitForSingleObject(m_hTrouterEvent, INFINITE); + + while (errors < POLLING_ERRORS_LIMIT && m_iStatus > ID_STATUS_OFFLINE) { - errors++; + TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId); + request->nlc = m_TrouterConnection; + NLHR_PTR response(request->Send(m_hNetlibUser)); delete request; - continue; - } + if (response == NULL) + { + errors++; + continue; + } - if (response->resultCode == 200) - { - if (response->pData) + if (response->resultCode == 200) { - char *json = strstr(response->pData, "{"); - if (json != NULL) + if (response->pData) { - JSONNode root = JSONNode::parse(json); - std::string szBody = root["body"].as_string(); - const JSONNode &headers = root["headers"]; - const JSONNode body = JSONNode::parse(szBody.c_str()); - OnTrouterEvent(body, headers); + char *json = strstr(response->pData, "{"); + if (json != NULL) + { + JSONNode root = JSONNode::parse(json); + std::string szBody = root["body"].as_string(); + const JSONNode &headers = root["headers"]; + const JSONNode body = JSONNode::parse(szBody.c_str()); + OnTrouterEvent(body, headers); + } } } + else + { + SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth); + WaitForSingleObject(m_hTrouterHealthEvent, INFINITE); + } + m_TrouterConnection = response->nlc; } - else - { - SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth); - WaitForSingleObject(m_hTrouterEvent, INFINITE); - } - m_TrouterConnection = response->nlc; - delete request; } m_hTrouterThread = NULL; m_TrouterConnection = NULL; -- cgit v1.2.3