我正在使用select()
而我只想在某种条件下重启计时器。
到目前为止,我有这个:
int t = 1;
fd_set readfds;
struct timeval timeout;
int sret;
while(1){
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
if(prevAck != ack || t == 1){ // only restart timer when necessary
timeout.tv_sec = 0;
timeout.tv_usec = 10000; // 10 msec
t = 0;
}
sret = select(sockfd + 1, &readfds, NULL, NULL, &timeout);
if(sret == 0){ //timeout
printf("%s\n", "Time Out!!!!!");
t = 1;
}
else
printf("%s\n", "No time Out!!!!!");
}
这会按预期工作吗?即:仅在满足条件或超时时重新启动计时器