传递一个负面的文件描述符轮询

问题描述:

该查询功能的手册页说:传递一个负面的文件描述符轮询

...  
    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事件都会被忽略?

不,只有带有否定文件描述符的struct pollfd将被忽略。