diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-14 08:56:46 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-14 08:56:46 +0000 |
commit | 7a917d3884e32266bd8645287c558fe095e986a3 (patch) | |
tree | 2838aa7030a2dee67dd19da05aa62c86bd99aba4 /protocols | |
parent | c597d66aa12a6cc27c6b0ffb87d8e63a63a86846 (diff) |
fix for killing ICQ threads on exit
git-svn-id: http://svn.miranda-ng.org/main/trunk@962 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/IcqOscarJ/chan_05ping.cpp | 13 | ||||
-rw-r--r-- | protocols/IcqOscarJ/fam_03buddy.cpp | 7 | ||||
-rw-r--r-- | protocols/IcqOscarJ/icq_infoupdate.cpp | 44 | ||||
-rw-r--r-- | protocols/IcqOscarJ/icq_proto.cpp | 3 | ||||
-rw-r--r-- | protocols/IcqOscarJ/icq_server.cpp | 26 | ||||
-rw-r--r-- | protocols/IcqOscarJ/icq_server.h | 1 |
6 files changed, 39 insertions, 55 deletions
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; i<LISTSIZE; i++)
- {
+ for (int i = 0; i<LISTSIZE; i++) {
m_infoUpdateList[i].dwUin = 0;
m_infoUpdateList[i].hContact = NULL;
m_infoUpdateList[i].queued = 0;
}
- hInfoThread = ForkThreadEx( &CIcqProto::InfoUpdateThread, NULL );
+ CloseHandle( ForkThreadEx( &CIcqProto::InfoUpdateThread, NULL));
}
bInfoPendingUsers = 0;
@@ -152,16 +149,13 @@ void CIcqProto::icq_DequeueUser(DWORD dwUin) void CIcqProto::icq_RescanInfoUpdate()
{
- HANDLE hContact = NULL;
- BOOL bOldEnable = bInfoUpdateEnabled;
-
bInfoPendingUsers = 0;
/* This is here, cause we do not want to emit large number of reuqest at once,
fill queue, and let thread deal with it */
bInfoUpdateEnabled = 0; // freeze thread
- // Queue all outdated users
- hContact = FindFirstContact();
+ // Queue all outdated users
+ HANDLE hContact = FindFirstContact();
while (hContact != NULL)
{
if (IsMetaInfoChanged(hContact))
@@ -174,7 +168,8 @@ void CIcqProto::icq_RescanInfoUpdate() }
hContact = FindNextContact(hContact);
}
- icq_EnableUserLookup(bOldEnable); // wake up thread
+
+ bInfoUpdateEnabled = TRUE;
}
@@ -199,9 +194,6 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) while (bInfoUpdateRunning)
{
- // Wait for a while
- ResetEvent(hInfoQueueEvent);
-
if (!nInfoUserCount && bInfoPendingUsers) // whole queue processed, check if more users needs updating
icq_RescanInfoUpdate();
@@ -254,7 +246,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) if (!bInfoUpdateRunning)
{ // need to end as fast as possible
NetLog_Server("%s thread ended.", "Info-Update");
- return;
+ goto LBL_Exit;
}
continue;
}
@@ -268,7 +260,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) if (!bInfoUpdateRunning)
{ // need to end as fast as possible
NetLog_Server("%s thread ended.", "Info-Update");
- return;
+ goto LBL_Exit;
}
continue;
}
@@ -296,7 +288,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) if (!bInfoUpdateRunning)
{ // need to end as fast as possible
NetLog_Server("%s thread ended.", "Info-Update");
- return;
+ goto LBL_Exit;
}
m_ratesMutex->Enter();
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 *---------------*/
|