mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-15 19:22:45 +03:00
polledTimeout: add option to use CPU count instead of millis() (#5870)
* polledTimeout: add option to use CPU count instead of millis() * use more "using" alias * more c++/clear code, using typename (thanks @devyte) * rename class name to include unit, introduce timeMax() and check it with assert() * remove useless defines * improve api readability, add micro-second unit * update example * mock: emulate getCycleCount, add/fix polledTimeout CI test * + nano-seconds, assert -> message, comments, host test * allow 0 for timeout (enables immediate timeout, fix division by 0) * typo, set member instead of local variable * unify error message * slight change on checkExpired() allows "never expired" also removed printed message, add YieldAndDelay, simplify calculations * remove traces of debug.h/cpp in this PR * include missing <limits> header * back to original expired test, introduce boolean _neverExpires, fix reset(), getTimeout() is invalid * fix expiredOneShot with _timeout==0 check * reenable getTimeout() * expose checkExpired with unit conversion * fix timing comments, move critical code to iram * add member ::neverExpires and use it where relevant * improve clarity * remove exposed checkExpired(), adapt LEAmDNS with equivalent * add API ::resetToNeverExpires(), use it in LEAmDNS * remove offending constness from ::flagged() LEAmDNS (due do API fix in PolledTimeout) * simplify "Fast" base classes * minor variable rename * Fix examples * compliance with good c++ manners * minor changes for consistency * add missing const * expired() and bool() moved to iram * constexpr compensation computing * add/update comments * move neverExpires and alwaysExpired
This commit is contained in:
@@ -1159,7 +1159,7 @@ bool MDNSResponder::stcMDNS_RRAnswerGeneric::clear(void) {
|
||||
MDNSResponder::stcProbeInformation::stcProbeInformation(void)
|
||||
: m_ProbingStatus(ProbingStatus_WaitingForData),
|
||||
m_u8SentCount(0),
|
||||
m_Timeout(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max()),
|
||||
m_Timeout(esp8266::polledTimeout::oneShotMs::neverExpires),
|
||||
m_bConflict(false),
|
||||
m_bTiebreakNeeded(false),
|
||||
m_fnHostProbeResultCallback(0),
|
||||
@@ -1173,7 +1173,7 @@ bool MDNSResponder::stcProbeInformation::clear(bool p_bClearUserdata /*= false*/
|
||||
|
||||
m_ProbingStatus = ProbingStatus_WaitingForData;
|
||||
m_u8SentCount = 0;
|
||||
m_Timeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
|
||||
m_Timeout.resetToNeverExpires();
|
||||
m_bConflict = false;
|
||||
m_bTiebreakNeeded = false;
|
||||
if (p_bClearUserdata) {
|
||||
@@ -1421,7 +1421,7 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::isOutdated(void) con
|
||||
*/
|
||||
MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::stcTTL(void)
|
||||
: m_u32TTL(0),
|
||||
m_TTLTimeout(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max()),
|
||||
m_TTLTimeout(esp8266::polledTimeout::oneShotMs::neverExpires),
|
||||
m_timeoutLevel(TIMEOUTLEVEL_UNSET) {
|
||||
|
||||
}
|
||||
@@ -1438,7 +1438,7 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::set(uint32_t p_u32TT
|
||||
}
|
||||
else {
|
||||
m_timeoutLevel = TIMEOUTLEVEL_UNSET; // undef
|
||||
m_TTLTimeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
|
||||
m_TTLTimeout.resetToNeverExpires();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1446,11 +1446,11 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::set(uint32_t p_u32TT
|
||||
/*
|
||||
* MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::flagged
|
||||
*/
|
||||
bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::flagged(void) const {
|
||||
bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::flagged(void) {
|
||||
|
||||
return ((m_u32TTL) &&
|
||||
(TIMEOUTLEVEL_UNSET != m_timeoutLevel) &&
|
||||
(m_TTLTimeout.checkExpired(millis())));
|
||||
(m_TTLTimeout.expired()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1468,7 +1468,7 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::restart(void) {
|
||||
}
|
||||
else {
|
||||
bResult = false;
|
||||
m_TTLTimeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
|
||||
m_TTLTimeout.resetToNeverExpires();
|
||||
m_timeoutLevel = TIMEOUTLEVEL_UNSET;
|
||||
}
|
||||
return bResult;
|
||||
@@ -1498,7 +1498,7 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::finalTimeoutLevel(vo
|
||||
*/
|
||||
unsigned long MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::timeout(void) const {
|
||||
|
||||
uint32_t u32Timeout = std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max();
|
||||
uint32_t u32Timeout = esp8266::polledTimeout::oneShotMs::neverExpires;
|
||||
|
||||
if (TIMEOUTLEVEL_BASE == m_timeoutLevel) { // 80%
|
||||
u32Timeout = (m_u32TTL * 800); // to milliseconds
|
||||
@@ -1922,7 +1922,7 @@ MDNSResponder::stcMDNSServiceQuery::stcMDNSServiceQuery(void)
|
||||
m_fnCallback(0),
|
||||
m_bLegacyQuery(false),
|
||||
m_u8SentCount(0),
|
||||
m_ResendTimeout(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max()),
|
||||
m_ResendTimeout(esp8266::polledTimeout::oneShotMs::neverExpires),
|
||||
m_bAwaitingAnswers(true),
|
||||
m_pAnswers(0) {
|
||||
|
||||
@@ -1945,7 +1945,7 @@ bool MDNSResponder::stcMDNSServiceQuery::clear(void) {
|
||||
m_fnCallback = 0;
|
||||
m_bLegacyQuery = false;
|
||||
m_u8SentCount = 0;
|
||||
m_ResendTimeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
|
||||
m_ResendTimeout.resetToNeverExpires();
|
||||
m_bAwaitingAnswers = true;
|
||||
while (m_pAnswers) {
|
||||
stcAnswer* pNext = m_pAnswers->m_pNext;
|
||||
|
Reference in New Issue
Block a user