int common_poll(struct pollfd *pfd, int *nsds, int timeout)
{
int nfd;
time_t tin;
time_t tout;
if (timeout > 0)
tin = time(NULL);
do{
nfd = poll(pfd, EVENTS, timeout);
if((rv < 0) && (errno == EINTR) && (timeout > 0)){
tout = time(NULL);
if(tout - tin >= timeout/1000){
nfd= 0;
break;
}else{
timeout -= (tout - tin)*1000;
tin = tout;
continue;
}
}
}while((nfd < 0) && (errno == EINTR));
(*nsds) = nfd;
if ((*nsds) < 0) {
return errno;
}
return 0;
}
防止poll监听被中断
最新推荐文章于 2024-06-17 01:25:58 发布