当应用程序正在运行时,如果没有发生IO事件,poll将在超时'指定的时间段后超时。 (如预期的那样)
然而,当回到forground时(在后台暂停一段时间后),poll会立即返回w / o等待指定的超时时间。
深入挖掘,似乎如果应用程序在后台,例如。 20秒,poll立即返回累计超时总和20秒,然后继续正常运行(按预期超时)。
我的代码可能会出错吗?有没有办法避免这种行为?
我已经应用了以下解决方法,虽然我真的希望以正确的方式解决它,因为这种解决方法可能最终会让我在后面咬我......
#ifdef TARGET_OS_IPHONE
// NOTE: The following code is used to cope with a suspected iOS bug, future iOS versions might have that fixed, once this
// is fixed the code will adversly affect performance by causing poll to really wait for a duration in the amount of time
// the app was in the background
if ((tNow - tLast) > ((int64_t)iWaitPeriod * 2)) {
// iOS use-case, we have been brougth back from the backgound
poll((pollfd*)m_pIOCPHandles, 0, tNow - tLast);// Account for the hibernation duration
LOGTRACE(Collections, "IOCompletionPort::DoModal(), accounting for %.1f seconds of hibernation.\n", (tNow - tLast) / 1000.0f);
}
#endif