我正在运行 cygwin 并使用 pselect 来监视子进程的套接字和文件描述符。
根据我在这里找到的一些示例http://www.linuxprogrammingblog.com/code-examples/using-pselect-to-avoid-a-signal-race并且手册页 pselect 应该返回设置的文件描述符的数量掩码字段(http://linux.die.net/man/2/pselect)。
现在,当我连接到我的服务器时,pselect 返回,这很好。但是当我使用 FD_ISSET 测试文件描述符时,它们总是返回 true:
FD_ZERO(&readers);
FD_ZERO(&writers);
FD_ZERO(&exceptions);
FD_SET(fileno(stdin), &readers);
FD_SET(socket, &readers);
pret = pselect(FD_SETSIZE, &readers, &writers, &exceptions, NULL, &mSignalMask);
, &readers, &writers, &exceptions, NULL, &mSignalMask);
if(pret <= 0)
{
// ignore for now
continue;
}
if(FD_ISSET(fileno(stdin), &readers))
{
string s;
cin >> s;
cout << "stdin: " << s << endl; // blocks because the code always gets here even when
// pselect returns because of a childsignal without any data.
continue;
}
if(FD_ISSET(socket, &readers))
{
accept(); // blocks because the code always gets here even when
// pselect returns because of a childsignal without any data.
cout << "task created connection from " <<task->getClientHost() << endl;
continue;
}