// JP opened flex table

Click to See Complete Forum and Search --> : VC++7.0, CAsync/Socket assertion when doing immediate close


Robert Rostek
April 13th, 2002, 06:01 PM
hello,
i had this problem in vc6.0 and it still exists in vc7.0

what i do:
i create a CAsyncSocket and install a timer (WM_TIMER), lets say, 3 seconds. when the timer is triggered, it calls pSocket->Close();

when i do that very often (e.g. setting the timer to 10 milliseconds) the program is creating/closing sockets very rapidly.

very soon i get an exception here (this is MFC code!):

void PASCAL CAsyncSocket::DoCallBack(WPARAM wParam, LPARAM lParam)
{
if (wParam == 0 && lParam == 0)
return;

// Has the socket be closed?
CAsyncSocket* pSocket = CAsyncSocket::LookupHandle((SOCKET)wParam, TRUE);

// If yes ignore message
if (pSocket != NULL)
return;

pSocket = CAsyncSocket::LookupHandle((SOCKET)wParam, FALSE);
if (pSocket == NULL)
{
// Must be in the middle of an Accept call
pSocket = CAsyncSocket::LookupHandle(INVALID_SOCKET, FALSE);
// ASSERTS HERE !!!
ASSERT(pSocket != NULL);
// ASSERTS HERE !!!
pSocket->m_hSocket = (SOCKET)wParam;
CAsyncSocket::DetachHandle(INVALID_SOCKET, FALSE);
CAsyncSocket::AttachHandle(pSocket->m_hSocket, pSocket, FALSE);
}




my only solution so far was not to call close, but "detach" and store the returned handle in a list. when the list gets bigger than ~5 items, delete one. this gets rid of the entire problem - no crash at all.

please help.

Robert Rostek
-=[tecxx[at]rrs.at]=-

//JP added flex table