Skip to content

Commit

Permalink
Avoid heartbeats during termination
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiohs84 committed Jul 31, 2017
1 parent 35ff258 commit 3eaeba7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/chatClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ void Client::heartbeat()
Client::~Client()
{
if (mHeartbeatTimer)
{
karere::cancelInterval(mHeartbeatTimer);
mHeartbeatTimer = 0;
}
//when the strophe::Connection is destroyed, its handlers are automatically destroyed
}

Expand Down Expand Up @@ -724,8 +727,19 @@ promise::Promise<void> Client::doConnect(Presence pres)
setConnState(kDisconnected);
});
assert(!mHeartbeatTimer);
mHeartbeatTimer = karere::setInterval([this]()
auto wptr = weakHandle();
mHeartbeatTimer = karere::setInterval([this, wptr]()
{
if (wptr.deleted())
{
return;
}

if (!mHeartbeatTimer)
{
return;
}

heartbeat();
}, 10000);
return pms;
Expand Down

0 comments on commit 3eaeba7

Please sign in to comment.