int sockfd;
fd_set fds;
struct timeval timeout;
timeout.tv_sec=3;
timeout.tv_usec=0;
for(;;)
{
FD_ZERO(&fds);
FD_SET(sockfd,&fds);
switch(select(sockfd+1,NULL,&fds,NULL,&timeout))//检查可写状态
{
case -1:perror("error");
case 0://超时发生,
default:if(FD_ISSET(sockfd,&fds))
{
//发送数据
}
}
}
为什么select每次执行只返回-1?
fd_set fds;
struct timeval timeout;
timeout.tv_sec=3;
timeout.tv_usec=0;
for(;;)
{
FD_ZERO(&fds);
FD_SET(sockfd,&fds);
switch(select(sockfd+1,NULL,&fds,NULL,&timeout))//检查可写状态
{
case -1:perror("error");
case 0://超时发生,
default:if(FD_ISSET(sockfd,&fds))
{
//发送数据
}
}
}
为什么select每次执行只返回-1?
FD_SET fds = {1,sockfd};
TIMEVAL timeout = {3, 0};
if(select(0, &fds, NULL, NULL, &timeout) == 0)
{
//超时处理
}
可能问题出在sockfd的连接上