Skip to content

Commit

Permalink
Added topic_alias_maximum for CONNACK.
Browse files Browse the repository at this point in the history
  • Loading branch information
redboltz committed Jul 17, 2021
1 parent 7560912 commit 53a2c81
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8858,21 +8858,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
break;
case protocol_version::v5:
if (auto ta_max = get_topic_alias_maximum_from_props(props)) {
if (ta_max.value() == 0) {
topic_alias_recv_ = nullopt;
}
else {
topic_alias_recv_.emplace(ta_max.value());
}
}
else {
if (topic_alias_recv_&& topic_alias_recv_.value().max() != 0) {
props.emplace_back(
MQTT_NS::v5::property::topic_alias_maximum(topic_alias_recv_.value().max())
);
}
}
update_topic_alias_maximum_recv(props);
do_sync_write(
v5::connect_message(
keep_alive_sec,
Expand Down Expand Up @@ -8906,6 +8892,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
break;
case protocol_version::v5:
update_topic_alias_maximum_recv(props);
do_sync_write(
v5::connack_message(
session_present,
Expand Down Expand Up @@ -9540,21 +9527,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
break;
case protocol_version::v5:
if (auto ta_max = get_topic_alias_maximum_from_props(props)) {
if (ta_max.value() == 0) {
topic_alias_recv_ = nullopt;
}
else {
topic_alias_recv_.emplace(ta_max.value());
}
}
else {
if (topic_alias_recv_&& topic_alias_recv_.value().max() != 0) {
props.emplace_back(
MQTT_NS::v5::property::topic_alias_maximum(topic_alias_recv_.value().max())
);
}
}
update_topic_alias_maximum_recv(props);
do_async_write(
v5::connect_message(
keep_alive_sec,
Expand Down Expand Up @@ -9591,6 +9564,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
break;
case protocol_version::v5:
update_topic_alias_maximum_recv(props);
do_async_write(
v5::connack_message(
session_present,
Expand Down Expand Up @@ -10277,6 +10251,24 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
}

void update_topic_alias_maximum_recv(v5::properties& props) {
if (auto ta_max = get_topic_alias_maximum_from_props(props)) {
if (ta_max.value() == 0) {
topic_alias_recv_ = nullopt;
}
else {
topic_alias_recv_.emplace(ta_max.value());
}
}
else {
if (topic_alias_recv_&& topic_alias_recv_.value().max() != 0) {
props.emplace_back(
MQTT_NS::v5::property::topic_alias_maximum(topic_alias_recv_.value().max())
);
}
}
}

static optional<topic_alias_t> get_topic_alias_maximum_from_prop(v5::property_variant const& prop) {
optional<topic_alias_t> val;
MQTT_NS::visit(
Expand Down

0 comments on commit 53a2c81

Please sign in to comment.