在使用 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[i].revents == 0”:“轮询失败,myPollfds[i].revents == 8193”
轮询呼叫不等待 fd 设置。有人可以帮忙吗?