我写了以下函数,它工作正常:
bool NetworkSocket::isSocketReady()
{
/// Got here because iSelectReturn > 0 thus data available on at least one descriptor
// Is our socket in the return list of readable sockets
bool res;
fd_set sready;
struct timeval nowait;
FD_ZERO(&sready);
FD_SET((unsigned int)this->socketFD,&sready);
//bzero((char *)&nowait,sizeof(nowait));
memset((char *)&nowait,0,sizeof(nowait));
res = select(this->socketFD+1,&sready,NULL,NULL,&nowait);
if( FD_ISSET(this->socketFD,&sready) )
res = true;
else
res = false;
return res;
}
当套接字准备好工作时,上面的函数返回true,你知道我测试套接字是否有数据我如何测试它吗?