18,362
社区成员
发帖
与我相关
我的任务
分享
// tcp listen thread
......
listen(sListenSocket, 1);
while(!m_ThreadTermined) //在主线程中,控制此变量的改变
{
fd_set fdSocket;
FD_ZERO(&fdSocket);
FD_SET(sListen, &fdSocket);
int nRet = ::select(0, &readSocket, 0, 0, &waitTime); //waitTime 设置1s
if (nRet<0)
AfxMessageBox("Failed select()");
else if(nRet ==0) //time out
continue;
else
{
Logger::getInstance()->error("nRet: %d\n", &nRet); //发现既是没有连接过来,结果总是1
Logger::getInstance()->error("Error: %d\n", GetLastError()); // 总是0
if(FD_ISSET(sListen, &readFD))
{//接受连接
sClient = ::accept(sListen, (sockaddr *)&clientAddr, &cAddrLen);
if(sClient == INVALID_SOCKET)
{
char chMsgBuffer[100];
wsprintf(chMsgBuffer, "\nWinsock error %d: TCP Faild accept()\n\n", GetLastError());//10093
Logger::getInstance()->error(chMsgBuffer);
continue;
}
。。。。。
}
}
}