select函数执行返回后会把传入的timeval结构体的数值清零,所以每次都要重新设置select的超时时间才能起作用
错误示范:
struct timeval tm ;
tm.tv_sec = 10; tm.tv_usec = 1000 ;
{
int ret = select(fd_max + 1, &rdfd, NULL, &erfd, &tm);
}
正确写法:
{
struct timeval tm ;
tm.tv_sec = 10; tm.tv_usec = 1000 ;
int ret = select(fd_max + 1, &rdfd, NULL, &erfd, &tm);
}