NZMQT_INLINE void PollingZMQContext::run() { if (m_stopped) return; try { poll(); } catch (const ZMQException& ex) { qWarning("Exception during poll: %s", ex.what()); emit pollError(ex.num(), ex.what()); } if (!m_stopped) QTimer::singleShot(m_interval, this, &PollingZMQContext::run); }
void LongPollManager::handlePollFinished () { auto reply = qobject_cast<QNetworkReply*> (sender ()); reply->deleteLater (); if (reply->error () != QNetworkReply::NoError) { ++PollErrorCount_; qWarning () << Q_FUNC_INFO << "network error:" << reply->error () << reply->errorString () << "; error count:" << PollErrorCount_; switch (reply->error ()) { case QNetworkReply::RemoteHostClosedError: { const auto diff = LastPollDT_.secsTo (QDateTime::currentDateTime ()); const auto newTimeout = std::max ((diff + WaitTimeout_) / 2 - 1, 5); qWarning () << Q_FUNC_INFO << "got timeout with" << WaitTimeout_ << diff << "; new timeout:" << newTimeout; WaitTimeout_ = newTimeout; break; } default: if (PollErrorCount_ == 4) emit pollError (); break; } Poll (); return; } else if (PollErrorCount_) { qDebug () << Q_FUNC_INFO << "finally successful network reply after" << PollErrorCount_ << "errors"; PollErrorCount_ = 0; emit listening (); } const auto& data = QJson::Parser ().parse (reply); const auto& rootMap = data.toMap (); if (rootMap.contains ("failed")) { ForceServerRequery (); start (); return; } emit gotPollData (rootMap); LPTS_ = rootMap ["ts"].toULongLong (); if (!ShouldStop_) { if (!LPServer_.isEmpty ()) Poll (); else start (); } else emit stopped (); }