-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TopicAlias lifetime is the same as Session lifetime It is different from MQTT v5 spec but practical choice. See https://lists.oasis-open.org/archives/mqtt-comment/202009/msg00000.html Related fix: When topic is empty and no topic alias entry is found, then protocol_error. The broker send DISCONNECT packet with protocol_error reason code. process_disconnect implementation was simply doesn't call `on_mqtt_message_processed()` but it was bad. It caused exit from ioc.run() loop because the next async_read was not called. The correct behavior is calling `on_mqtt_message_processed()` and close socket. The endpoint can detect the socket close by on_error(). Fixed topic alias.
- Loading branch information
Showing
26 changed files
with
1,021 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright Takatoshi Kondo 2020 | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#if !defined(MQTT_TOPIC_ALIAS_RECV_HPP) | ||
#define MQTT_TOPIC_ALIAS_RECV_HPP | ||
|
||
#include <string> | ||
#include <map> | ||
#include <array> | ||
|
||
#include <boost/multi_index_container.hpp> | ||
#include <boost/multi_index/ordered_index.hpp> | ||
#include <boost/multi_index/member.hpp> | ||
|
||
#include <mqtt/string_view.hpp> | ||
#include <mqtt/constant.hpp> | ||
#include <mqtt/type.hpp> | ||
#include <mqtt/log.hpp> | ||
|
||
namespace MQTT_NS { | ||
|
||
using topic_alias_recv_map_t = std::map<topic_alias_t, std::string>; | ||
|
||
inline void register_topic_alias(topic_alias_recv_map_t& m, string_view topic, topic_alias_t alias) { | ||
BOOST_ASSERT(alias > 0 && alias <= topic_alias_max); | ||
|
||
MQTT_LOG("mqtt_impl", info) | ||
<< MQTT_ADD_VALUE(address, &m) | ||
<< "register_topic_alias" | ||
<< " topic:" << topic | ||
<< " alias:" << alias; | ||
|
||
if (topic.empty()) { | ||
m.erase(alias); | ||
} | ||
else { | ||
m[alias] = std::string(topic); // overwrite | ||
} | ||
} | ||
|
||
inline std::string find_topic_by_alias(topic_alias_recv_map_t const& m, topic_alias_t alias) { | ||
BOOST_ASSERT(alias > 0 && alias <= topic_alias_max); | ||
|
||
std::string topic; | ||
auto it = m.find(alias); | ||
if (it != m.end()) topic = it->second; | ||
|
||
MQTT_LOG("mqtt_impl", info) | ||
<< MQTT_ADD_VALUE(address, &m) | ||
<< "find_topic_by_alias" | ||
<< " alias:" << alias | ||
<< " topic:" << topic; | ||
|
||
return topic; | ||
} | ||
|
||
inline void clear_topic_alias(topic_alias_recv_map_t& m) { | ||
MQTT_LOG("mqtt_impl", info) | ||
<< MQTT_ADD_VALUE(address, &m) | ||
<< "clear_topic_alias"; | ||
|
||
m.clear(); | ||
} | ||
|
||
} // namespace MQTT_NS | ||
|
||
#endif // MQTT_TOPIC_ALIAS_RECV_HPP |
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
Oops, something went wrong.