Skip to content

Commit

Permalink
Merge pull request #307 from redboltz/fix_301
Browse files Browse the repository at this point in the history
Fixed #301.
  • Loading branch information
redboltz authored Jun 29, 2019
2 parents 8ec8032 + 727eb12 commit dd67cc7
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,13 +3228,17 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
* Properties<BR>
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145<BR>
* 3.6.2.2 PUBREL Properties
* @param life_keeper
* An object that stays alive (but is moved with std::move()) until the async operation is finished.
* @param
*/
void pubrel(
packet_id_t packet_id,
mqtt::optional<std::uint8_t> reason_code = mqtt::nullopt,
std::vector<v5::property_variant> props = {}
std::vector<v5::property_variant> props = {},
mqtt::any life_keeper = mqtt::any()
) {
send_pubrel(packet_id, reason_code, std::move(props));
send_pubrel(packet_id, reason_code, std::move(props), std::move(life_keeper));
}

/**
Expand Down Expand Up @@ -6974,7 +6978,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
* @param packet_id packet id corresponding to publish
* @param func
* functor object who's operator() will be called when the async operation completes.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718043
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718043
*/
void async_pubrel(
packet_id_t packet_id,
Expand All @@ -6996,15 +7000,18 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
* 3.6.2.2 PUBREL Properties
* @param func
* functor object who's operator() will be called when the async operation completes.
* @param life_keeper
* An object that stays alive (but is moved with std::move()) until the async operation is finished.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718043
*/
void async_pubrel(
packet_id_t packet_id,
std::uint8_t reason_code,
std::vector<v5::property_variant> props,
async_handler_t func = async_handler_t()
async_handler_t func = async_handler_t(),
mqtt::any life_keeper = mqtt::any()
) {
async_send_pubrel(packet_id, reason_code, std::move(props), std::move(func));
async_send_pubrel(packet_id, reason_code, std::move(props), std::move(func), std::move(life_keeper));
}

/**
Expand Down Expand Up @@ -8914,7 +8921,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
else store_pubrel(packet_id);
},
[this, &packet_id, &func] {
if (connected_) async_send_pubrel(packet_id, mqtt::nullopt, std::vector<v5::property_variant>{}, func);
if (connected_) async_send_pubrel(packet_id, mqtt::nullopt, std::vector<v5::property_variant>{}, func, mqtt::any());
else store_pubrel(packet_id);
}
);
Expand Down Expand Up @@ -9636,7 +9643,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
void send_pubrel(
packet_id_t packet_id,
mqtt::optional<std::uint8_t> reason = mqtt::nullopt,
std::vector<v5::property_variant> props = {}
std::vector<v5::property_variant> props = {},
mqtt::any life_keeper = mqtt::any()
) {

auto impl =
Expand All @@ -9650,7 +9658,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
auto ret = store_.emplace(
packet_id,
control_packet_type::pubcomp,
msg
msg,
std::move(life_keeper)
);
BOOST_ASSERT(ret.second);
}
Expand Down Expand Up @@ -10195,7 +10204,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
packet_id_t packet_id,
mqtt::optional<std::uint8_t> reason,
std::vector<v5::property_variant> props,
async_handler_t func
async_handler_t func,
mqtt::any life_keeper
) {

auto msg = basic_pubrel_message<PacketIdBytes>(packet_id);
Expand Down Expand Up @@ -10226,7 +10236,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
e = store(
packet_id,
control_packet_type::pubcomp,
msg
msg,
life_keeper
);
}
);
Expand All @@ -10236,7 +10247,12 @@ class endpoint : public std::enable_shared_from_this<endpoint<Socket, Mutex, Loc
if (serialize) {
serialize(msg);
}
do_async_write(std::move(msg), std::move(func));
do_async_write(
std::move(msg),
[life_keeper = std::move(life_keeper), func = std::move(func)](boost::system::error_code const& ec) {
if (func) func(ec);
}
);
};

switch (version_) {
Expand Down

0 comments on commit dd67cc7

Please sign in to comment.