64,644
社区成员
发帖
与我相关
我的任务
分享
int SockCanRead(int iSocketId, int timeout)
{
fd_set readfds;
int iMaxFd;
struct timeval stuTime;
int iReady;
iMaxFd = iSocketId;
memset((char *)&readfds, 0, sizeof(fd_set));
FD_ZERO(&readfds);
FD_SET(iSocketId, &readfds);
if (timeout > 0){
stuTime.tv_sec = timeout;
stuTime.tv_usec = 0;
iReady = select(iMaxFd + 1, &readfds, NULL, NULL, &stuTime);
}
else{
iReady = select(iMaxFd + 1, &readfds, NULL, NULL, NULL);
}
if (iReady > 0 && FD_ISSET(iSocketId, &readfds)){
return 0;
}
else{
return -1;
}
}