-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporing PINGREQ from gateway to client when no data from client for…
… too long.
- Loading branch information
Showing
21 changed files
with
303 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright 2016 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "Ping.h" | ||
|
||
#include <cassert> | ||
|
||
namespace cc_mqttsn_gateway | ||
{ | ||
|
||
namespace session_op | ||
{ | ||
|
||
Ping::Ping(SessionImpl& session) : | ||
Base(session) | ||
{ | ||
} | ||
|
||
Ping::~Ping() = default; | ||
|
||
void Ping::tickImpl() | ||
{ | ||
sendPing(); | ||
} | ||
|
||
void Ping::connStatusUpdatedImpl() | ||
{ | ||
restartPingTimer(); | ||
} | ||
|
||
void Ping::handle([[maybe_unused]] MqttsnMessage& msg) | ||
{ | ||
restartPingTimer(); | ||
} | ||
|
||
void Ping::sendPing() | ||
{ | ||
auto& st = state(); | ||
|
||
if (st.m_retryCount <= m_attempt) { | ||
termRequest(); | ||
return; | ||
} | ||
|
||
++m_attempt; | ||
sendToClient(PingreqMsg_SN()); | ||
nextTickReq(st.m_retryPeriod); | ||
} | ||
|
||
void Ping::restartPingTimer() | ||
{ | ||
auto& st = state(); | ||
if (st.m_connStatus != ConnectionStatus::Connected) { | ||
cancelTick(); | ||
return; | ||
} | ||
|
||
m_attempt = 0U; | ||
assert(0U < st.m_keepAlive); | ||
auto nextPingTick = (st.m_keepAlive * 1000); | ||
nextTickReq(nextPingTick); | ||
} | ||
|
||
} // namespace session_op | ||
|
||
} // namespace cc_mqttsn_gateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Copyright 2016 - 2024 (C). Alex Robenko. All rights reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "SessionOp.h" | ||
#include "common.h" | ||
|
||
namespace cc_mqttsn_gateway | ||
{ | ||
|
||
namespace session_op | ||
{ | ||
|
||
class Ping final : public SessionOp | ||
{ | ||
typedef SessionOp Base; | ||
|
||
public: | ||
explicit Ping(SessionImpl& session); | ||
~Ping(); | ||
|
||
void clientConnected(); | ||
|
||
protected: | ||
virtual void tickImpl() override; | ||
virtual void connStatusUpdatedImpl() override; | ||
|
||
private: | ||
using Base::handle; | ||
virtual void handle(MqttsnMessage& msg) override; | ||
|
||
void sendPing(); | ||
void restartPingTimer(); | ||
|
||
unsigned m_attempt = 0; | ||
}; | ||
|
||
} // namespace session_op | ||
|
||
} // namespace cc_mqttsn_gateway | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.