From 0d0add7b1272241fe4c90f09c7ca8be1762a3c6d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 16 Jul 2014 11:17:06 +0000 Subject: fix for keep-alive in ICQ git-svn-id: http://svn.miranda-ng.org/main/trunk@9827 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/IcqOscarJ/src/icq_avatar.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'protocols/IcqOscarJ/src/icq_avatar.cpp') diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp index f71b32ede0..35bcd7de2a 100644 --- a/protocols/IcqOscarJ/src/icq_avatar.cpp +++ b/protocols/IcqOscarJ/src/icq_avatar.cpp @@ -941,12 +941,11 @@ void avatars_server_connection::connectionThread() { // This is the "infinite" loop that receives the packets from the ICQ avatar server NETLIBPACKETRECVER packetRecv = { 0 }; - DWORD wLastKeepAlive = 0; // we send keep-alive at most one per 30secs - DWORD dwKeepAliveInterval = ppro->getDword("KeepAliveInterval", KEEPALIVE_INTERVAL); + DWORD dwLastKeepAlive = time(0) + KEEPALIVE_INTERVAL; hPacketRecver = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)hConnection, 65536); packetRecv.cbSize = sizeof(packetRecv); - packetRecv.dwTimeout = dwKeepAliveInterval < KEEPALIVE_INTERVAL ? dwKeepAliveInterval: KEEPALIVE_INTERVAL; // timeout - for stopThread to work + packetRecv.dwTimeout = 1000; // timeout - for stopThread to work while (!stopThread) { int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv); if (recvResult == 0) { @@ -956,36 +955,27 @@ void avatars_server_connection::connectionThread() if (recvResult == SOCKET_ERROR) { if (GetLastError() == ERROR_TIMEOUT) { // timeout, check if we should be still running - if (Miranda_Terminated()) { // we must stop here, cause due to a hack in netlib, we always get timeout, even if the connection is already dead - stopThread = 1; - continue; - } + if (Miranda_Terminated()) + break; - if (GetTickCount() > wLastKeepAlive) { // limit frequency (HACK: on some systems select() does not work well) + if (time(0) >= dwLastKeepAlive) { // limit frequency (HACK: on some systems select() does not work well) if (!ppro->m_bGatewayMode && ppro->getByte("KeepAlive", DEFAULT_KEEPALIVE_ENABLED)) { // send keep-alive packet icq_packet packet; - packet.wLen = 0; write_flap(&packet, ICQ_PING_CHAN); sendServerPacket(&packet); } - wLastKeepAlive = GetTickCount() + dwKeepAliveInterval; - } - else { // this is bad, the system does not handle select() properly - SleepEx(500, TRUE); // wait some time, can we do anything else ?? - if (Miranda_Terminated()) { - stopThread = 1; - continue; - } + dwLastKeepAlive = time(0) + KEEPALIVE_INTERVAL; } + // check if we got something to request checkRequestQueue(); continue; } if (!stopThread) - ppro->debugLogA("Abortive closure of server socket, error: %d", GetLastError()); + ppro->debugLogA("Avatar socket closed abortively, error: %d", GetLastError()); else - ppro->debugLogA("Connection closed."); + ppro->debugLogA("Avatar socket gracefully closed."); break; } -- cgit v1.2.3