libevhandler only checks for heartbeats if not overridden by user

This commit is contained in:
Emiel Bruijntjes 2018-11-12 22:07:48 +01:00
parent 888dc8c40b
commit 549fec5cb1
1 changed files with 12 additions and 0 deletions

View File

@ -189,6 +189,12 @@ private:
*/ */
ev_tstamp _expire; ev_tstamp _expire;
/**
* Are heartbeats enabled?
* @var bool
*/
bool _enabled = false;
/** /**
* Interval between heartbeats * Interval between heartbeats
* @var uint16_t * @var uint16_t
@ -216,6 +222,9 @@ private:
*/ */
virtual void onExpired() override virtual void onExpired() override
{ {
// do nothing if heartbeats are not enabled
if (!_enabled) return;
// get the current time // get the current time
ev_tstamp now = ev_now(_loop); ev_tstamp now = ev_now(_loop);
@ -313,6 +322,9 @@ private:
*/ */
uint16_t start() uint16_t start()
{ {
// remember that heartbeats are enabled
_enabled = true;
// expose the interval (the timer is already running, so we do not have to explicitly start it) // expose the interval (the timer is already running, so we do not have to explicitly start it)
return _interval; return _interval;
} }