|
-
March 20th, 2008, 09:10 PM
#1
winsock: function select() work in wrong way under release version.
I'm writing a server program, My ide is vs2005. When the program is built in "debug version", it works all right, but when the program is built in "release version", it works in wrong way.
The part of source code follows:
Code:
while(WaitForSingleObject(hEventWork, 0) == WAIT_TIMEOUT)
{
Sleep(10);
FD_ZERO(&fdset_accept);
FD_SET(svr_sock, &fdset_accept);
// the follow select can't work in release version, it will return 0 even though there are some income connections pending
if (select(0, &fdset_accept, NULL, NULL, &waittime) > 0)
{
if ((sk_income =accept(svr_sock, &arrive_sock_addr, &addrlen)) == INVALID_SOCKET)
{
break;
}
if (g_tHandleCount < MAX_THREAD_LIMIT)
{
HANDLE hNewThread = CreateThread(NULL, 0, ThreadTransfor, (LPVOID)sk_income, CREATE_SUSPENDED, NULL);
if (hNewThread != NULL)
{
g_tHandle[g_tHandleCount++] = hNewThread;
ResumeThread(hNewThread);
}
else
{
dwret = GetLastError();
}
}
else
{
closesocket(sk_income); // Too many threads
}
}
// test for child threads ending
if (g_tHandleCount > 0)
{
dwWaitResult = WaitForMultipleObjects(g_tHandleCount, g_tHandle, FALSE, 0);
switch(dwWaitResult)
{
case WAIT_FAILED:
break;
case WAIT_TIMEOUT:
break;
default:
if (dwWaitResult >= WAIT_OBJECT_0 && dwWaitResult <= WAIT_OBJECT_0 + g_tHandleCount -1)
{
CloseHandle(g_tHandle[dwWaitResult]);
for(int i = dwWaitResult; i < MAX_THREAD_LIMIT; i++)
{
g_tHandle[i] = g_tHandle[i+1];
}
g_tHandleCount--;
}
break;
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|