本文整理汇总了C++中FileHandle::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ FileHandle::poll方法的具体用法?C++ FileHandle::poll怎么用?C++ FileHandle::poll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandle
的用法示例。
在下文中一共展示了FileHandle::poll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: poll
// timeout -1 forever, or milliseconds
int poll(pollfh fhs[], unsigned nfhs, int timeout)
{
/**
* TODO Proper wake-up mechanism.
* In order to correctly detect availability of read/write a FileHandle, we needed
* a select or poll mechanisms. We opted for poll as POSIX defines in
* http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html Currently,
* mbed::poll() just spins and scans filehandles looking for any events we are
* interested in. In future, his spinning behaviour will be replaced with
* condition variables.
*/
Timer timer;
if (timeout > 0) {
timer.start();
}
int count = 0;
for (;;) {
/* Scan the file handles */
for (unsigned n = 0; n < nfhs; n++) {
FileHandle *fh = fhs[n].fh;
short mask = fhs[n].events | POLLERR | POLLHUP | POLLNVAL;
if (fh) {
fhs[n].revents = fh->poll(mask) & mask;
} else {
fhs[n].revents = POLLNVAL;
}
if (fhs[n].revents) {
count++;
}
}
if (count) {
break;
}
/* Nothing selected - this is where timeout handling would be needed */
if (timeout == 0 || (timeout > 0 && timer.read_ms() > timeout)) {
break;
}
#ifdef MBED_CONF_RTOS_PRESENT
// TODO - proper blocking
// wait for condition variable, wait queue whatever here
rtos::Thread::wait(1);
#endif
}
return count;
}