Added exponential backoff when errors occur in sicspoll
This commit is contained in:
38
sicspoll.c
38
sicspoll.c
@ -9,6 +9,11 @@
|
||||
* Copyright: see COPYRIGHT
|
||||
*
|
||||
* Mark Koennecke, November-December 2006
|
||||
*
|
||||
* Implemented exponential backoff up to 6 minutes when polling fails. This in order to
|
||||
* reduce the number of error messages in the logs if something is MIA
|
||||
*
|
||||
* Mark Koennecke, November 2016
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -109,7 +114,33 @@ void SicsPollSignal(void *pData, int iSignal, void *pSigData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
This function implements the exponential backoff when there is a failure
|
||||
in polling
|
||||
------------------------------------------------------------------------*/
|
||||
static void advancePoll(pPollDriv poll, int status)
|
||||
{
|
||||
if(status == 1) {
|
||||
/* success */
|
||||
poll->actualPollIntervall = poll->pollIntervall;
|
||||
} else {
|
||||
/*
|
||||
poll error, backoff
|
||||
*/
|
||||
if(poll->actualPollIntervall < poll->pollIntervall){
|
||||
poll->actualPollIntervall = 2 * poll->pollIntervall;
|
||||
} else {
|
||||
poll->actualPollIntervall = 2 * poll->actualPollIntervall;
|
||||
/*
|
||||
poll at least every 6 minutes
|
||||
*/
|
||||
if(poll->actualPollIntervall > 360){
|
||||
poll->actualPollIntervall = 360;
|
||||
}
|
||||
}
|
||||
}
|
||||
poll->nextPoll = time(NULL) + poll->actualPollIntervall;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int PollTask(void *data)
|
||||
{
|
||||
@ -141,7 +172,8 @@ static int PollTask(void *data)
|
||||
poll = (pPollDriv) LLDnodePtr(self->pollList);
|
||||
if (status != 0 && poll != NULL) {
|
||||
if (poll->isDue(poll, now, self->pCon)) {
|
||||
poll->poll(poll, self->pCon);
|
||||
status = poll->poll(poll, self->pCon);
|
||||
advancePoll(poll,status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,6 +344,7 @@ int SICSPollWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
driv->pollIntervall = iVal;
|
||||
driv->actualPollIntervall = iVal;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} else {
|
||||
@ -346,6 +379,7 @@ int SICSPollWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
status = driv->poll(driv, pCon);
|
||||
advancePoll(driv,status);
|
||||
if (status != 1) {
|
||||
SCWrite(pCon, "ERROR: polling object", eError);
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user