linux中投票系统调用的错误行为
Incorrect behaviour of poll system call in linux
在使用poll系统调用时,我发现了一个奇怪的行为。我有下面的代码片段:
struct pollfd myPollfds[nCount];
ACE_Time_Value selectTime;
selectTime.set(60);
myPollfds[0].fd = rtrrmEvent[0];
myPollfds[0].events = POLLIN | POLLRDHUP | POLLHUP | POLLERR;
myPollfds[0].revents = 0;
myPollfds[1].fd = rtrfeEvent[0];
myPollfds[1].events = POLLIN | POLLRDHUP | POLLHUP | POLLERR;
myPollfds[1].revents = 0;
myPollfds[2].fd = _h[msclient_pos];
myPollfds[2].events = POLLIN | POLLRDHUP | POLLHUP | POLLERR;
myPollfds[2].revents = 0;
myPollfds[3].fd = holdTimeEvent[0];
myPollfds[3].events = POLLIN | POLLRDHUP | POLLHUP | POLLERR;
myPollfds[3].revents = 0;
ACE_Time_Value sleepTime(0,20000);
while(isRunning() && !_stopRequested)
{
ACE_OS::sleep(sleepTime);
for(int i = 0; i < 4; i++)
myPollfds[i].revents = 0;
waitResult = ACE_OS::poll (myPollfds, nCount, &selectTime);
if(waitResult == -1) // poll failed
{
DEBUG("%s", "poll failed");
continue;
}
else if(waitResult == 0) // Time out
{
//Do something .
}
char nodata[256];
for(short i = 0; i < nCount; i++)
if(myPollfds[i].revents == POLLIN)
{
if(i == rtrrm_pos)
{
// Stop channel
}
else if(i == rtrfe_pos) // 'rtrfe' command
{
DEBUG("%s", "fe issued");
}
else if(i == msclient_pos || waitResult == 0)
{
//Do something
}
else if(i == holdTime_pos)
{
DEBUG("%s", "Hold issued");
}
}
else
{
DEBUG("polling failed with with myPollfds[i].revents == %d",myPollfds[i].revents);
}
问题是,我得到一些时间:"使用myPollfds进行的民意调查失败了。事件== 0":"使用myPollfds进行的民意调查失败了。 轮询调用没有等待fd的设置。有人能帮忙吗?
这个测试是错误的:
if(myPollfds[i].revents == POLLIN)
它可能应该是(不能确定,因为你删除了所有的逻辑):
if((myPollfds[i].revents & POLLIN) != 0)
同样,看到"轮询失败"消息是完全正常的。它只是意味着在那个特定的文件描述符上没有活动。你在轮询不止一个描述符,对吧?所以有些人没有活动是正常的
正如David所说,
"轮询失败"消息是完全正常的。
在任何情况下,当poll返回的不仅仅是POLLIN时例如:
poll ... = 1
{fd=8193, revents=POLLIN|**POLLHUP**}
if (POLLIN|POLLHUP == POLLIN)
将进入"else"子句。
我的C语言不太好,所以我不知道David的if语句是否正确
相关文章:
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 错误:调用'getline'没有匹配函数
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?
- 可能的Qt5错误:调用setFixedSize()禁用主窗口的关闭按钮(在Win7下)
- 如何将C++系统调用连接到 freertos
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 错误:调用"es_queue::set_rpc_vector(std::vector >&, std::__cxx11::string)"没有匹配函数
- 错误:调用'strcmp'没有匹配函数(尝试设置显示用户信息功能)
- Boost Json 写入错误:调用 'boost::p roperty_tree::basic_ptree<std::__cxx11
- 第 5 行:字符 54:错误:调用"min(int,std::__cxx11::basic_string<char>::size_type)"没有匹配函数
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- 错误:调用'function namel'没有匹配函数
- 系统调用:一次和多次,哪个更好?
- 使用路径和空格的系统调用
- Valgrind 错误:系统调用参数 epoll_pwait(sigmask) 指向不可寻址的字节
- 系统错误122-调用WriteMsgQueue()时出现Error_INSUFFIENT_BUFFER
- Qt:如何捕获系统调用的错误
- linux中投票系统调用的错误行为
- C++:系统调用重新启动 ntpd ->错误的端口
- Netbeans 显示 unix 系统调用错误"getcontext"