diff options
Diffstat (limited to 'protocols/IcqOscarJ/src/chan_05ping.cpp')
-rw-r--r-- | protocols/IcqOscarJ/src/chan_05ping.cpp | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/protocols/IcqOscarJ/src/chan_05ping.cpp b/protocols/IcqOscarJ/src/chan_05ping.cpp index 62c3377ada..5fe2aaf9a7 100644 --- a/protocols/IcqOscarJ/src/chan_05ping.cpp +++ b/protocols/IcqOscarJ/src/chan_05ping.cpp @@ -29,50 +29,30 @@ void CIcqProto::handlePingChannel(BYTE *buf, WORD datalen) debugLogA("Warning: Ignoring server packet on PING channel");
}
-void __cdecl CIcqProto::KeepAliveThread(void *arg)
+void CIcqProto::StartKeepAlive(serverthread_info *info)
{
- serverthread_info *info = (serverthread_info*)arg;
- icq_packet packet;
- DWORD dwInterval = getDword("KeepAliveInterval", KEEPALIVE_INTERVAL);
-
- debugLogA("Keep alive thread starting.");
-
- info->hKeepAliveEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-
- for (;;) {
- DWORD dwWait = ICQWaitForSingleObject(info->hKeepAliveEvent, dwInterval);
- if (serverThreadHandle == NULL) // connection lost, end
- break;
+ if (getByte("KeepAlive", DEFAULT_KEEPALIVE_ENABLED))
+ info->iKeepalive = getDword("KeepAliveInterval", KEEPALIVE_INTERVAL);
+ else
+ info->iKeepalive = -1;
+}
- // Possible shutdown in progress
- if (dwWait == WAIT_IO_COMPLETION)
- break;
+void CIcqProto::StopKeepAlive(serverthread_info *info)
+{
+ info->iKeepalive = -1;
+}
- if (dwWait == WAIT_TIMEOUT) {
+void CIcqProto::CheckKeepAlive(serverthread_info *info)
+{
+ if (info->iKeepalive != -1) {
+ if (info->iKeepalive == 0) {
// Send a keep alive packet to server
- packet.wLen = 0;
+ icq_packet packet = { 0 };
write_flap(&packet, ICQ_PING_CHAN);
sendServPacket(&packet);
+
+ StartKeepAlive(info);
}
+ else info->iKeepalive--;
}
-
- debugLogA("Keep alive thread ended.");
-
- CloseHandle(info->hKeepAliveEvent);
- info->hKeepAliveEvent = NULL;
-}
-
-void CIcqProto::StartKeepAlive(serverthread_info *info)
-{
- if (info->hKeepAliveEvent) // start only once
- return;
-
- if (getByte("KeepAlive", DEFAULT_KEEPALIVE_ENABLED))
- ForkThread(&CIcqProto::KeepAliveThread, info);
-}
-
-void CIcqProto::StopKeepAlive(serverthread_info *info)
-{
- if (info->hKeepAliveEvent)
- SetEvent(info->hKeepAliveEvent);
}
|