在多个线程中使用CSocket会出现问题,在线程的入口处添加下列代码或许能解决:
unsigned Thread(void* pvoid)
{
#ifndef _AFXDLL
// setup maps and lists specific to socket state
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
if (pState->m_pmapSocketHandle == NULL)
pState->m_pmapSocketHandle = new CMapPtrToPtr;
if (pState->m_pmapDeadSockets == NULL)
pState->m_pmapDeadSockets = new CMapPtrToPtr;
if (pState->m_plistSocketNotifications == NULL)
pState->m_plistSocketNotifications = new CPtrList;
#endif
.......
}