int rc = poll(fds, 1, -1); 假设远程对等点出现故障。套接字在这里中断。 在这种情况下 poll 系统调用会返回 -1 或 将返回 > 0 并将断开连接报告为 FD 上的错误事件。
此外,轮询在 0 超时时会返回什么。 int rc = poll(fds, nfds, 0);
不,没有。它只知道套接字上发生了某些事情,以及是读取事件、写入事件还是错误事件。对等断开连接算作读取事件。
来自man页面:
字段 revents 是一个输出参数,由内核用事件填充 这确实发生了。 revents 中返回的位可以包括以下任何一个 在事件中指定,或者值 POLLERR、POLLHUP 或 POLLNVAL 之一。 (这三位在事件字段中无意义,将在 每当相应的条件为真时,revent 字段。)
If none of the events requested (and no error) has occurred for any of the file
descriptors, then poll() blocks until one of the events occurs.
Return Value
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.
所以,它清楚地表明,如果 FD 中存在错误,则返回值 > 0,并且 revents 字段将填充适当的值。例如 POLLERR。