0

根据 man(2) 民意调查:

int poll(struct pollfd *fds, nfds_t nfds, int timeout);
struct pollfd {
    int   fd;         /* file descriptor */
    short events;     /* requested events */
    short revents;    /* returned events */
};

如果我写if(! (fds.revents &1 ))后使用poll是什么意思?

4

1 回答 1

1

根据man(2) 民意调查确实...

字段 revents 是一个输出参数,由内核填充实际发生的事件。revents 中返回的位可以包括任何在 events 中指定的位,或值 POLLERR、POLLHUP 或 POLLNVAL 之一。(这三个位在 events 字段中是没有意义的,只要相应的条件为真,就会在 revents 字段中设置。)

poll.h将这些定义为

#define POLLIN      0x001       /* There is data to read.  */
#define POLLPRI     0x002       /* There is urgent data to read.  */
#define POLLOUT     0x004       /* Writing now will not block.  */
// etc...

如此拥有这些知识,

if(!(fds.revents & 1))

是相同的

if(!(fds.revents & POLLIN))

这意味着“如果没有设置“有数据要读取”位”,即“如果没有数据要读取”。

于 2021-03-22T20:31:50.920 回答