From 7a917d3884e32266bd8645287c558fe095e986a3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 14 Jul 2012 08:56:46 +0000 Subject: fix for killing ICQ threads on exit git-svn-id: http://svn.miranda-ng.org/main/trunk@962 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/IcqOscarJ/chan_05ping.cpp | 13 +++------- protocols/IcqOscarJ/fam_03buddy.cpp | 7 +++--- protocols/IcqOscarJ/icq_infoupdate.cpp | 44 ++++++++++++++-------------------- protocols/IcqOscarJ/icq_proto.cpp | 3 --- protocols/IcqOscarJ/icq_server.cpp | 26 ++++++++++---------- protocols/IcqOscarJ/icq_server.h | 1 - 6 files changed, 39 insertions(+), 55 deletions(-) (limited to 'protocols') diff --git a/protocols/IcqOscarJ/chan_05ping.cpp b/protocols/IcqOscarJ/chan_05ping.cpp index 53f094efee..2a2b843509 100644 --- a/protocols/IcqOscarJ/chan_05ping.cpp +++ b/protocols/IcqOscarJ/chan_05ping.cpp @@ -44,7 +44,7 @@ void __cdecl CIcqProto::KeepAliveThread(void *arg) NetLog_Server("Keep alive thread starting."); - info->hKeepAliveEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + info->hKeepAliveEvent = CreateEvent(NULL, FALSE, FALSE, NULL); for (;;) { @@ -65,7 +65,7 @@ void __cdecl CIcqProto::KeepAliveThread(void *arg) break; } - NetLog_Server("Keep alive thread shutting down."); + NetLog_Server("Keep alive thread ended."); CloseHandle(info->hKeepAliveEvent); info->hKeepAliveEvent = NULL; @@ -78,19 +78,12 @@ void CIcqProto::StartKeepAlive(serverthread_info *info) return; if (getSettingByte(NULL, "KeepAlive", DEFAULT_KEEPALIVE_ENABLED)) - info->hKeepAliveThread = ForkThreadEx(&CIcqProto::KeepAliveThread, info); + CloseHandle( ForkThreadEx(&CIcqProto::KeepAliveThread, info)); } void CIcqProto::StopKeepAlive(serverthread_info *info) { // finish keep alive thread if (info->hKeepAliveEvent) - { SetEvent(info->hKeepAliveEvent); - - // wait for the thread to finish - ICQWaitForSingleObject(info->hKeepAliveThread, INFINITE, TRUE); - CloseHandle(info->hKeepAliveThread); - info->hKeepAliveThread = NULL; - } } diff --git a/protocols/IcqOscarJ/fam_03buddy.cpp b/protocols/IcqOscarJ/fam_03buddy.cpp index 91f59147df..caa41d966c 100644 --- a/protocols/IcqOscarJ/fam_03buddy.cpp +++ b/protocols/IcqOscarJ/fam_03buddy.cpp @@ -195,10 +195,12 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) unpackWord(&buf, &wTLVCount); wLen -= 2; - // Determine contact - HANDLE hContact = HContactFromUID(dwUIN, szUID, NULL); + // notify that the set status note & mood process is finished + if (m_hNotifyNameInfoEvent) + SetEvent(m_hNotifyNameInfoEvent); // Ignore status notification if the user is not already on our list + HANDLE hContact = HContactFromUID(dwUIN, szUID, NULL); if (hContact == INVALID_HANDLE_VALUE) { #ifdef _DEBUG @@ -578,7 +580,6 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) } } - void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) { DWORD dwUIN; diff --git a/protocols/IcqOscarJ/icq_infoupdate.cpp b/protocols/IcqOscarJ/icq_infoupdate.cpp index a5bf1656a7..5d0abbf47c 100644 --- a/protocols/IcqOscarJ/icq_infoupdate.cpp +++ b/protocols/IcqOscarJ/icq_infoupdate.cpp @@ -35,21 +35,18 @@ void CIcqProto::icq_InitInfoUpdate(void) { // Create wait objects hInfoQueueEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - - if (hInfoQueueEvent) - { + if (hInfoQueueEvent) { // Init mutexes infoUpdateMutex = new icq_critical_section(); // Init list - for (int i = 0; iEnter(); if (!m_rates) // we lost connection when we slept, go away @@ -391,19 +383,19 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) break; } } + NetLog_Server("%s thread ended.", "Info-Update"); + +LBL_Exit: + SAFE_DELETE(&infoUpdateMutex); + CloseHandle(hInfoQueueEvent); } // Clean up before exit void CIcqProto::icq_InfoUpdateCleanup(void) { + NetLog_Server("%s must die.", "Info-Update"); bInfoUpdateRunning = FALSE; - SetEvent(hInfoQueueEvent); // break queue loop - if (hInfoThread) - ICQWaitForSingleObject(hInfoThread, INFINITE, TRUE); - - // Uninit mutex - SAFE_DELETE(&infoUpdateMutex); - CloseHandle(hInfoQueueEvent); - CloseHandle(hInfoThread); + if (hInfoQueueEvent) + SetEvent(hInfoQueueEvent); // break queue loop } diff --git a/protocols/IcqOscarJ/icq_proto.cpp b/protocols/IcqOscarJ/icq_proto.cpp index 495c29bd98..8e5d11100c 100644 --- a/protocols/IcqOscarJ/icq_proto.cpp +++ b/protocols/IcqOscarJ/icq_proto.cpp @@ -359,9 +359,6 @@ int CIcqProto::OnModulesLoaded( WPARAM wParam, LPARAM lParam ) int CIcqProto::OnPreShutdown(WPARAM wParam,LPARAM lParam) { - // all threads should be terminated here - icq_InfoUpdateCleanup(); - // Make sure all connections are closed CloseContactDirectConns(NULL); return 0; diff --git a/protocols/IcqOscarJ/icq_server.cpp b/protocols/IcqOscarJ/icq_server.cpp index c12d6ef362..1226eae0c4 100644 --- a/protocols/IcqOscarJ/icq_server.cpp +++ b/protocols/IcqOscarJ/icq_server.cpp @@ -182,6 +182,9 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam) SetCurrentStatus(ID_STATUS_OFFLINE); } + // signal info update thread to stop + icq_InfoUpdateCleanup(); + // signal keep-alive thread to stop StopKeepAlive(&info); @@ -234,20 +237,19 @@ void __cdecl CIcqProto::ServerThread(serverthread_start_info *infoParam) void CIcqProto::icq_serverDisconnect(BOOL bBlock) { - if (hServerConn) - { - NetLog_Server("Server shutdown requested"); - Netlib_Shutdown(hServerConn); + if ( !hServerConn) + return; - if (serverThreadHandle) - { - // Not called from network thread? - if (bBlock && GetCurrentThreadId() != serverThreadId) - while (ICQWaitForSingleObject(serverThreadHandle, INFINITE) != WAIT_OBJECT_0); + NetLog_Server("Server shutdown requested"); + Netlib_Shutdown(hServerConn); - CloseHandle(serverThreadHandle); - serverThreadHandle = NULL; - } + if (serverThreadHandle) { + // Not called from network thread? + if (bBlock && GetCurrentThreadId() != serverThreadId) + while (ICQWaitForSingleObject(serverThreadHandle, INFINITE) != WAIT_OBJECT_0); + + CloseHandle(serverThreadHandle); + serverThreadHandle = NULL; } } diff --git a/protocols/IcqOscarJ/icq_server.h b/protocols/IcqOscarJ/icq_server.h index 231ebaaa4d..eba3ecfa42 100644 --- a/protocols/IcqOscarJ/icq_server.h +++ b/protocols/IcqOscarJ/icq_server.h @@ -58,7 +58,6 @@ struct serverthread_info HANDLE hDirectBoundPort; // HANDLE hKeepAliveEvent; - HANDLE hKeepAliveThread; }; /*---------* Functions *---------------*/ -- cgit v1.2.3