c - 如果设置了任何 POLLERR、POLLHUP 或 POLLNVAL revents,poll 是否会返回 -1?

标签 c posix

来自民意调查手册页:

The bits returned in revents can include any of those specified in events, or one of the values POLLERR, POLLHUP, or POLLNVAL

返回值:

On success, a positive number is returned; this is the number of structures which have nonzero revents fields (in other words, those descriptors with events or errors reported). A value of 0 indicates that the call timed out and no file descriptors were ready. On error, -1 is returned, and errno is set appropriately.

如果 poll 在 revents 中设置了 POLLERR、POLLHUP 或 POLLNVAL 之一,这是否意味着 poll 函数将返回 -1?如果不是,poll什么时候会返回-1?

我的猜测是否定的,因为返回值解释中的第一句话是返回是具有非零 revents 字段的结构的数量。因此,如果设置了 POLLERR,则至少有 1 个具有非零 revents 的结构。

最佳答案

If poll sets one of POLLERR, POLLHUP, or POLLNVAL in revents, does this mean that the poll function will return -1?

没有。如果 poll() 设置任何 revents 值,那么它将返回 >0 来表明这一点。然后,您必须检查各个项目以查看哪些项目分配了 revents 值。

If not, when will poll return -1?

poll() 仅当 poll() 本身失败时返回 -1,而不是在任何被轮询的项目失败时返回。

关于c - 如果设置了任何 POLLERR、POLLHUP 或 POLLNVAL revents,poll 是否会返回 -1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22890021/

相关文章:

c - 如何分配要存储到数组中的用户输入

c - Linux 中的 malloc 错误,相同的代码在 Mac OS X 上运行良好

c - 使用文件中的 OpenSSL 设置私钥和公钥 EC key

c - C中线程的内存访问

c - fopen() 接受的参数格式是什么

c - POSIX 计时器 : Signal Handler for Timer freezes

unix - 从父进程中分 ionic 进程

c - 为什么 pcap_next_ex 的第三个参数是不兼容的指针类型?

c - 读取可能包含换行符的标准输入的最佳方式?

C-孙子进程