diff options
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.h | 15 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_thread.cpp | 52 |
2 files changed, 34 insertions, 33 deletions
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 430f8b0eed..57044acd21 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -81,7 +81,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface friend struct CJabberProto;
CJabberProto &m_proto;
- CTimer m_heartBeat;
+ CTimer m_heartBeat, m_keepAlive;
void OnHeartBeat(CTimer *pTimer)
{
m_proto.SendGetVcard(0);
@@ -90,11 +90,18 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface pTimer->Start(86400 * 1000);
}
+ void OnKeepAlive(CTimer*)
+ {
+ m_proto.CheckKeepAlive();
+ }
+
CJabberProtoImpl(CJabberProto &pro) :
m_proto(pro),
- m_heartBeat(Miranda_GetSystemWindow(), UINT_PTR(this))
+ m_heartBeat(Miranda_GetSystemWindow(), UINT_PTR(this)),
+ m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this)+1)
{
m_heartBeat.OnEvent = Callback(this, &CJabberProtoImpl::OnHeartBeat);
+ m_keepAlive.OnEvent = Callback(this, &CJabberProtoImpl::OnKeepAlive);
}
} m_impl;
@@ -828,7 +835,9 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface void xmlStreamInitialize(char *which);
void xmlStreamInitializeNow(ThreadData *info);
-
+
+ void CheckKeepAlive(void);
+
bool OnProcessJingle(const TiXmlElement *node);
void OnProcessIq(const TiXmlElement *node);
void SetRegConfig(CJabberFormDlg *pDlg, void *from);
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 7e4a20b731..5b6877dc97 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -139,6 +139,26 @@ void CJabberProto::JLoginFailed(int errorCode) /////////////////////////////////////////////////////////////////////////////////////////
+void CJabberProto::CheckKeepAlive()
+{
+ if (GetTickCount() - m_lastTicks < m_iConnectionKeepAliveInterval)
+ return;
+
+ if (m_bKeepAlive && m_ThreadInfo) {
+ if (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_PING) {
+ CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, this);
+ pInfo->SetTimeout(m_iConnectionKeepAliveTimeout);
+ m_ThreadInfo->send(XmlNodeIq(pInfo) << XATTR("from", m_ThreadInfo->fullJID) << XCHILDNS("ping", JABBER_FEAT_PING));
+ }
+ else m_ThreadInfo->send(" \t ");
+ }
+
+ if (m_bEnableStreamMgmt)
+ m_StrmMgmt.RequestAck();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static int CompareDNS(const DNS_SRV_DATAA* dns1, const DNS_SRV_DATAA* dns2)
{
return (int)dns1->wPriority - (int)dns2->wPriority;
@@ -385,14 +405,12 @@ LBL_FatalError: // User may change status to OFFLINE while we are connecting above
if (m_iDesiredStatus != ID_STATUS_OFFLINE || info.bIsReg) {
- bool bSendKeepAlive = false;
-
if (!info.bIsReg) {
m_szJabberJID = CMStringA(FORMAT, "%s@%s", info.conn.username, info.conn.server).Detach();
- bSendKeepAlive = m_bKeepAlive;
setUString("jid", m_szJabberJID); // store jid in database
ListInit();
+ m_impl.m_keepAlive.Start(1000);
}
xmlStreamInitializeNow(&info);
@@ -401,34 +419,7 @@ LBL_FatalError: int datalen = 0;
// cache values
- DWORD dwConnectionKeepAliveInterval = m_iConnectionKeepAliveInterval;
for (;;) {
- if (!info.useZlib || info.zRecvReady) {
- DWORD dwIdle = GetTickCount() - m_lastTicks;
- if (dwIdle >= dwConnectionKeepAliveInterval)
- dwIdle = dwConnectionKeepAliveInterval - 10; // now!
-
- NETLIBSELECT nls = {};
- nls.dwTimeout = dwConnectionKeepAliveInterval - dwIdle;
- nls.hReadConns[0] = info.s;
- int nSelRes = Netlib_Select(&nls);
- if (nSelRes == -1) // error
- break;
- else if (nSelRes == 0) {
- if (bSendKeepAlive) {
- if (info.jabberServerCaps & JABBER_CAPS_PING) {
- CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, this);
- pInfo->SetTimeout(m_iConnectionKeepAliveTimeout);
- info.send(XmlNodeIq(pInfo) << XATTR("from", info.fullJID) << XCHILDNS("ping", JABBER_FEAT_PING));
- }
- else info.send(" \t ");
- }
-
- if (m_bEnableStreamMgmt)
- m_StrmMgmt.RequestAck();
- }
- }
-
int recvResult = info.recv(info.buffer + datalen, jabberNetworkBufferSize - datalen);
debugLogA("recvResult = %d", recvResult);
if (recvResult <= 0)
@@ -493,6 +484,7 @@ recvRest: }
if (!info.bIsReg) {
+ m_impl.m_keepAlive.Stop();
m_iqManager.ExpireAll();
m_bJabberOnline = false;
info.zlibUninit();
|