fix: client threads number excceeding bug
This commit is contained in:
@@ -18,7 +18,7 @@ CKernelManager::~CKernelManager()
|
||||
{
|
||||
printf("~CKernelManager begin\n");
|
||||
int i = 0;
|
||||
for (i=0;i<0x1000;++i)
|
||||
for (i=0;i<MAX_THREADNUM;++i)
|
||||
{
|
||||
if (m_hThread[i].h!=0)
|
||||
{
|
||||
@@ -33,10 +33,33 @@ CKernelManager::~CKernelManager()
|
||||
printf("~CKernelManager end\n");
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>õ<EFBFBD><C3B5>߳<EFBFBD><DFB3>±<EFBFBD>
|
||||
UINT CKernelManager::GetAvailableIndex() {
|
||||
if (m_ulThreadCount < MAX_THREADNUM) {
|
||||
return m_ulThreadCount;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_THREADNUM; ++i)
|
||||
{
|
||||
if (m_hThread[i].p == NULL) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
IOCPClient *pNew = szBuffer[0] == COMMAND_BYE ? NULL : new IOCPClient(true);
|
||||
m_hThread[m_ulThreadCount].p = pNew;
|
||||
bool isExit = szBuffer[0] == COMMAND_BYE || szBuffer[0] == SERVER_EXIT;
|
||||
if ((m_ulThreadCount = GetAvailableIndex()) == -1) {
|
||||
if (!isExit) {
|
||||
printf("CKernelManager: The number of threads exceeds the limit.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!isExit){
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(true);
|
||||
}
|
||||
|
||||
switch(szBuffer[0])
|
||||
{
|
||||
@@ -78,9 +101,6 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 1;
|
||||
OutputDebugStringA("======> Client exit \n");
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
delete pNew;
|
||||
pNew = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -90,9 +110,6 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 2;
|
||||
OutputDebugStringA("======> Server exit \n");
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
delete pNew;
|
||||
pNew = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -147,9 +164,10 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
default:
|
||||
{
|
||||
OutputDebugStringA("======> Error operator\n");
|
||||
if (m_ulThreadCount != -1) {
|
||||
delete m_hThread[m_ulThreadCount].p;
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
delete pNew;
|
||||
pNew = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
#include "Manager.h"
|
||||
#include <vector>
|
||||
|
||||
// <20>߳<EFBFBD><DFB3><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
#define MAX_THREADNUM 0x1000
|
||||
|
||||
// <20>߳<EFBFBD><DFB3><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>, <20><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>Ա: <20><><EFBFBD><EFBFBD>״̬(run)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(h)<29><>ͨѶ<CDA8>ͻ<EFBFBD><CDBB><EFBFBD>(p).
|
||||
struct ThreadInfo
|
||||
{
|
||||
BOOL run;
|
||||
@@ -28,8 +30,11 @@ public:
|
||||
virtual ~CKernelManager();
|
||||
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
||||
|
||||
ThreadInfo m_hThread[0x1000];
|
||||
ThreadInfo m_hThread[MAX_THREADNUM];
|
||||
// <20><>ֵ<EFBFBD><D6B5>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>¼<EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱm_hThread<61><64>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD>쳣
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD>ֵ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>Ϊ"<22><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>±<EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m_hThread<61><64><EFBFBD><EFBFBD>ָλ<D6B8>ÿ<EFBFBD><C3BF>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5>̷߳<DFB3><CCB7><EFBFBD><EFBFBD>ڸ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
ULONG m_ulThreadCount;
|
||||
UINT GetAvailableIndex();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_KERNELMANAGER_H__B1186DC0_E4D7_4D1A_A8B8_08A01B87B89E__INCLUDED_)
|
||||
|
||||
Reference in New Issue
Block a user