| 35 | } |
| 36 | |
| 37 | void NetScheduler::rearm() |
| 38 | { |
| 39 | m_timer.stop(); |
| 40 | const QDateTime now = nowUtc(); |
| 41 | |
| 42 | // Prune fired keys for occurrences now safely in the past. |
| 43 | for (auto it = m_firedKeys.begin(); it != m_firedKeys.end();) { |
| 44 | const qint64 occMs = it->section('|', 1).toLongLong(); |
| 45 | if (occMs < now.toMSecsSinceEpoch() - 60000) |
| 46 | it = m_firedKeys.erase(it); |
| 47 | else |
| 48 | ++it; |
| 49 | } |
| 50 | |
| 51 | m_armed = nextReminderAcross(m_entries, now); |
| 52 | if (!m_armed.isValid()) |
| 53 | return; |
| 54 | |
| 55 | const qint64 ms = now.msecsTo(m_armed.reminderUtc); |
| 56 | const qint64 sleep = qBound<qint64>(0, ms, kMaxSleepMs) + kArmGuardMs; |
| 57 | m_timer.start(static_cast<int>(qMin<qint64>(sleep, kMaxSleepMs + kArmGuardMs))); |
| 58 | } |
| 59 | |
| 60 | void NetScheduler::onTimeout() |
| 61 | { |