Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets 在特定条件下重新启动计时器_Sockets_Select_Udp_Timeout - Fatal编程技术网

Sockets 在特定条件下重新启动计时器

Sockets 在特定条件下重新启动计时器,sockets,select,udp,timeout,Sockets,Select,Udp,Timeout,我正在使用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 t

我正在使用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!!!!!");


}

这会像预期的那样工作吗?ie:只有在满足条件或出现超时时才重新启动计时器

是否存在阻止您运行/编译此程序以检查其是否能按预期工作的因素?有一个叫做ideone.com的很好的在线网站,它可以让你在浏览器中快速编译和测试各种语言的代码。如果条件为false,你对select的行为有什么打算?如果条件为false,我仍然想检查文件描述符是否有可读取的数据,但不想重置计时器ie:contonue using previous timer value continue using previous timer value select的某些实现修改超时值。如果是这种情况,您需要在重用它们之前重新初始化它们。有关详细信息,请参阅select上的实现文档。