轮询函数的手册页说:
...
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
会被忽略。
关于linux - 将负文件描述符传递给轮询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45207194/