检查 revents 到 struct pollfd

check revents into struct pollfd

根据 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 */
};

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

根据man(2) poll确实...

The field revents is an output parameter, filled by the kernel with the events that actually occurred. The bits returned in revents can include any of those specified in events, or one of the values POLLERR, POLLHUP, or POLLNVAL. (These three bits are meaningless in the events field, and will be set in the revents field whenever the corresponding condition is true.)

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))

表示“如果没有设置‘有数据可读’位”,即“如果没有数据可读”。