2017-07-20 72 views
1

該查詢功能的手冊頁說:傳遞一個負面的文件描述符輪詢

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

回答

0

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