c++ - errorfds vs select 返回值,然后 select() 立即返回?
问题描述
我来维护一个软件,它可以:
/*... init, setting timeout, etc ... */
FD_ZERO(&set);
FD_SET(socket_, &set);
int selectRes = select(socket_ + 1, &set, NULL, NULL, &timeout);
if (selectRes < 0) {
throw IoException("Select: ", errno);
}
if (selectRes == 0) {
throw TimeoutException();
}
/* ... then handle recvfrom, throw IoException if return < 0 ... */
IoException 应该导致程序终止。超时异常恢复操作。无异常循环返回。socket_ 是一个 UNIX 数据报套接字(从另一个本地进程读取消息)。
This program runs at very high priority (required to react to messages quickly) but it's expected to be idle most of the time, hanging on select()'s timeout waiting for incoming messages. Meanwhile, it seems like it sometimes hogs 100% of CPU time (without receiving enough messages to grant such behavior). The occurrence is rather erratic, never mind the program's high priority makes debugging it very hard (a small single-core Linux embedded system, everything else grinds to a halt).
I'm worried about the NULL in the errorfds position - is testing the return value of select() enough in this case, or may select() return immediately (with 0) if there's an error condition on the socket but errorfds is NULL, and keep repeating doing so every time it loops back to select()?
或者,除了大量消息之外,还有哪些其他情况可以使 select() 立即退出(或者可能在自旋锁中等待而不是释放 CPU 时间)?
解决方案
推荐阅读
- python - 烧瓶静态图像未加载
- php - 如何更新 id 在数组中的所有行?
- azure - 将数组作为参数提供给 devops 管道
- javascript - JSON文件可以获取自己的路径(访问自己的属性)吗?
- docusignapi - 获取签名者详细信息、文档签名 URL、选择退出请求的请求结构
- ada - 多态类型的函数参数的深层副本
- java - 如果 CSV 项目不在引号中,如何引发异常
- node.js - 有效 METHOD 参数上带有“未指定方法”的 PayPal 错误(错误代码 81002)
- python - 如何将多个数据框保存到 xlsx 中的多个工作表中
- java - Java 原生包要求