传递否定文件描述符以进行轮询

时间:2017-07-20 06:47:16

标签: linux operating-system polling systems-programming

民意调查功能的手册页说:

   ...       
   int poll(struct pollfd *fds, nfds_t nfds, int timeout);
   ...

   struct pollfd {
               int   fd;         /* file descriptor */
               short events;     /* requested events */
               short revents;    /* returned events */
           };
   ...
   The field fd contains a file descriptor for an open file.  If this
   field is negative, then the corresponding events field is ignored and
   the revents field returns zero.  (This provides an easy way of
   ignoring a file descriptor for a single poll() call: simply negate
   the fd field.  Note, however, that this technique can't be used to
   ignore file descriptor 0.)

因此,如果我按如下方式定义pollfd结构:

   struct pollfd pollevent;
   pollevent.fd=-1;
   pollevent.event=POLLIN;

对于使用fd = 1打开的文件,是否会忽略所有POLLIN事件?

1 个答案:

答案 0 :(得分:0)

没有。只有带有负文件描述符的struct pollfd才会被忽略。