c select()函数总是返回1

时间:2014-09-21 20:46:53

标签: c sockets file-descriptor

我正在使用select()函数来侦听包括stdin在内的所有文件描述符中的事件。 select函数总是在时间上调用,但无论发生什么事件和fd触发事件,select()函数总是返回1.

    void startSelecting()
    {
       printf("ready! start listening all events\n");
      int current;
      while(is_running){

         do{
             current=select(1000,&readset,NULL,NULL,NULL);
           }while(current==-1&&errno==EINTR);
              printf("file descriptor %d has event\n",current);
              processEvents(current);

        }


    }

所以,就是说,它始终打印"文件描述符1有事件" ... 而且,我正在实施C语言代码。 谢谢你们

1 个答案:

答案 0 :(得分:0)

On success, select() and pselect() return the number of file descriptors contained in the three returned descriptor sets

因此,如果只有一个文件描述符触发事件(这是您的情况),select()将返回1.在select()返回后,您的readset因此只包含一个fd } - 触发事件的那个。

相关问题