From 9c35c59d8111db578423ad9a5a99743a24f6b045 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Fri, 7 Oct 2022 18:45:03 +0900 Subject: [PATCH 1/5] Introduced move_only_function. --- .gitmodules | 3 + include/CMakeLists.txt | 2 +- include/mqtt/broker/broker.hpp | 52 +- include/mqtt/broker/session_state.hpp | 6 +- include/mqtt/broker/topic_filter.hpp | 1 + include/mqtt/callable_overlay.hpp | 95 +- include/mqtt/endpoint.hpp | 177 +-- include/mqtt/external/function2.hpp | 1829 +++++++++++++++++++++++++ include/mqtt/move_only_function.hpp | 30 + include/mqtt/null_strand.hpp | 72 +- include/mqtt/server.hpp | 73 +- include/mqtt/store.hpp | 5 +- include/mqtt/strand.hpp | 2 +- include/mqtt/tcp_endpoint.hpp | 17 +- include/mqtt/type_erased_socket.hpp | 13 +- include/mqtt/ws_endpoint.hpp | 21 +- test/system/st_offline.cpp | 4 +- test/system/st_pubsub_no_strand.cpp | 2 - update_external.sh | 4 + 19 files changed, 2180 insertions(+), 228 deletions(-) create mode 100644 include/mqtt/external/function2.hpp create mode 100644 include/mqtt/move_only_function.hpp create mode 100755 update_external.sh diff --git a/.gitmodules b/.gitmodules index e69de29bb..d2e779d0a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/function2"] + path = external/function2 + url = https://github.com/Naios/function2 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 73f704b6a..8c61721e2 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -64,7 +64,7 @@ ADD_LIBRARY(check_deps OBJECT EXCLUDE_FROM_ALL ${CHK_MQTT}) # We don't need to actually run the whole compiler. We're just checking that all the includes are valid # So here we ask for only the syntax checking mode to be used. # We also don't mind that there might be unused constant variables when doing deps checking. -TARGET_COMPILE_OPTIONS(check_deps PUBLIC -Wno-unused-const-variable $,/Zs,-fsyntax-only>) +TARGET_COMPILE_OPTIONS(check_deps PUBLIC -Wno-unneeded-internal-declaration -Wno-unused-const-variable $,/Zs,-fsyntax-only>) TARGET_LINK_LIBRARIES (check_deps PUBLIC ${PROJECT_NAME}) diff --git a/include/mqtt/broker/broker.hpp b/include/mqtt/broker/broker.hpp index 1299105f5..a326dfc03 100644 --- a/include/mqtt/broker/broker.hpp +++ b/include/mqtt/broker/broker.hpp @@ -721,43 +721,43 @@ class broker_t { pubcomp_props_ = force_move(props); } - void set_connect_props_handler(std::function h) { + void set_connect_props_handler(move_only_function h) { h_connect_props_ = force_move(h); } - void set_disconnect_props_handler(std::function h) { + void set_disconnect_props_handler(move_only_function h) { h_disconnect_props_ = force_move(h); } - void set_publish_props_handler(std::function h) { + void set_publish_props_handler(move_only_function h) { h_publish_props_ = force_move(h); } - void set_puback_props_handler(std::function h) { + void set_puback_props_handler(move_only_function h) { h_puback_props_ = force_move(h); } - void set_pubrec_props_handler(std::function h) { + void set_pubrec_props_handler(move_only_function h) { h_pubrec_props_ = force_move(h); } - void set_pubrel_props_handler(std::function h) { + void set_pubrel_props_handler(move_only_function h) { h_pubrel_props_ = force_move(h); } - void set_pubcomp_props_handler(std::function h) { + void set_pubcomp_props_handler(move_only_function h) { h_pubcomp_props_ = force_move(h); } - void set_subscribe_props_handler(std::function h) { + void set_subscribe_props_handler(move_only_function h) { h_subscribe_props_ = force_move(h); } - void set_unsubscribe_props_handler(std::function h) { + void set_unsubscribe_props_handler(move_only_function h) { h_unsubscribe_props_ = force_move(h); } - void set_auth_props_handler(std::function h) { + void set_auth_props_handler(move_only_function h) { h_auth_props_ = force_move(h); } @@ -1174,7 +1174,7 @@ class broker_t { bool session_present, bool authenticated, v5::properties props, - std::function finish = [](error_code){} + move_only_function finish = [](error_code){} ) { // Reply to the connect message. switch (ep.get_protocol_version()) { @@ -1184,7 +1184,7 @@ class broker_t { authenticated ? connect_return_code::accepted : connect_return_code::not_authorized, [finish = force_move(finish)] - (error_code ec) { + (error_code ec) mutable { finish(ec); } ); @@ -1201,7 +1201,7 @@ class broker_t { : v5::connect_reason_code::not_authorized, force_move(props), [finish = force_move(finish)] - (error_code ec) { + (error_code ec) mutable { finish(ec); } ); @@ -1214,7 +1214,7 @@ class broker_t { : v5::connect_reason_code::not_authorized, connack_props_, [finish = force_move(finish)] - (error_code ec) { + (error_code ec) mutable { finish(ec); } ); @@ -1792,7 +1792,7 @@ class broker_t { ); }; - std::vector> retain_deliver; + std::vector> retain_deliver; retain_deliver.reserve(entries.size()); // subscription identifier @@ -1906,7 +1906,7 @@ class broker_t { break; } - for (auto const& f : retain_deliver) { + for (auto& f : retain_deliver) { f(); } return true; @@ -2175,16 +2175,16 @@ class broker_t { v5::properties pubrec_props_; v5::properties pubrel_props_; v5::properties pubcomp_props_; - std::function h_connect_props_; - std::function h_disconnect_props_; - std::function h_publish_props_; - std::function h_puback_props_; - std::function h_pubrec_props_; - std::function h_pubrel_props_; - std::function h_pubcomp_props_; - std::function h_subscribe_props_; - std::function h_unsubscribe_props_; - std::function h_auth_props_; + move_only_function h_connect_props_; + move_only_function h_disconnect_props_; + move_only_function h_publish_props_; + move_only_function h_puback_props_; + move_only_function h_pubrec_props_; + move_only_function h_pubrel_props_; + move_only_function h_pubcomp_props_; + move_only_function h_subscribe_props_; + move_only_function h_unsubscribe_props_; + move_only_function h_auth_props_; bool pingresp_ = true; bool connack_ = true; }; diff --git a/include/mqtt/broker/session_state.hpp b/include/mqtt/broker/session_state.hpp index 6f0ab8ba6..7bcf2bc8e 100644 --- a/include/mqtt/broker/session_state.hpp +++ b/include/mqtt/broker/session_state.hpp @@ -52,7 +52,7 @@ class session_states; * Retained messages do not form part of the Session State in the Server, they are not deleted as a result of a Session ending. */ struct session_state { - using will_sender_t = std::function< + using will_sender_t = move_only_function< void( session_state const& source_ss, buffer topic, @@ -283,7 +283,7 @@ struct session_state { } } - void set_clean_handler(std::function handler) { + void set_clean_handler(move_only_function handler) { clean_handler_ = force_move(handler); } @@ -601,7 +601,7 @@ struct session_state { std::set qos2_publish_handled_; optional response_topic_; - std::function clean_handler_; + move_only_function clean_handler_; }; class session_states { diff --git a/include/mqtt/broker/topic_filter.hpp b/include/mqtt/broker/topic_filter.hpp index 055f0b80c..7c8e6eb5a 100644 --- a/include/mqtt/broker/topic_filter.hpp +++ b/include/mqtt/broker/topic_filter.hpp @@ -8,6 +8,7 @@ #define MQTT_BROKER_TOPIC_FILTER_HPP #include +#include #include #include diff --git a/include/mqtt/callable_overlay.hpp b/include/mqtt/callable_overlay.hpp index 0dbf03c65..01648fb5d 100644 --- a/include/mqtt/callable_overlay.hpp +++ b/include/mqtt/callable_overlay.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace MQTT_NS { template @@ -758,7 +759,7 @@ struct callable_overlay final : public Impl * 3.13 PINGREQ – PING request * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pingreq_handler = std::function; + using pingreq_handler = move_only_function; /** * @brief Pingresp handler @@ -766,7 +767,7 @@ struct callable_overlay final : public Impl * 3.13 PINGRESP – PING response * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pingresp_handler = std::function; + using pingresp_handler = move_only_function; // MQTT v3_1_1 handlers @@ -808,7 +809,7 @@ struct callable_overlay final : public Impl * @return if the handler returns true, then continue receiving, otherwise quit. * */ - using connect_handler = std::function< + using connect_handler = move_only_function< bool(buffer client_id, optional user_name, optional password, @@ -828,7 +829,7 @@ struct callable_overlay final : public Impl * 3.2.2.3 Connect Return code * @return if the handler returns true, then continue receiving, otherwise quit. */ - using connack_handler = std::function; + using connack_handler = move_only_function; /** * @brief Publish handler @@ -847,7 +848,7 @@ struct callable_overlay final : public Impl * Published contents * @return if the handler returns true, then continue receiving, otherwise quit. */ - using publish_handler = std::function packet_id, + using publish_handler = move_only_function packet_id, publish_options pubopts, buffer topic_name, buffer contents)>; @@ -860,7 +861,7 @@ struct callable_overlay final : public Impl * 3.4.2 Variable header * @return if the handler returns true, then continue receiving, otherwise quit. */ - using puback_handler = std::function; + using puback_handler = move_only_function; /** * @brief Pubrec handler @@ -870,7 +871,7 @@ struct callable_overlay final : public Impl * 3.5.2 Variable header * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubrec_handler = std::function; + using pubrec_handler = move_only_function; /** * @brief Pubrel handler @@ -880,7 +881,7 @@ struct callable_overlay final : public Impl * 3.6.2 Variable header * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubrel_handler = std::function; + using pubrel_handler = move_only_function; /** * @brief Pubcomp handler @@ -890,7 +891,7 @@ struct callable_overlay final : public Impl * 3.7.2 Variable header * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubcomp_handler = std::function; + using pubcomp_handler = move_only_function; /** * @brief Subscribe handler @@ -902,7 +903,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
* @return if the handler returns true, then continue receiving, otherwise quit. */ - using subscribe_handler = std::function entries)>; /** @@ -916,7 +917,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071
* @return if the handler returns true, then continue receiving, otherwise quit. */ - using suback_handler = std::function qoss)>; /** @@ -929,7 +930,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
* @return if the handler returns true, then continue receiving, otherwise quit. */ - using unsubscribe_handler = std::function entries)>; /** @@ -939,14 +940,14 @@ struct callable_overlay final : public Impl * 3.11.2 Variable header * @return if the handler returns true, then continue receiving, otherwise quit. */ - using unsuback_handler = std::function; + using unsuback_handler = move_only_function; /** * @brief Disconnect handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463
* 3.14 DISCONNECT – Disconnect notification */ - using disconnect_handler = std::function; + using disconnect_handler = move_only_function; // MQTT v5 handlers @@ -993,7 +994,7 @@ struct callable_overlay final : public Impl * @return if the handler returns true, then continue receiving, otherwise quit. * */ - using v5_connect_handler = std::function< + using v5_connect_handler = move_only_function< bool(buffer client_id, optional user_name, optional password, @@ -1019,7 +1020,7 @@ struct callable_overlay final : public Impl * 3.2.2.3 CONNACK Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_connack_handler = std::function< + using v5_connack_handler = move_only_function< bool(bool session_present, v5::connect_reason_code reason_code, v5::properties props) @@ -1050,7 +1051,7 @@ struct callable_overlay final : public Impl * 3.3.2.3 PUBLISH Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_publish_handler = std::function< + using v5_publish_handler = move_only_function< bool(optional packet_id, publish_options pubopts, buffer topic_name, @@ -1074,7 +1075,7 @@ struct callable_overlay final : public Impl * 3.4.2.2 PUBACK Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_puback_handler = std::function< + using v5_puback_handler = move_only_function< bool(packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props) @@ -1096,7 +1097,7 @@ struct callable_overlay final : public Impl * 3.5.2.2 PUBREC Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubrec_handler = std::function< + using v5_pubrec_handler = move_only_function< bool(packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props) @@ -1118,7 +1119,7 @@ struct callable_overlay final : public Impl * 3.6.2.2 PUBREL Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubrel_handler = std::function< + using v5_pubrel_handler = move_only_function< bool(packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props) @@ -1140,7 +1141,7 @@ struct callable_overlay final : public Impl * 3.7.2.2 PUBCOMP Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubcomp_handler = std::function< + using v5_pubcomp_handler = move_only_function< bool(packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props) @@ -1160,7 +1161,7 @@ struct callable_overlay final : public Impl * 3.8.2.1 SUBSCRIBE Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_subscribe_handler = std::function< + using v5_subscribe_handler = move_only_function< bool(packet_id_t packet_id, std::vector entries, v5::properties props) @@ -1181,7 +1182,7 @@ struct callable_overlay final : public Impl * 3.9.2.1 SUBACK Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_suback_handler = std::function< + using v5_suback_handler = move_only_function< bool(packet_id_t packet_id, std::vector reasons, v5::properties props) @@ -1202,7 +1203,7 @@ struct callable_overlay final : public Impl * 3.10.2.1 UNSUBSCRIBE Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_unsubscribe_handler = std::function< + using v5_unsubscribe_handler = move_only_function< bool(packet_id_t packet_id, std::vector entries, v5::properties props) @@ -1223,7 +1224,7 @@ struct callable_overlay final : public Impl * 3.11.2.1 UNSUBACK Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_unsuback_handler = std::function< + using v5_unsuback_handler = move_only_function< bool(packet_id_t, std::vector reasons, v5::properties props) @@ -1242,7 +1243,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
* 3.14.2.2 DISCONNECT Properties */ - using v5_disconnect_handler = std::function< + using v5_disconnect_handler = move_only_function< void(v5::disconnect_reason_code reason_code, v5::properties props) >; @@ -1261,7 +1262,7 @@ struct callable_overlay final : public Impl * 3.15.2.2 AUTH Properties * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_auth_handler = std::function< + using v5_auth_handler = move_only_function< bool(v5::auth_reason_code reason_code, v5::properties props) >; @@ -1275,7 +1276,7 @@ struct callable_overlay final : public Impl * This handler is called if the client called `disconnect()` and the server closed the socket cleanly. * If the socket is closed by other reasons, error_handler is called. */ - using close_handler = std::function; + using close_handler = move_only_function; /** * @brief Error handler @@ -1284,7 +1285,7 @@ struct callable_overlay final : public Impl * * @param ec error code */ - using error_handler = std::function; + using error_handler = move_only_function; /** * @brief Publish response sent handler @@ -1294,7 +1295,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026
* 2.2.1 Packet Identifier */ - using pub_res_sent_handler = std::function; + using pub_res_sent_handler = move_only_function; /** * @brief Serialize publish handler @@ -1302,7 +1303,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg publish message */ - using serialize_publish_message_handler = std::function msg)>; + using serialize_publish_message_handler = move_only_function msg)>; /** * @brief Serialize publish handler @@ -1310,7 +1311,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg v5::publish message */ - using serialize_v5_publish_message_handler = std::function msg)>; + using serialize_v5_publish_message_handler = move_only_function msg)>; /** * @brief Serialize publish handler @@ -1320,7 +1321,7 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_publish_handler = std::function; + using serialize_publish_handler = move_only_function; /** * @brief Serialize pubrel handler @@ -1330,7 +1331,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_pubrel_message_handler = std::function msg)>; + using serialize_pubrel_message_handler = move_only_function msg)>; /** * @brief Serialize pubrel handler @@ -1340,7 +1341,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_v5_pubrel_message_handler = std::function msg)>; + using serialize_v5_pubrel_message_handler = move_only_function msg)>; /** * @brief Serialize pubrel handler @@ -1352,19 +1353,19 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_pubrel_handler = std::function; + using serialize_pubrel_handler = move_only_function; /** * @brief Remove serialized message * @param packet_id packet identifier of the removing message */ - using serialize_remove_handler = std::function; + using serialize_remove_handler = move_only_function; /** * @brief Pre-send handler * This handler is called when any mqtt control packet is decided to send. */ - using pre_send_handler = std::function; + using pre_send_handler = move_only_function; /** * @brief is valid length handler @@ -1374,7 +1375,7 @@ struct callable_overlay final : public Impl * @return true if check is success, otherwise false */ using is_valid_length_handler = - std::function; + move_only_function; /** * @brief next read handler @@ -1382,7 +1383,7 @@ struct callable_overlay final : public Impl * @param func A callback function that is called when async operation will finish. */ using mqtt_message_processed_handler = - std::function; + move_only_function; @@ -1879,7 +1880,7 @@ struct callable_overlay final : public Impl serialize_remove_handler h_remove) { h_serialize_publish_ = [h_publish = force_move(h_publish)] - (basic_publish_message msg) { + (basic_publish_message msg) mutable { if (h_publish) { auto buf = msg.continuous_buffer(); h_publish(msg.packet_id(), buf.data(), buf.size()); @@ -1887,7 +1888,7 @@ struct callable_overlay final : public Impl }; h_serialize_pubrel_ = [h_pubrel = force_move(h_pubrel)] - (basic_pubrel_message msg) { + (basic_pubrel_message msg) mutable { if (h_pubrel) { auto buf = msg.continuous_buffer(); h_pubrel(msg.packet_id(), buf.data(), buf.size()); @@ -1908,7 +1909,7 @@ struct callable_overlay final : public Impl serialize_remove_handler h_remove) { h_serialize_v5_publish_ = [h_publish = force_move(h_publish)] - (v5::basic_publish_message msg) { + (v5::basic_publish_message msg) mutable { if (h_publish) { auto buf = msg.continuous_buffer(); h_publish(msg.packet_id(), buf.data(), buf.size()); @@ -1916,7 +1917,7 @@ struct callable_overlay final : public Impl }; h_serialize_v5_pubrel_ = [h_pubrel = force_move(h_pubrel)] - (v5::basic_pubrel_message msg) { + (v5::basic_pubrel_message msg) mutable { if (h_pubrel) { auto buf = msg.continuous_buffer(); h_pubrel(msg.packet_id(), buf.data(), buf.size()); @@ -2042,7 +2043,7 @@ struct callable_overlay final : public Impl * @brief Get mqtt_message_processed_handler. * @return mqtt_message_processed_handler. */ - mqtt_message_processed_handler get_mqtt_message_processed_handler() const { + mqtt_message_processed_handler const& get_mqtt_message_processed_handler() const { return h_mqtt_message_processed_; } @@ -2066,7 +2067,7 @@ struct callable_overlay final : public Impl * @brief Get close handler * @return handler */ - close_handler get_close_handler() const { + close_handler const& get_close_handler() const { return h_close_; } @@ -2074,7 +2075,7 @@ struct callable_overlay final : public Impl * @brief Get error handler * @return handler */ - error_handler get_error_handler() const { + error_handler const& get_error_handler() const { return h_error_; } diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 179cfa2b9..49dd21e25 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -71,6 +71,7 @@ #include #include #include +#include #if defined(MQTT_USE_WS) #include @@ -173,7 +174,7 @@ class endpoint : public std::enable_shared_from_this; public: - using async_handler_t = std::function; + using async_handler_t = move_only_function; using packet_id_t = typename packet_id_type::type; /** @@ -2229,7 +2230,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); } ); @@ -2268,7 +2269,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); } ); @@ -2756,7 +2757,7 @@ class endpoint : public std::enable_shared_from_this const& f) { + void for_each_store(move_only_function f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "for_each_store(ptr, size)"; LockGuard lck (store_mtx_); store_.for_each( - [f]( + [f = force_move(f)] + ( basic_store_message_variant const& message, any const& /*life_keeper*/ - ) { + ) mutable { auto cb = continuous_buffer(message); f(cb.data(), cb.size()); return false; // no erase @@ -4343,16 +4345,17 @@ class endpoint : public std::enable_shared_from_this)> const& f) { + void for_each_store(move_only_function)> f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "for_each_store(store_message_variant)"; LockGuard lck (store_mtx_); store_.for_each( - [f]( + [f = force_move(f)] + ( basic_store_message_variant const& message, any const& /*life_keeper*/ - ) { + ) mutable { f(message); return false; // no erase } @@ -4363,17 +4366,18 @@ class endpoint : public std::enable_shared_from_this, any)> const& f) { + void for_each_store_with_life_keeper(move_only_function, any)> f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "for_each_store(store_message_variant, life_keeper)"; LockGuard lck (store_mtx_); store_.for_each( - [f]( + [f = force_move(f)] + ( basic_store_message_variant const& message, any const& life_keeper - ) { + ) mutable { f(message, life_keeper); return false; // no erase } @@ -4782,7 +4786,7 @@ class endpoint : public std::enable_shared_from_this(std::get<0>(msg_lk))) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -4799,7 +4803,7 @@ class endpoint : public std::enable_shared_from_this(msg_lk)), [func = force_move(func), life_keeper = force_move(std::get<1>(msg_lk))] - (error_code ec) { + (error_code ec) mutable { if (func) func(ec); } ); @@ -4810,7 +4814,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -4859,14 +4863,14 @@ class endpoint : public std::enable_shared_from_this&& msg) mutable { + [this, func = force_move(func)] (v5::basic_publish_message&& msg) mutable { if (publish_send_count_.load() == publish_send_max_) { { LockGuard lck (publish_send_queue_mtx_); publish_send_queue_.emplace_back(force_move(msg), true); } socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { // message has already been stored so func should be called with success here if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); } @@ -5365,7 +5369,7 @@ class endpoint : public std::enable_shared_from_this; using parse_handler = - std::function< + move_only_function< void( this_type_sp&& spep, any&& session_life_keeper, @@ -10492,7 +10496,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10512,7 +10516,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10543,7 +10547,8 @@ class endpoint : public std::enable_shared_from_this(std::get<0>(msg_lk))) { if (packet_id != 0) { @@ -10551,7 +10556,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10561,12 +10566,18 @@ class endpoint : public std::enable_shared_from_this(serialize_publish), - std::forward(receive_maximum_proc) + [ + &func, + receive_maximum_proc = std::forward(receive_maximum_proc) + ] + (auto&& msg) mutable { + return receive_maximum_proc(force_move(msg), func); + } ) ) { do_async_write( force_move(std::get<0>(msg_lk)), - [life_keeper = force_move(std::get<1>(msg_lk)), func](error_code ec) { + [life_keeper = force_move(std::get<1>(msg_lk)), func = force_move(func)](error_code ec) mutable { if (func) func(ec); } ); @@ -10583,7 +10594,7 @@ class endpoint : public std::enable_shared_from_this&& msg) mutable { + [this] (v5::basic_publish_message&& msg, async_handler_t& func) mutable { if (publish_send_count_.load() == publish_send_max_) { { LockGuard lck (publish_send_queue_mtx_); publish_send_queue_.emplace_back(force_move(msg), true); } socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { // message has already been stored so func should be called with success here if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); } @@ -10635,7 +10646,7 @@ class endpoint : public std::enable_shared_from_this(packet_id); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10644,7 +10655,7 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), packet_id, func = force_move(func)] - (error_code ec) { + (error_code ec) mutable { if (func) func(ec); on_pub_res_sent(packet_id); } @@ -10654,7 +10665,7 @@ class endpoint : public std::enable_shared_from_this(packet_id, reason, force_move(props)); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10663,7 +10674,7 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), packet_id, func = force_move(func)] - (error_code ec) { + (error_code ec) mutable { erase_publish_received(packet_id); if (func) func(ec); on_pub_res_sent(packet_id); @@ -10687,7 +10698,7 @@ class endpoint : public std::enable_shared_from_this(packet_id); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10702,7 +10713,7 @@ class endpoint : public std::enable_shared_from_this(packet_id, reason, force_move(props)); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10711,7 +10722,7 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), packet_id, func = force_move(func)] - (error_code ec) { + (error_code ec) mutable { erase_publish_received(packet_id); if (func) func(ec); } @@ -10738,7 +10749,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10777,7 +10788,8 @@ class endpoint : public std::enable_shared_from_this(packet_id); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10822,7 +10834,7 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), packet_id, func = force_move(func)] - (error_code ec) { + (error_code ec) mutable { if (func) func(ec); on_pub_res_sent(packet_id); } @@ -10832,7 +10844,7 @@ class endpoint : public std::enable_shared_from_this(packet_id, reason, force_move(props)); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10841,7 +10853,7 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), packet_id, func = force_move(func)] - (error_code ec) { + (error_code ec) mutable { if (func) func(ec); on_pub_res_sent(packet_id); } @@ -10868,7 +10880,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10891,7 +10903,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10926,7 +10938,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10945,7 +10957,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -10977,7 +10989,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11000,7 +11012,7 @@ class endpoint : public std::enable_shared_from_thispost( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11030,7 +11042,7 @@ class endpoint : public std::enable_shared_from_this(packet_id); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11064,7 +11076,7 @@ class endpoint : public std::enable_shared_from_this(force_move(params), packet_id, force_move(props)); if (maximum_packet_size_send_ < size(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11087,7 +11099,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11100,7 +11112,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11121,7 +11133,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11133,7 +11145,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11160,7 +11172,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11184,7 +11196,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11196,7 +11208,7 @@ class endpoint : public std::enable_shared_from_this(msg)) { socket_->post( - [func = force_move(func)] { + [func = force_move(func)] () mutable { if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); } ); @@ -11210,13 +11222,14 @@ class endpoint : public std::enable_shared_from_this func) { + template + void async_send_store(Func&& func) { // packet_id has already been registered - auto g = shared_scope_guard( - [func = force_move(func)] { + auto g{shared_scope_guard( + [func = std::forward(func)] () mutable { func(); } - ); + )}; LockGuard lck (store_mtx_); if (store_.empty()) { socket().post( @@ -11359,7 +11372,7 @@ class endpoint : public std::enable_shared_from_thisqueue_.pop_front(); @@ -11379,7 +11392,7 @@ class endpoint : public std::enable_shared_from_thistotal_bytes_sent_ += bytes_transferred; for (std::size_t i = 0; i != num_of_messages_; ++i) { @@ -11418,7 +11431,7 @@ class endpoint : public std::enable_shared_from_this(iterator_count)); // And further, only up to the specified maximum bytes @@ -11446,11 +11459,11 @@ class endpoint : public std::enable_shared_from_thisshared_from_this(), [handlers = force_move(handlers)] - (error_code ec) { - for (auto const& h : handlers) { + (error_code ec) mutable { + for (auto& h : handlers) { if (h) h(ec); } }, diff --git a/include/mqtt/external/function2.hpp b/include/mqtt/external/function2.hpp new file mode 100644 index 000000000..542c72ba5 --- /dev/null +++ b/include/mqtt/external/function2.hpp @@ -0,0 +1,1829 @@ + +// Copyright 2015-2020 Denis Blank +// 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) + +#ifndef FU2_INCLUDED_FUNCTION2_HPP_ +#define FU2_INCLUDED_FUNCTION2_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +// Defines: +// - FU2_HAS_DISABLED_EXCEPTIONS +#if defined(FU2_WITH_DISABLED_EXCEPTIONS) || \ + defined(FU2_MACRO_DISABLE_EXCEPTIONS) +#define FU2_HAS_DISABLED_EXCEPTIONS +#else // FU2_WITH_DISABLED_EXCEPTIONS +#if defined(_MSC_VER) +#if !defined(_HAS_EXCEPTIONS) || (_HAS_EXCEPTIONS == 0) +#define FU2_HAS_DISABLED_EXCEPTIONS +#endif +#elif defined(__clang__) +#if !(__EXCEPTIONS && __has_feature(cxx_exceptions)) +#define FU2_HAS_DISABLED_EXCEPTIONS +#endif +#elif defined(__GNUC__) +#if !__EXCEPTIONS +#define FU2_HAS_DISABLED_EXCEPTIONS +#endif +#endif +#endif // FU2_WITH_DISABLED_EXCEPTIONS +// - FU2_HAS_LIMITED_EMPTY_PROPAGATION +#if defined(FU2_WITH_LIMITED_EMPTY_PROPAGATION) +#define FU2_HAS_LIMITED_EMPTY_PROPAGATION +#endif // FU2_WITH_NO_EMPTY_PROPAGATION +// - FU2_HAS_NO_FUNCTIONAL_HEADER +#if !defined(FU2_WITH_NO_FUNCTIONAL_HEADER) && \ + !defined(FU2_NO_FUNCTIONAL_HEADER) && \ + (!defined(FU2_HAS_DISABLED_EXCEPTIONS) || \ + defined(FU2_HAS_LIMITED_EMPTY_PROPAGATION)) +#include +#else +#define FU2_HAS_NO_FUNCTIONAL_HEADER +#endif +// - FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#if defined(FU2_WITH_CXX17_NOEXCEPT_FUNCTION_TYPE) +#define FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#else // FU2_WITH_CXX17_NOEXCEPT_FUNCTION_TYPE +#if defined(_MSC_VER) +#if defined(_HAS_CXX17) && _HAS_CXX17 +#define FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#endif +#elif defined(__cpp_noexcept_function_type) +#define FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#elif defined(__cplusplus) && (__cplusplus >= 201703L) +#define FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#endif +#endif // FU2_WITH_CXX17_NOEXCEPT_FUNCTION_TYPE + +// - FU2_HAS_NO_EMPTY_PROPAGATION +#if defined(FU2_WITH_NO_EMPTY_PROPAGATION) +#define FU2_HAS_NO_EMPTY_PROPAGATION +#endif // FU2_WITH_NO_EMPTY_PROPAGATION + +#if !defined(FU2_HAS_DISABLED_EXCEPTIONS) +#include +#endif + +#if defined(__cpp_constexpr) && (__cpp_constexpr >= 201304) +#define FU2_DETAIL_CXX14_CONSTEXPR constexpr +#elif defined(__clang__) && defined(__has_feature) +#if __has_feature(__cxx_generic_lambdas__) && \ + __has_feature(__cxx_relaxed_constexpr__) +#define FU2_DETAIL_CXX14_CONSTEXPR constexpr +#endif +#elif defined(_MSC_VER) && (_MSC_VER >= 1915) && (_MSVC_LANG >= 201402) +#define FU2_DETAIL_CXX14_CONSTEXPR constexpr +#endif +#ifndef FU2_DETAIL_CXX14_CONSTEXPR +#define FU2_DETAIL_CXX14_CONSTEXPR +#endif + +/// Hint for the compiler that this point should be unreachable +#if defined(_MSC_VER) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE_INTRINSIC() __assume(false) +#elif defined(__GNUC__) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE_INTRINSIC() __builtin_unreachable() +#elif defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE_INTRINSIC() __builtin_unreachable() +#endif +#endif +#ifndef FU2_DETAIL_UNREACHABLE_INTRINSIC +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE_INTRINSIC() abort() +#endif + +/// Causes the application to exit abnormally +#if defined(_MSC_VER) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_TRAP() __debugbreak() +#elif defined(__GNUC__) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_TRAP() __builtin_trap() +#elif defined(__has_builtin) +#if __has_builtin(__builtin_trap) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_TRAP() __builtin_trap() +#endif +#endif +#ifndef FU2_DETAIL_TRAP +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_TRAP() *(volatile int*)0x11 = 0 +#endif + +#ifndef NDEBUG +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE() ::fu2::detail::unreachable_debug() +#else +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FU2_DETAIL_UNREACHABLE() FU2_DETAIL_UNREACHABLE_INTRINSIC() +#endif + +namespace fu2 { +inline namespace abi_400 { +namespace detail { +template +class function; + +template +struct identity {}; + +// Equivalent to C++17's std::void_t which targets a bug in GCC, +// that prevents correct SFINAE behavior. +// See http://stackoverflow.com/questions/35753920 for details. +template +struct deduce_to_void : std::common_type {}; + +template +using void_t = typename deduce_to_void::type; + +template +using unrefcv_t = std::remove_cv_t>; + +template +struct lazy_and; + +template +struct lazy_and : B1 {}; + +template +struct lazy_and : std::conditional::type {}; + +// template +// struct lazy_and +// : std::conditional, B1>::type {}; + +// Copy enabler helper class +template +struct copyable {}; +template <> +struct copyable { + copyable() = default; + ~copyable() = default; + copyable(copyable const&) = delete; + copyable(copyable&&) = default; + copyable& operator=(copyable const&) = delete; + copyable& operator=(copyable&&) = default; +}; + +/// Configuration trait to configure the function_base class. +template +struct config { + // Is true if the function is owning. + static constexpr auto const is_owning = Owning; + + // Is true if the function is copyable. + static constexpr auto const is_copyable = Copyable; + + // The internal capacity of the function + // used in small functor optimization. + // The object shall expose the real capacity through Capacity::capacity + // and the intended alignment through Capacity::alignment. + using capacity = Capacity; +}; + +/// A config which isn't compatible to other configs +template +struct property { + // Is true when the function throws an exception on empty invocation. + static constexpr auto const is_throwing = Throws; + + // Is true when the function throws an exception on empty invocation. + static constexpr auto const is_strong_exception_guaranteed = + HasStrongExceptGuarantee; +}; + +#ifndef NDEBUG +[[noreturn]] inline void unreachable_debug() { + FU2_DETAIL_TRAP(); + std::abort(); +} +#endif + +/// Provides utilities for invocing callable objects +namespace invocation { +/// Invokes the given callable object with the given arguments +template +constexpr auto invoke(Callable&& callable, Args&&... args) noexcept( + noexcept(std::forward(callable)(std::forward(args)...))) + -> decltype(std::forward(callable)(std::forward(args)...)) { + + return std::forward(callable)(std::forward(args)...); +} +/// Invokes the given member function pointer by reference +template +constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept( + noexcept((std::forward(self).*member)(std::forward(args)...))) + -> decltype((std::forward(self).* + member)(std::forward(args)...)) { + return (std::forward(self).*member)(std::forward(args)...); +} +/// Invokes the given member function pointer by pointer +template +constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept( + noexcept((std::forward(self)->*member)(std::forward(args)...))) + -> decltype((std::forward(self)->*member)( + std::forward(args)...)) { + return (std::forward(self)->*member)(std::forward(args)...); +} +/// Invokes the given pointer to a scalar member by reference +template +constexpr auto +invoke(Type T::*member, + Self&& self) noexcept(noexcept(std::forward(self).*member)) + -> decltype(std::forward(self).*member) { + return (std::forward(self).*member); +} +/// Invokes the given pointer to a scalar member by pointer +template +constexpr auto +invoke(Type T::*member, + Self&& self) noexcept(noexcept(std::forward(self)->*member)) + -> decltype(std::forward(self)->*member) { + return std::forward(self)->*member; +} + +/// Deduces to a true type if the callable object can be invoked with +/// the given arguments. +/// We don't use invoke here because MSVC can't evaluate the nested expression +/// SFINAE here. +template +struct can_invoke : std::false_type {}; +template +struct can_invoke, + decltype((void)std::declval()(std::declval()...))> + : std::true_type {}; +template +struct can_invoke, + decltype((void)((std::declval().*std::declval())( + std::declval()...)))> : std::true_type {}; +template +struct can_invoke, + decltype(( + void)((std::declval().*std::declval())( + std::declval()...)))> : std::true_type {}; +template +struct can_invoke, + decltype(( + void)((std::declval()->*std::declval())( + std::declval()...)))> : std::true_type {}; +template +struct can_invoke, + decltype((void)(std::declval().*std::declval()))> + : std::true_type {}; +template +struct can_invoke, + decltype((void)(std::declval().* + std::declval()))> : std::true_type { +}; +template +struct can_invoke, + decltype(( + void)(std::declval()->*std::declval()))> + : std::true_type {}; + +template +struct is_noexcept_correct : std::true_type {}; +template +struct is_noexcept_correct> + : std::integral_constant(), std::declval()...))> { +}; +} // end namespace invocation + +namespace overloading { +template +struct overload_impl; +template +struct overload_impl : Current, + overload_impl { + explicit overload_impl(Current current, Next next, Rest... rest) + : Current(std::move(current)), overload_impl( + std::move(next), std::move(rest)...) { + } + + using Current::operator(); + using overload_impl::operator(); +}; +template +struct overload_impl : Current { + explicit overload_impl(Current current) : Current(std::move(current)) { + } + + using Current::operator(); +}; + +template +constexpr auto overload(T&&... callables) { + return overload_impl...>{std::forward(callables)...}; +} +} // namespace overloading + +/// Declares the namespace which provides the functionality to work with a +/// type-erased object. +namespace type_erasure { +/// Specialization to work with addresses of callable objects +template +struct address_taker { + template + static void* take(O&& obj) { + return std::addressof(obj); + } + static T& restore(void* ptr) { + return *static_cast(ptr); + } + static T const& restore(void const* ptr) { + return *static_cast(ptr); + } + static T volatile& restore(void volatile* ptr) { + return *static_cast(ptr); + } + static T const volatile& restore(void const volatile* ptr) { + return *static_cast(ptr); + } +}; +/// Specialization to work with addresses of raw function pointers +template +struct address_taker::value>> { + template + static void* take(O&& obj) { + return reinterpret_cast(obj); + } + template + static T restore(O ptr) { + return reinterpret_cast(const_cast(ptr)); + } +}; + +template +struct box_factory; +/// Store the allocator inside the box +template +struct box : private Allocator { + friend box_factory; + + T value_; + + explicit box(T value, Allocator allocator_) + : Allocator(std::move(allocator_)), value_(std::move(value)) { + } + + box(box&&) = default; + box(box const&) = default; + box& operator=(box&&) = default; + box& operator=(box const&) = default; + ~box() = default; +}; +template +struct box : private Allocator { + friend box_factory; + + T value_; + + explicit box(T value, Allocator allocator_) + : Allocator(std::move(allocator_)), value_(std::move(value)) { + } + + box(box&&) = default; + box(box const&) = delete; + box& operator=(box&&) = default; + box& operator=(box const&) = delete; + ~box() = default; +}; + +template +struct box_factory> { + using real_allocator = + typename std::allocator_traits>:: + template rebind_alloc>; + + /// Allocates space through the boxed allocator + static box* + box_allocate(box const* me) { + real_allocator allocator_(*static_cast(me)); + + return static_cast*>( + std::allocator_traits::allocate(allocator_, 1U)); + } + + /// Destroys the box through the given allocator + static void box_deallocate(box* me) { + real_allocator allocator_(*static_cast(me)); + + me->~box(); + std::allocator_traits::deallocate(allocator_, me, 1U); + } +}; + +/// Creates a box containing the given value and allocator +template +auto make_box(std::integral_constant, T&& value, + Allocator&& allocator_) { + return box, std::decay_t>( + std::forward(value), std::forward(allocator_)); +} + +template +struct is_box : std::false_type {}; +template +struct is_box> : std::true_type {}; + +/// Provides access to the pointer to a heal allocated erased object +/// as well to the inplace storage. +union data_accessor { + data_accessor() = default; + explicit constexpr data_accessor(std::nullptr_t) noexcept : ptr_(nullptr) { + } + explicit constexpr data_accessor(void* ptr) noexcept : ptr_(ptr) { + } + + /// The pointer we use if the object is on the heap + void* ptr_; + /// The first field of the inplace storage + std::size_t inplace_storage_; +}; + +/// See opcode::op_fetch_empty +static FU2_DETAIL_CXX14_CONSTEXPR void write_empty(data_accessor* accessor, + bool empty) noexcept { + accessor->inplace_storage_ = std::size_t(empty); +} + +template +using transfer_const_t = + std::conditional_t>::value, + std::add_const_t, To>; +template +using transfer_volatile_t = + std::conditional_t>::value, + std::add_volatile_t, To>; + +/// The retriever when the object is allocated inplace +template +FU2_DETAIL_CXX14_CONSTEXPR auto retrieve(std::true_type /*is_inplace*/, + Accessor from, + std::size_t from_capacity) { + using type = transfer_const_t>*; + + /// Process the command by using the data inside the internal capacity + auto storage = &(from->inplace_storage_); + auto inplace = const_cast(static_cast(storage)); + return type(std::align(alignof(T), sizeof(T), inplace, from_capacity)); +} + +/// The retriever which is used when the object is allocated +/// through the allocator +template +constexpr auto retrieve(std::false_type /*is_inplace*/, Accessor from, + std::size_t /*from_capacity*/) { + + return from->ptr_; +} + +namespace invocation_table { +#if !defined(FU2_HAS_DISABLED_EXCEPTIONS) +#if defined(FU2_HAS_NO_FUNCTIONAL_HEADER) +struct bad_function_call : std::exception { + bad_function_call() noexcept { + } + + char const* what() const noexcept override { + return "bad function call"; + } +}; +#else +using std::bad_function_call; +#endif +#endif + +#ifdef FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#define FU2_DETAIL_EXPAND_QUALIFIERS_NOEXCEPT(F) \ + F(, , noexcept, , &) \ + F(const, , noexcept, , &) \ + F(, volatile, noexcept, , &) \ + F(const, volatile, noexcept, , &) \ + F(, , noexcept, &, &) \ + F(const, , noexcept, &, &) \ + F(, volatile, noexcept, &, &) \ + F(const, volatile, noexcept, &, &) \ + F(, , noexcept, &&, &&) \ + F(const, , noexcept, &&, &&) \ + F(, volatile, noexcept, &&, &&) \ + F(const, volatile, noexcept, &&, &&) +#define FU2_DETAIL_EXPAND_CV_NOEXCEPT(F) \ + F(, , noexcept) \ + F(const, , noexcept) \ + F(, volatile, noexcept) \ + F(const, volatile, noexcept) +#else // FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE +#define FU2_DETAIL_EXPAND_QUALIFIERS_NOEXCEPT(F) +#define FU2_DETAIL_EXPAND_CV_NOEXCEPT(F) +#endif // FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE + +#define FU2_DETAIL_EXPAND_QUALIFIERS(F) \ + F(, , , , &) \ + F(const, , , , &) \ + F(, volatile, , , &) \ + F(const, volatile, , , &) \ + F(, , , &, &) \ + F(const, , , &, &) \ + F(, volatile, , &, &) \ + F(const, volatile, , &, &) \ + F(, , , &&, &&) \ + F(const, , , &&, &&) \ + F(, volatile, , &&, &&) \ + F(const, volatile, , &&, &&) \ + FU2_DETAIL_EXPAND_QUALIFIERS_NOEXCEPT(F) +#define FU2_DETAIL_EXPAND_CV(F) \ + F(, , ) \ + F(const, , ) \ + F(, volatile, ) \ + F(const, volatile, ) \ + FU2_DETAIL_EXPAND_CV_NOEXCEPT(F) + +/// If the function is qualified as noexcept, the call will never throw +template +[[noreturn]] void throw_or_abortnoexcept( + std::integral_constant /*is_throwing*/) noexcept { + std::abort(); +} +/// Calls std::abort on empty function calls +[[noreturn]] inline void +throw_or_abort(std::false_type /*is_throwing*/) noexcept { + std::abort(); +} +/// Throws bad_function_call on empty funciton calls +[[noreturn]] inline void throw_or_abort(std::true_type /*is_throwing*/) { +#ifdef FU2_HAS_DISABLED_EXCEPTIONS + throw_or_abort(std::false_type{}); +#else + throw bad_function_call{}; +#endif +} + +template +struct function_trait; + +using is_noexcept_ = std::false_type; +using is_noexcept_noexcept = std::true_type; + +#define FU2_DEFINE_FUNCTION_TRAIT(CONST, VOLATILE, NOEXCEPT, OVL_REF, REF) \ + template \ + struct function_trait { \ + using pointer_type = Ret (*)(data_accessor CONST VOLATILE*, \ + std::size_t capacity, Args...); \ + template \ + struct internal_invoker { \ + static Ret invoke(data_accessor CONST VOLATILE* data, \ + std::size_t capacity, Args... args) NOEXCEPT { \ + auto obj = retrieve(std::integral_constant{}, \ + data, capacity); \ + auto box = static_cast(obj); \ + return invocation::invoke( \ + static_castvalue_)> CONST VOLATILE \ + REF>(box->value_), \ + std::forward(args)...); \ + } \ + }; \ + \ + template \ + struct view_invoker { \ + static Ret invoke(data_accessor CONST VOLATILE* data, std::size_t, \ + Args... args) NOEXCEPT { \ + \ + auto ptr = static_cast(data->ptr_); \ + return invocation::invoke(address_taker::restore(ptr), \ + std::forward(args)...); \ + } \ + }; \ + \ + template \ + using callable = T CONST VOLATILE REF; \ + \ + using arguments = identity; \ + \ + using is_noexcept = is_noexcept_##NOEXCEPT; \ + \ + template \ + struct empty_invoker { \ + static Ret invoke(data_accessor CONST VOLATILE* /*data*/, \ + std::size_t /*capacity*/, Args... /*args*/) NOEXCEPT { \ + throw_or_abort##NOEXCEPT(std::integral_constant{}); \ + } \ + }; \ + }; + +FU2_DETAIL_EXPAND_QUALIFIERS(FU2_DEFINE_FUNCTION_TRAIT) +#undef FU2_DEFINE_FUNCTION_TRAIT + +/// Deduces to the function pointer to the given signature +template +using function_pointer_of = typename function_trait::pointer_type; + +template +struct invoke_table; + +/// We optimize the vtable_t in case there is a single function overload +template +struct invoke_table { + using type = function_pointer_of; + + /// Return the function pointer itself + template + static constexpr auto fetch(type pointer) noexcept { + static_assert(Index == 0U, "The index should be 0 here!"); + return pointer; + } + + /// Returns the thunk of an single overloaded callable + template + static constexpr type get_invocation_table_of() noexcept { + return &function_trait::template internal_invoker::invoke; + } + /// Returns the thunk of an single overloaded callable + template + static constexpr type get_invocation_view_table_of() noexcept { + return &function_trait::template view_invoker::invoke; + } + /// Returns the thunk of an empty single overloaded callable + template + static constexpr type get_empty_invocation_table() noexcept { + return &function_trait::template empty_invoker::invoke; + } +}; +/// We generate a table in case of multiple function overloads +template +struct invoke_table { + using type = + std::tuple, function_pointer_of, + function_pointer_of...> const*; + + /// Return the function pointer at the particular index + template + static constexpr auto fetch(type table) noexcept { + return std::get(*table); + } + + /// The invocation vtable for a present object + template + struct invocation_vtable : public std::tuple, + function_pointer_of, + function_pointer_of...> { + constexpr invocation_vtable() noexcept + : std::tuple, function_pointer_of, + function_pointer_of...>(std::make_tuple( + &function_trait::template internal_invoker< + T, IsInplace>::invoke, + &function_trait::template internal_invoker< + T, IsInplace>::invoke, + &function_trait::template internal_invoker< + T, IsInplace>::invoke...)) { + } + }; + + /// Returns the thunk of an multi overloaded callable + template + static type get_invocation_table_of() noexcept { + static invocation_vtable const table; + return &table; + } + + /// The invocation vtable for a present object + template + struct invocation_view_vtable + : public std::tuple, + function_pointer_of, + function_pointer_of...> { + constexpr invocation_view_vtable() noexcept + : std::tuple, function_pointer_of, + function_pointer_of...>(std::make_tuple( + &function_trait::template view_invoker::invoke, + &function_trait::template view_invoker::invoke, + &function_trait::template view_invoker::invoke...)) { + } + }; + + /// Returns the thunk of an multi overloaded callable + template + static type get_invocation_view_table_of() noexcept { + static invocation_view_vtable const table; + return &table; + } + + /// The invocation table for an empty wrapper + template + struct empty_vtable : public std::tuple, + function_pointer_of, + function_pointer_of...> { + constexpr empty_vtable() noexcept + : std::tuple, function_pointer_of, + function_pointer_of...>( + std::make_tuple(&function_trait::template empty_invoker< + IsThrowing>::invoke, + &function_trait::template empty_invoker< + IsThrowing>::invoke, + &function_trait::template empty_invoker< + IsThrowing>::invoke...)) { + } + }; + + /// Returns the thunk of an multi single overloaded callable + template + static type get_empty_invocation_table() noexcept { + static empty_vtable const table; + return &table; + } +}; + +template +class operator_impl; + +#define FU2_DEFINE_FUNCTION_TRAIT(CONST, VOLATILE, NOEXCEPT, OVL_REF, REF) \ + template \ + class operator_impl \ + : operator_impl { \ + \ + template \ + friend class operator_impl; \ + \ + protected: \ + operator_impl() = default; \ + ~operator_impl() = default; \ + operator_impl(operator_impl const&) = default; \ + operator_impl(operator_impl&&) = default; \ + operator_impl& operator=(operator_impl const&) = default; \ + operator_impl& operator=(operator_impl&&) = default; \ + \ + using operator_impl::operator(); \ + \ + Ret operator()(Args... args) CONST VOLATILE OVL_REF NOEXCEPT { \ + auto parent = static_cast(this); \ + using erasure_t = std::decay_terasure_)>; \ + \ + /* `std::decay_terasure_)>` is a workaround for a */ \ + /* compiler regression of MSVC 16.3.1, see #29 for details. */ \ + return std::decay_terasure_)>::template invoke( \ + static_cast(parent->erasure_), \ + std::forward(args)...); \ + } \ + }; \ + template \ + class operator_impl, \ + Ret(Args...) CONST VOLATILE OVL_REF NOEXCEPT> \ + : copyable { \ + \ + template \ + friend class operator_impl; \ + \ + protected: \ + operator_impl() = default; \ + ~operator_impl() = default; \ + operator_impl(operator_impl const&) = default; \ + operator_impl(operator_impl&&) = default; \ + operator_impl& operator=(operator_impl const&) = default; \ + operator_impl& operator=(operator_impl&&) = default; \ + \ + Ret operator()(Args... args) CONST VOLATILE OVL_REF NOEXCEPT { \ + auto parent = \ + static_cast CONST VOLATILE*>(this); \ + using erasure_t = std::decay_terasure_)>; \ + \ + /* `std::decay_terasure_)>` is a workaround for a */ \ + /* compiler regression of MSVC 16.3.1, see #29 for details. */ \ + return std::decay_terasure_)>::template invoke( \ + static_cast(parent->erasure_), \ + std::forward(args)...); \ + } \ + }; + +FU2_DETAIL_EXPAND_QUALIFIERS(FU2_DEFINE_FUNCTION_TRAIT) +#undef FU2_DEFINE_FUNCTION_TRAIT +} // namespace invocation_table + +namespace tables { +/// Identifies the action which is dispatched on the erased object +enum class opcode { + op_move, ///< Move the object and set the vtable + op_copy, ///< Copy the object and set the vtable + op_destroy, ///< Destroy the object and reset the vtable + op_weak_destroy, ///< Destroy the object without resetting the vtable + op_fetch_empty, ///< Stores true or false into the to storage + ///< to indicate emptiness +}; + +/// Abstraction for a vtable together with a command table +/// TODO Add optimization for a single formal argument +/// TODO Add optimization to merge both tables if the function is size +/// optimized +template +class vtable; +template +class vtable> { + using command_function_t = void (*)(vtable* /*this*/, opcode /*op*/, + data_accessor* /*from*/, + std::size_t /*from_capacity*/, + data_accessor* /*to*/, + std::size_t /*to_capacity*/); + + using invoke_table_t = invocation_table::invoke_table; + + command_function_t cmd_; + typename invoke_table_t::type vtable_; + + template + struct trait { + static_assert(is_box::value, + "The trait must be specialized with a box!"); + + /// The command table + template + static void process_cmd(vtable* to_table, opcode op, data_accessor* from, + std::size_t from_capacity, data_accessor* to, + std::size_t to_capacity) { + + switch (op) { + case opcode::op_move: { + /// Retrieve the pointer to the object + auto box = static_cast(retrieve( + std::integral_constant{}, from, from_capacity)); + assert(box && "The object must not be over aligned or null!"); + + if (!IsInplace) { + // Just swap both pointers if we allocated on the heap + to->ptr_ = from->ptr_; + +#ifndef NDEBUG + // We don't need to null the pointer since we know that + // we don't own the data anymore through the vtable + // which is set to empty. + from->ptr_ = nullptr; +#endif + + to_table->template set_allocated(); + + } + // The object is allocated inplace + else { + construct(std::true_type{}, std::move(*box), to_table, to, + to_capacity); + box->~T(); + } + return; + } + case opcode::op_copy: { + auto box = static_cast(retrieve( + std::integral_constant{}, from, from_capacity)); + assert(box && "The object must not be over aligned or null!"); + + assert(std::is_copy_constructible::value && + "The box is required to be copyable here!"); + + // Try to allocate the object inplace + construct(std::is_copy_constructible{}, *box, to_table, to, + to_capacity); + return; + } + case opcode::op_destroy: + case opcode::op_weak_destroy: { + + assert(!to && !to_capacity && "Arg overflow!"); + auto box = static_cast(retrieve( + std::integral_constant{}, from, from_capacity)); + + if (IsInplace) { + box->~T(); + } else { + box_factory::box_deallocate(box); + } + + if (op == opcode::op_destroy) { + to_table->set_empty(); + } + return; + } + case opcode::op_fetch_empty: { + write_empty(to, false); + return; + } + } + + FU2_DETAIL_UNREACHABLE(); + } + + template + static void + construct(std::true_type /*apply*/, Box&& box, vtable* to_table, + data_accessor* to, + std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) { + // Try to allocate the object inplace + void* storage = retrieve(std::true_type{}, to, to_capacity); + if (storage) { + to_table->template set_inplace(); + } else { + // Allocate the object through the allocator + to->ptr_ = storage = + box_factory>::box_allocate(std::addressof(box)); + to_table->template set_allocated(); + } + new (storage) T(std::forward(box)); + } + + template + static void + construct(std::false_type /*apply*/, Box&& /*box*/, vtable* /*to_table*/, + data_accessor* /*to*/, + std::size_t /*to_capacity*/) noexcept(HasStrongExceptGuarantee) { + } + }; + + /// The command table + static void empty_cmd(vtable* to_table, opcode op, data_accessor* /*from*/, + std::size_t /*from_capacity*/, data_accessor* to, + std::size_t /*to_capacity*/) { + + switch (op) { + case opcode::op_move: + case opcode::op_copy: { + to_table->set_empty(); + break; + } + case opcode::op_destroy: + case opcode::op_weak_destroy: { + // Do nothing + break; + } + case opcode::op_fetch_empty: { + write_empty(to, true); + break; + } + default: { + FU2_DETAIL_UNREACHABLE(); + } + } + } + +public: + vtable() noexcept = default; + + /// Initialize an object at the given position + template + static void init(vtable& table, T&& object, data_accessor* to, + std::size_t to_capacity) { + + trait>::construct(std::true_type{}, std::forward(object), + &table, to, to_capacity); + } + + /// Moves the object at the given position + void move(vtable& to_table, data_accessor* from, std::size_t from_capacity, + data_accessor* to, + std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) { + cmd_(&to_table, opcode::op_move, from, from_capacity, to, to_capacity); + set_empty(); + } + + /// Destroys the object at the given position + void copy(vtable& to_table, data_accessor const* from, + std::size_t from_capacity, data_accessor* to, + std::size_t to_capacity) const { + cmd_(&to_table, opcode::op_copy, const_cast(from), + from_capacity, to, to_capacity); + } + + /// Destroys the object at the given position + void destroy(data_accessor* from, + std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) { + cmd_(this, opcode::op_destroy, from, from_capacity, nullptr, 0U); + } + + /// Destroys the object at the given position without invalidating the + /// vtable + void + weak_destroy(data_accessor* from, + std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) { + cmd_(this, opcode::op_weak_destroy, from, from_capacity, nullptr, 0U); + } + + /// Returns true when the vtable doesn't hold any erased object + bool empty() const noexcept { + data_accessor data; + cmd_(nullptr, opcode::op_fetch_empty, nullptr, 0U, &data, 0U); + return bool(data.inplace_storage_); + } + + /// Invoke the function at the given index + template + constexpr decltype(auto) invoke(Args&&... args) const { + auto thunk = invoke_table_t::template fetch(vtable_); + return thunk(std::forward(args)...); + } + /// Invoke the function at the given index + template + constexpr decltype(auto) invoke(Args&&... args) const volatile { + auto thunk = invoke_table_t::template fetch(vtable_); + return thunk(std::forward(args)...); + } + + template + void set_inplace() noexcept { + using type = std::decay_t; + vtable_ = invoke_table_t::template get_invocation_table_of(); + cmd_ = &trait::template process_cmd; + } + + template + void set_allocated() noexcept { + using type = std::decay_t; + vtable_ = invoke_table_t::template get_invocation_table_of(); + cmd_ = &trait::template process_cmd; + } + + void set_empty() noexcept { + vtable_ = invoke_table_t::template get_empty_invocation_table(); + cmd_ = &empty_cmd; + } +}; +} // namespace tables + +/// A union which makes the pointer to the heap object share the +/// same space with the internal capacity. +/// The storage type is distinguished by multiple versions of the +/// control and vtable. +template +struct internal_capacity { + /// We extend the union through a technique similar to the tail object hack + typedef union { + /// Tag to access the structure in a type-safe way + data_accessor accessor_; + /// The internal capacity we use to allocate in-place + std::aligned_storage_t capacity_; + } type; +}; +template +struct internal_capacity< + Capacity, std::enable_if_t<(Capacity::capacity < sizeof(void*))>> { + typedef struct { + /// Tag to access the structure in a type-safe way + data_accessor accessor_; + } type; +}; + +template +class internal_capacity_holder { + // Tag to access the structure in a type-safe way + typename internal_capacity::type storage_; + +public: + constexpr internal_capacity_holder() = default; + + FU2_DETAIL_CXX14_CONSTEXPR data_accessor* opaque_ptr() noexcept { + return &storage_.accessor_; + } + constexpr data_accessor const* opaque_ptr() const noexcept { + return &storage_.accessor_; + } + FU2_DETAIL_CXX14_CONSTEXPR data_accessor volatile* + opaque_ptr() volatile noexcept { + return &storage_.accessor_; + } + constexpr data_accessor const volatile* opaque_ptr() const volatile noexcept { + return &storage_.accessor_; + } + + static constexpr std::size_t capacity() noexcept { + return sizeof(storage_); + } +}; + +/// An owning erasure +template +class erasure : internal_capacity_holder { + template + friend class erasure; + template + friend class operator_impl; + + using vtable_t = tables::vtable; + + vtable_t vtable_; + +public: + /// Returns the capacity of this erasure + static constexpr std::size_t capacity() noexcept { + return internal_capacity_holder::capacity(); + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure() noexcept { + vtable_.set_empty(); + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure(std::nullptr_t) noexcept { + vtable_.set_empty(); + } + + FU2_DETAIL_CXX14_CONSTEXPR + erasure(erasure&& right) noexcept(Property::is_strong_exception_guaranteed) { + right.vtable_.move(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure(erasure const& right) { + right.vtable_.copy(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + } + + template + FU2_DETAIL_CXX14_CONSTEXPR + erasure(erasure right) noexcept( + Property::is_strong_exception_guaranteed) { + right.vtable_.move(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + } + + template >> + FU2_DETAIL_CXX14_CONSTEXPR erasure(std::false_type /*use_bool_op*/, + T&& callable, + Allocator&& allocator_ = Allocator{}) { + vtable_t::init(vtable_, + type_erasure::make_box( + std::integral_constant{}, + std::forward(callable), + std::forward(allocator_)), + this->opaque_ptr(), capacity()); + } + template >> + FU2_DETAIL_CXX14_CONSTEXPR erasure(std::true_type /*use_bool_op*/, + T&& callable, + Allocator&& allocator_ = Allocator{}) { + if (!!callable) { + vtable_t::init(vtable_, + type_erasure::make_box( + std::integral_constant{}, + std::forward(callable), + std::forward(allocator_)), + this->opaque_ptr(), capacity()); + } else { + vtable_.set_empty(); + } + } + + ~erasure() { + vtable_.weak_destroy(this->opaque_ptr(), capacity()); + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure& + operator=(std::nullptr_t) noexcept(Property::is_strong_exception_guaranteed) { + vtable_.destroy(this->opaque_ptr(), capacity()); + return *this; + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure& operator=(erasure&& right) noexcept( + Property::is_strong_exception_guaranteed) { + vtable_.weak_destroy(this->opaque_ptr(), capacity()); + right.vtable_.move(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + return *this; + } + + FU2_DETAIL_CXX14_CONSTEXPR erasure& operator=(erasure const& right) { + vtable_.weak_destroy(this->opaque_ptr(), capacity()); + right.vtable_.copy(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + return *this; + } + + template + FU2_DETAIL_CXX14_CONSTEXPR erasure& + operator=(erasure right) noexcept( + Property::is_strong_exception_guaranteed) { + vtable_.weak_destroy(this->opaque_ptr(), capacity()); + right.vtable_.move(vtable_, right.opaque_ptr(), right.capacity(), + this->opaque_ptr(), capacity()); + return *this; + } + + template >> + void assign(std::false_type /*use_bool_op*/, T&& callable, + Allocator&& allocator_ = {}) { + vtable_.weak_destroy(this->opaque_ptr(), capacity()); + vtable_t::init(vtable_, + type_erasure::make_box( + std::integral_constant{}, + std::forward(callable), + std::forward(allocator_)), + this->opaque_ptr(), capacity()); + } + + template >> + void assign(std::true_type /*use_bool_op*/, T&& callable, + Allocator&& allocator_ = {}) { + if (bool(callable)) { + assign(std::false_type{}, std::forward(callable), + std::forward(allocator_)); + } else { + operator=(nullptr); + } + } + + /// Returns true when the erasure doesn't hold any erased object + constexpr bool empty() const noexcept { + return vtable_.empty(); + } + + /// Invoke the function of the erasure at the given index + /// + /// We define this out of class to be able to forward the qualified + /// erasure correctly. + template + static constexpr decltype(auto) invoke(Erasure&& erasure, Args&&... args) { + auto const capacity = erasure.capacity(); + return erasure.vtable_.template invoke( + std::forward(erasure).opaque_ptr(), capacity, + std::forward(args)...); + } +}; + +// A non owning erasure +template +class erasure> { + template + friend class erasure; + template + friend class operator_impl; + + using property_t = property; + + using invoke_table_t = invocation_table::invoke_table; + typename invoke_table_t::type invoke_table_; + + /// The internal pointer to the non owned object + data_accessor view_; + +public: + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + constexpr erasure() noexcept + : invoke_table_( + invoke_table_t::template get_empty_invocation_table()), + view_(nullptr) { + } + + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + constexpr erasure(std::nullptr_t) noexcept + : invoke_table_( + invoke_table_t::template get_empty_invocation_table()), + view_(nullptr) { + } + + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + constexpr erasure(erasure&& right) noexcept + : invoke_table_(right.invoke_table_), view_(right.view_) { + } + + constexpr erasure(erasure const& /*right*/) = default; + + template + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + constexpr erasure(erasure right) noexcept + : invoke_table_(right.invoke_table_), view_(right.view_) { + } + + template + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + constexpr erasure(std::false_type /*use_bool_op*/, T&& object) + : invoke_table_(invoke_table_t::template get_invocation_view_table_of< + std::decay_t>()), + view_(address_taker>::take(std::forward(object))) { + } + template + // NOLINTNEXTLINE(cppcoreguidlines-pro-type-member-init) + FU2_DETAIL_CXX14_CONSTEXPR erasure(std::true_type use_bool_op, T&& object) { + this->assign(use_bool_op, std::forward(object)); + } + + ~erasure() = default; + + constexpr erasure& + operator=(std::nullptr_t) noexcept(HasStrongExceptGuarantee) { + invoke_table_ = + invoke_table_t::template get_empty_invocation_table(); + view_.ptr_ = nullptr; + return *this; + } + + constexpr erasure& operator=(erasure&& right) noexcept { + invoke_table_ = right.invoke_table_; + view_ = right.view_; + right = nullptr; + return *this; + } + + constexpr erasure& operator=(erasure const& /*right*/) = default; + + template + constexpr erasure& + operator=(erasure right) noexcept { + invoke_table_ = right.invoke_table_; + view_ = right.view_; + return *this; + } + + template + constexpr void assign(std::false_type /*use_bool_op*/, T&& callable) { + invoke_table_ = invoke_table_t::template get_invocation_view_table_of< + std::decay_t>(); + view_.ptr_ = + address_taker>::take(std::forward(callable)); + } + template + constexpr void assign(std::true_type /*use_bool_op*/, T&& callable) { + if (bool(callable)) { + assign(std::false_type{}, std::forward(callable)); + } else { + operator=(nullptr); + } + } + + /// Returns true when the erasure doesn't hold any erased object + constexpr bool empty() const noexcept { + return view_.ptr_ == nullptr; + } + + template + static constexpr decltype(auto) invoke(Erasure&& erasure, T&&... args) { + auto thunk = invoke_table_t::template fetch(erasure.invoke_table_); + return thunk(&(erasure.view_), 0UL, std::forward(args)...); + } +}; +} // namespace type_erasure + +/// Deduces to a true_type if the type T provides the given signature and the +/// signature is noexcept correct callable. +template > +struct accepts_one + : detail::lazy_and< // both are std::integral_constant + invocation::can_invoke, + typename Trait::arguments>, + invocation::is_noexcept_correct, + typename Trait::arguments>> {}; + +/// Deduces to a true_type if the type T provides all signatures +template +struct accepts_all : std::false_type {}; +template +struct accepts_all< + T, identity, + void_t::value>...>> + : std::true_type {}; + +#if defined(FU2_HAS_NO_EMPTY_PROPAGATION) +template +struct use_bool_op : std::false_type {}; +#elif defined(FU2_HAS_LIMITED_EMPTY_PROPAGATION) +/// Implementation for use_bool_op based on the behaviour of std::function, +/// propagating empty state for pointers, `std::function` and +/// `fu2::detail::function` types only. +template +struct use_bool_op : std::false_type {}; + +#if !defined(FU2_HAS_NO_FUNCTIONAL_HEADER) +template +struct use_bool_op> : std::true_type {}; +#endif + +template +struct use_bool_op> : std::true_type {}; + +template +struct use_bool_op : std::true_type {}; + +template +struct use_bool_op : std::true_type {}; +#else +template +struct has_bool_op : std::false_type {}; +template +struct has_bool_op()))>> + : std::true_type { +#ifndef NDEBUG + static_assert(!std::is_pointer::value, + "Missing deduction for function pointer!"); +#endif +}; + +/// Deduces to a true_type if the type T is implementing operator bool() +/// or if the type is convertible to bool directly, this also implements an +/// optimizations for function references `void(&)()` which are can never +/// be null and for such a conversion to bool would never return false. +template +struct use_bool_op : has_bool_op {}; + +#define FU2_DEFINE_USE_OP_TRAIT(CONST, VOLATILE, NOEXCEPT) \ + template \ + struct use_bool_op \ + : std::true_type {}; + +FU2_DETAIL_EXPAND_CV(FU2_DEFINE_USE_OP_TRAIT) +#undef FU2_DEFINE_USE_OP_TRAIT + +template +struct use_bool_op : std::false_type {}; + +#if defined(FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE) +template +struct use_bool_op : std::false_type {}; +#endif +#endif // FU2_HAS_NO_EMPTY_PROPAGATION + +template +struct assert_wrong_copy_assign { + static_assert(!Config::is_owning || !Config::is_copyable || + std::is_copy_constructible>::value, + "Can't wrap a non copyable object into a unique function!"); + + using type = void; +}; + +template +struct assert_no_strong_except_guarantee { + static_assert( + !IsStrongExceptGuaranteed || + (std::is_nothrow_move_constructible::value && + std::is_nothrow_destructible::value), + "Can't wrap a object an object that has no strong exception guarantees " + "if this is required by the wrapper!"); + + using type = void; +}; + +/// SFINAES out if the given callable is not copyable correct to the left one. +template +using enable_if_copyable_correct_t = + std::enable_if_t<(!LeftConfig::is_copyable || RightConfig::is_copyable)>; + +template +using is_owning_correct = + std::integral_constant; + +/// SFINAES out if the given function2 is not owning correct to this one +template +using enable_if_owning_correct_t = + std::enable_if_t::value>; + +template +class function> + : type_erasure::invocation_table::operator_impl< + 0U, + function>, + Args...> { + + template + friend class function; + + template + friend class type_erasure::invocation_table::operator_impl; + + using property_t = property; + using erasure_t = + type_erasure::erasure; + + template + using enable_if_can_accept_all_t = + std::enable_if_t, identity>::value>; + + template + struct is_convertible_to_this : std::false_type {}; + template + struct is_convertible_to_this< + function, + void_t, + enable_if_owning_correct_t>> + : std::true_type {}; + + template + using enable_if_not_convertible_to_this = + std::enable_if_t>::value>; + + template + using enable_if_owning_t = + std::enable_if_t::value && Config::is_owning>; + + template + using assert_wrong_copy_assign_t = + typename assert_wrong_copy_assign>::type; + + template + using assert_no_strong_except_guarantee_t = + typename assert_no_strong_except_guarantee>::type; + + erasure_t erasure_; + +public: + /// Default constructor which empty constructs the function + function() = default; + ~function() = default; + + explicit FU2_DETAIL_CXX14_CONSTEXPR + function(function const& /*right*/) = default; + explicit FU2_DETAIL_CXX14_CONSTEXPR function(function&& /*right*/) = default; + + /// Copy construction from another copyable function + template * = nullptr, + enable_if_copyable_correct_t* = nullptr, + enable_if_owning_correct_t* = nullptr> + FU2_DETAIL_CXX14_CONSTEXPR + function(function const& right) + : erasure_(right.erasure_) { + } + + /// Move construction from another function + template * = nullptr, + enable_if_owning_correct_t* = nullptr> + FU2_DETAIL_CXX14_CONSTEXPR function(function&& right) + : erasure_(std::move(right.erasure_)) { + } + + /// Construction from a callable object which overloads the `()` operator + template * = nullptr, + enable_if_can_accept_all_t* = nullptr, + assert_wrong_copy_assign_t* = nullptr, + assert_no_strong_except_guarantee_t* = nullptr> + FU2_DETAIL_CXX14_CONSTEXPR function(T&& callable) + : erasure_(use_bool_op>{}, std::forward(callable)) { + } + template * = nullptr, + enable_if_can_accept_all_t* = nullptr, + enable_if_owning_t* = nullptr, + assert_wrong_copy_assign_t* = nullptr, + assert_no_strong_except_guarantee_t* = nullptr> + FU2_DETAIL_CXX14_CONSTEXPR function(T&& callable, Allocator&& allocator_) + : erasure_(use_bool_op>{}, std::forward(callable), + std::forward(allocator_)) { + } + + /// Empty constructs the function + FU2_DETAIL_CXX14_CONSTEXPR function(std::nullptr_t np) : erasure_(np) { + } + + function& operator=(function const& /*right*/) = default; + function& operator=(function&& /*right*/) = default; + + /// Copy assigning from another copyable function + template * = nullptr, + enable_if_copyable_correct_t* = nullptr, + enable_if_owning_correct_t* = nullptr> + function& operator=(function const& right) { + erasure_ = right.erasure_; + return *this; + } + + /// Move assigning from another function + template * = nullptr, + enable_if_owning_correct_t* = nullptr> + function& operator=(function&& right) { + erasure_ = std::move(right.erasure_); + return *this; + } + + /// Move assigning from a callable object + template * = nullptr, + enable_if_can_accept_all_t* = nullptr, + assert_wrong_copy_assign_t* = nullptr, + assert_no_strong_except_guarantee_t* = nullptr> + function& operator=(T&& callable) { + erasure_.assign(use_bool_op>{}, std::forward(callable)); + return *this; + } + + /// Clears the function + function& operator=(std::nullptr_t np) { + erasure_ = np; + return *this; + } + + /// Returns true when the function is empty + bool empty() const noexcept { + return erasure_.empty(); + } + + /// Returns true when the function isn't empty + explicit operator bool() const noexcept { + return !empty(); + } + + /// Assigns a new target with an optional allocator + template >, + enable_if_not_convertible_to_this* = nullptr, + enable_if_can_accept_all_t* = nullptr, + assert_wrong_copy_assign_t* = nullptr, + assert_no_strong_except_guarantee_t* = nullptr> + void assign(T&& callable, Allocator&& allocator_ = Allocator{}) { + erasure_.assign(use_bool_op>{}, std::forward(callable), + std::forward(allocator_)); + } + + /// Swaps this function with the given function + void swap(function& other) noexcept(HasStrongExceptGuarantee) { + if (&other == this) { + return; + } + + function cache = std::move(other); + other = std::move(*this); + *this = std::move(cache); + } + + /// Swaps the left function with the right one + friend void swap(function& left, + function& right) noexcept(HasStrongExceptGuarantee) { + left.swap(right); + } + + /// Calls the wrapped callable object + using type_erasure::invocation_table::operator_impl< + 0U, function, Args...>::operator(); +}; + +template +bool operator==(function const& f, std::nullptr_t) { + return !bool(f); +} + +template +bool operator!=(function const& f, std::nullptr_t) { + return bool(f); +} + +template +bool operator==(std::nullptr_t, function const& f) { + return !bool(f); +} + +template +bool operator!=(std::nullptr_t, function const& f) { + return bool(f); +} + +// Default intended object size of the function +using object_size = std::integral_constant; +} // namespace detail +} // namespace abi_400 + +/// Can be passed to function_base as template argument which causes +/// the internal small buffer to be sized according to the given size, +/// and aligned with the given alignment. +template +struct capacity_fixed { + static constexpr std::size_t capacity = Capacity; + static constexpr std::size_t alignment = Alignment; +}; + +/// Default capacity for small functor optimization +struct capacity_default + : capacity_fixed {}; + +/// Can be passed to function_base as template argument which causes +/// the internal small buffer to be removed from the callable wrapper. +/// The owning function_base will then allocate memory for every object +/// it applies a type erasure on. +struct capacity_none : capacity_fixed<0UL> {}; + +/// Can be passed to function_base as template argument which causes +/// the internal small buffer to be sized such that it can hold +/// the given object without allocating memory for an applied type erasure. +template +struct capacity_can_hold { + static constexpr std::size_t capacity = sizeof(T); + static constexpr std::size_t alignment = alignof(T); +}; + +/// An adaptable function wrapper base for arbitrary functional types. +/// +/// \tparam IsOwning Is true when the type erasure shall be owning the object. +/// +/// \tparam IsCopyable Defines whether the function is copyable or not +/// +/// \tparam Capacity Defines the internal capacity of the function +/// for small functor optimization. +/// The size of the whole function object will be the capacity +/// plus the size of two pointers. If the capacity is zero, +/// the size will increase through one additional pointer +/// so the whole object has the size of 3 * sizeof(void*). +/// The type which is passed to the Capacity template parameter +/// shall provide a capacity and alignment member which +/// looks like the following example: +/// ```cpp +/// struct my_capacity { +/// static constexpr std::size_t capacity = sizeof(my_type); +/// static constexpr std::size_t alignment = alignof(my_type); +/// }; +/// ``` +/// +/// \tparam IsThrowing Defines whether the function throws an exception on +/// empty function call, `std::abort` is called otherwise. +/// +/// \tparam HasStrongExceptGuarantee Defines whether all objects satisfy the +/// strong exception guarantees, +/// which means the function type will satisfy +/// the strong exception guarantees too. +/// +/// \tparam Signatures Defines the signature of the callable wrapper +/// +template +using function_base = detail::function< + detail::config, + detail::property>; + +/// An owning copyable function wrapper for arbitrary callable types. +template +using function = function_base; + +/// An owning non copyable function wrapper for arbitrary callable types. +template +using unique_function = function_base; + +/// A non owning copyable function wrapper for arbitrary callable types. +template +using function_view = function_base; + +#if !defined(FU2_HAS_DISABLED_EXCEPTIONS) +/// Exception type that is thrown when invoking empty function objects +/// and exception support isn't disabled. +/// +/// Exception support is enabled if +/// the template parameter 'Throwing' is set to true (default). +/// +/// This type will default to std::bad_function_call if the +/// functional header is used, otherwise the library provides its own type. +/// +/// You may disable the inclusion of the functional header +/// through defining `FU2_WITH_NO_FUNCTIONAL_HEADER`. +/// +using detail::type_erasure::invocation_table::bad_function_call; +#endif + +/// Returns a callable object, which unifies all callable objects +/// that were passed to this function. +/// +/// ```cpp +/// auto overloaded = fu2::overload([](std::true_type) { return true; }, +/// [](std::false_type) { return false; }); +/// ``` +/// +/// \param callables A pack of callable objects with arbitrary signatures. +/// +/// \returns A callable object which exposes the +/// +template +constexpr auto overload(T&&... callables) { + return detail::overloading::overload(std::forward(callables)...); +} +} // namespace fu2 + +#undef FU2_DETAIL_EXPAND_QUALIFIERS +#undef FU2_DETAIL_EXPAND_QUALIFIERS_NOEXCEPT +#undef FU2_DETAIL_EXPAND_CV +#undef FU2_DETAIL_EXPAND_CV_NOEXCEPT +#undef FU2_DETAIL_UNREACHABLE_INTRINSIC +#undef FU2_DETAIL_TRAP +#undef FU2_DETAIL_CXX14_CONSTEXPR + +#endif // FU2_INCLUDED_FUNCTION2_HPP_ diff --git a/include/mqtt/move_only_function.hpp b/include/mqtt/move_only_function.hpp new file mode 100644 index 000000000..08b0513bb --- /dev/null +++ b/include/mqtt/move_only_function.hpp @@ -0,0 +1,30 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_MOVE_ONLY_FUNCTION_HPP) +#define MQTT_MOVE_ONLY_FUNCTION_HPP + +#pragma GCC diagnostic push +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Waddress" +#endif // defined(__GNUC__) + +#include + +#include + +namespace MQTT_NS { + +template +using move_only_function = fu2::unique_function; + +} // namespace MQTT_NS + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif // defined(__GNUC__) + +#endif // MQTT_MOVE_ONLY_FUNCTION_HPP diff --git a/include/mqtt/null_strand.hpp b/include/mqtt/null_strand.hpp index a9f56b0cc..f14fe1247 100644 --- a/include/mqtt/null_strand.hpp +++ b/include/mqtt/null_strand.hpp @@ -17,9 +17,77 @@ namespace MQTT_NS { namespace as = boost::asio; -// Using standard executor style null_strand / simple executor -using null_strand = as::io_context::executor_type; +namespace detail { + +struct null_strand { + using inner_executor_type = as::io_context::executor_type; + template + explicit null_strand(Executor e) noexcept + : exe_{force_move(e)} + {} + + template + void defer(Func&& f, Allocator) const { + as::defer( + exe_, + [f = std::forward(f)] () mutable { + std::move(f)(); + } + ); + } + template + void dispatch(Func&& f, Allocator) const { + as::dispatch( + exe_, + [f = std::forward(f)] () mutable { + std::move(f)(); + } + ); + } + template + void post(Func&& f, Allocator) const { + as::post( + exe_, + [f = std::forward(f)] () mutable { + std::move(f)(); + } + ); + } + as::any_io_executor get_inner_executor() const { + return exe_; + } + void on_work_started() const noexcept {} + void on_work_finished() const noexcept {} + bool running_in_this_thread() const noexcept { return true; } + operator as::any_io_executor() const { + return exe_; + } +private: + as::io_context::executor_type exe_; +}; + +} // namespace detail + +using null_strand = detail::null_strand; + +inline bool operator==(null_strand const& lhs, null_strand const& rhs) { + return std::addressof(lhs) == std::addressof(rhs); +} + +inline bool operator!=(null_strand const& lhs, null_strand const& rhs) { + return !(lhs == rhs); +} } // namespace MQTT_NS +namespace boost { +namespace asio { + +template<> +struct is_executor : std::true_type { +}; + +} // namespace asio +} // namespace boost + #endif // MQTT_NULL_STRAND_HPP diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 1cdc6b99f..1e8c85fdc 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace MQTT_NS { @@ -53,7 +54,7 @@ class server { * After this handler called, the next accept will automatically start. * @param ep endpoint of the connecting client */ - using accept_handler = std::function ep)>; + using accept_handler = move_only_function ep)>; /** * @brief Error handler during after accepted before connection established @@ -61,7 +62,7 @@ class server { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = std::function; + using connection_error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -69,7 +70,7 @@ class server { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = std::function; + using error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -78,7 +79,7 @@ class server { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = std::function; + using error_handler_with_ioc = move_only_function; template server( @@ -119,7 +120,7 @@ class server { server( AsioEndpoint&& ep, as::io_context& ioc_accept, - std::function ioc_con_getter, + move_only_function ioc_con_getter, AcceptorConfig&& config = [](as::ip::tcp::acceptor&) {}) : ep_(std::forward(ep)), ioc_accept_(ioc_accept), @@ -173,7 +174,7 @@ class server { void set_error_handler(error_handler h) { h_error_ = [h = force_move(h)] - (error_code ec, as::io_context&) { + (error_code ec, as::io_context&) mutable { if (h) h(ec); }; } @@ -230,9 +231,9 @@ class server { as::ip::tcp::endpoint ep_; as::io_context& ioc_accept_; as::io_context* ioc_con_ = nullptr; - std::function ioc_con_getter_; + move_only_function ioc_con_getter_; optional acceptor_; - std::function config_; + move_only_function config_; bool close_request_{false}; accept_handler h_accept_; connection_error_handler h_connection_error_; @@ -258,7 +259,7 @@ class server_tls { * After this handler called, the next accept will automatically start. * @param ep endpoint of the connecting client */ - using accept_handler = std::function ep)>; + using accept_handler = move_only_function ep)>; /** * @brief Error handler during after accepted before connection established @@ -266,7 +267,7 @@ class server_tls { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = std::function; + using connection_error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -274,7 +275,7 @@ class server_tls { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = std::function; + using error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -283,7 +284,7 @@ class server_tls { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = std::function; + using error_handler_with_ioc = move_only_function; template server_tls( @@ -330,7 +331,7 @@ class server_tls { AsioEndpoint&& ep, tls::context&& ctx, as::io_context& ioc_accept, - std::function ioc_con_getter, + move_only_function ioc_con_getter, AcceptorConfig&& config = [](as::ip::tcp::acceptor&) {}) : ep_(std::forward(ep)), ioc_accept_(ioc_accept), @@ -385,7 +386,7 @@ class server_tls { void set_error_handler(error_handler h) { h_error_ = [h = force_move(h)] - (error_code ec, as::io_context&) { + (error_code ec, as::io_context&) mutable { if (h) h(ec); }; } @@ -445,10 +446,10 @@ class server_tls { return ctx_; } - using verify_cb_t = std::function> const&) >; + using verify_cb_t = move_only_function> const&) >; void set_verify_callback(verify_cb_t verify_cb) { - verify_cb_with_username_ = verify_cb; + verify_cb_with_username_ = force_move(verify_cb); } private: @@ -551,9 +552,9 @@ class server_tls { as::ip::tcp::endpoint ep_; as::io_context& ioc_accept_; as::io_context* ioc_con_ = nullptr; - std::function ioc_con_getter_; + move_only_function ioc_con_getter_; optional acceptor_; - std::function config_; + move_only_function config_; bool close_request_{false}; accept_handler h_accept_; connection_error_handler h_connection_error_; @@ -582,7 +583,7 @@ class server_ws { * @brief Accept handler * @param ep endpoint of the connecting client */ - using accept_handler = std::function ep)>; + using accept_handler = move_only_function ep)>; /** * @brief Error handler during after accepted before connection established @@ -590,7 +591,7 @@ class server_ws { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = std::function; + using connection_error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -598,7 +599,7 @@ class server_ws { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = std::function; + using error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -607,7 +608,7 @@ class server_ws { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = std::function; + using error_handler_with_ioc = move_only_function; template server_ws( @@ -648,7 +649,7 @@ class server_ws { server_ws( AsioEndpoint&& ep, as::io_context& ioc_accept, - std::function ioc_con_getter, + move_only_function ioc_con_getter, AcceptorConfig&& config = [](as::ip::tcp::acceptor&) {}) : ep_(std::forward(ep)), ioc_accept_(ioc_accept), @@ -701,7 +702,7 @@ class server_ws { void set_error_handler(error_handler h) { h_error_ = [h = force_move(h)] - (error_code ec, as::io_context&) { + (error_code ec, as::io_context&) mutable { if (h) h(ec); }; } @@ -917,9 +918,9 @@ class server_ws { as::ip::tcp::endpoint ep_; as::io_context& ioc_accept_; as::io_context* ioc_con_ = nullptr; - std::function ioc_con_getter_; + move_only_function ioc_con_getter_; optional acceptor_; - std::function config_; + move_only_function config_; bool close_request_{false}; accept_handler h_accept_; connection_error_handler h_connection_error_; @@ -946,7 +947,7 @@ class server_tls_ws { * @brief Accept handler * @param ep endpoint of the connecting client */ - using accept_handler = std::function ep)>; + using accept_handler = move_only_function ep)>; /** * @brief Error handler during after accepted before connection established @@ -954,7 +955,7 @@ class server_tls_ws { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = std::function; + using connection_error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -962,7 +963,7 @@ class server_tls_ws { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = std::function; + using error_handler = move_only_function; /** * @brief Error handler for listen and accpet @@ -971,7 +972,7 @@ class server_tls_ws { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = std::function; + using error_handler_with_ioc = move_only_function; template server_tls_ws( @@ -1018,7 +1019,7 @@ class server_tls_ws { AsioEndpoint&& ep, tls::context&& ctx, as::io_context& ioc_accept, - std::function ioc_con_getter, + move_only_function ioc_con_getter, AcceptorConfig&& config = [](as::ip::tcp::acceptor&) {}) : ep_(std::forward(ep)), ioc_accept_(ioc_accept), @@ -1073,7 +1074,7 @@ class server_tls_ws { void set_error_handler(error_handler h) { h_error_ = [h = force_move(h)] - (error_code ec, as::io_context&) { + (error_code ec, as::io_context&) mutable { if (h) h(ec); }; } @@ -1133,10 +1134,10 @@ class server_tls_ws { return ctx_; } - using verify_cb_t = std::function> const&) >; + using verify_cb_t = move_only_function> const&) >; void set_verify_callback(verify_cb_t verify_cb) { - verify_cb_with_username_ = verify_cb; + verify_cb_with_username_ = force_move(verify_cb); } private: @@ -1361,9 +1362,9 @@ class server_tls_ws { as::ip::tcp::endpoint ep_; as::io_context& ioc_accept_; as::io_context* ioc_con_ = nullptr; - std::function ioc_con_getter_; + move_only_function ioc_con_getter_; optional acceptor_; - std::function config_; + move_only_function config_; bool close_request_{false}; accept_handler h_accept_; connection_error_handler h_connection_error_; diff --git a/include/mqtt/store.hpp b/include/mqtt/store.hpp index 717ad4f44..3fa0cdcc9 100644 --- a/include/mqtt/store.hpp +++ b/include/mqtt/store.hpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace MQTT_NS { @@ -84,10 +85,10 @@ class store { } void for_each( - std::function< + move_only_function< // if return true, then erase element bool(basic_store_message_variant const&, any const&) - > const& f + > f ) { auto& idx = elems_.template get(); auto it = idx.begin(); diff --git a/include/mqtt/strand.hpp b/include/mqtt/strand.hpp index fa83f45d1..0b0e29e73 100644 --- a/include/mqtt/strand.hpp +++ b/include/mqtt/strand.hpp @@ -18,6 +18,6 @@ namespace as = boost::asio; using strand = as::strand; -} +} // namespace MQTT_NS #endif // MQTT_STRAND_HPP diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 295ea3109..295294d71 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace MQTT_NS { @@ -32,7 +33,7 @@ class tcp_endpoint : public socket { MQTT_ALWAYS_INLINE void async_read( as::mutable_buffer buffers, - std::function handler + move_only_function handler ) override final { as::async_read( tcp_, @@ -46,7 +47,7 @@ class tcp_endpoint : public socket { MQTT_ALWAYS_INLINE void async_write( std::vector buffers, - std::function handler + move_only_function handler ) override final { as::async_write( tcp_, @@ -65,21 +66,21 @@ class tcp_endpoint : public socket { return as::write(tcp_,force_move(buffers), ec); } - MQTT_ALWAYS_INLINE void post(std::function handler) override final { + MQTT_ALWAYS_INLINE void post(move_only_function handler) override final { as::post( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void dispatch(std::function handler) override final { + MQTT_ALWAYS_INLINE void dispatch(move_only_function handler) override final { as::dispatch( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void defer(std::function handler) override final { + MQTT_ALWAYS_INLINE void defer(move_only_function handler) override final { as::defer( strand_, force_move(handler) @@ -102,7 +103,7 @@ class tcp_endpoint : public socket { shutdown_and_close_impl(tcp_, ec); } - MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(std::function handler) override final { + MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_function handler) override final { async_shutdown_and_close_impl(tcp_, force_move(handler)); } @@ -156,7 +157,7 @@ class tcp_endpoint : public socket { << ec.message(); } - void async_shutdown_and_close_impl(as::basic_socket& s, std::function handler) { + void async_shutdown_and_close_impl(as::basic_socket& s, move_only_function handler) { post( [this, &s, handler = force_move(handler)] () mutable { error_code ec; @@ -175,7 +176,7 @@ class tcp_endpoint : public socket { << ec.message(); shutdown_and_close_impl(lowest_layer(), ec); } - void async_shutdown_and_close_impl(tls::stream& s, std::function handler) { + void async_shutdown_and_close_impl(tls::stream& s, move_only_function handler) { s.async_shutdown( as::bind_executor( strand_, diff --git a/include/mqtt/type_erased_socket.hpp b/include/mqtt/type_erased_socket.hpp index dffd29223..4041311dc 100644 --- a/include/mqtt/type_erased_socket.hpp +++ b/include/mqtt/type_erased_socket.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace MQTT_NS { @@ -22,17 +23,17 @@ namespace as = boost::asio; class socket { public: virtual ~socket() = default; - virtual void async_read(as::mutable_buffer, std::function) = 0; - virtual void async_write(std::vector, std::function) = 0; + virtual void async_read(as::mutable_buffer, move_only_function) = 0; + virtual void async_write(std::vector, move_only_function) = 0; virtual std::size_t write(std::vector, boost::system::error_code&) = 0; - virtual void post(std::function) = 0; - virtual void dispatch(std::function) = 0; - virtual void defer(std::function) = 0; + virtual void post(move_only_function) = 0; + virtual void dispatch(move_only_function) = 0; + virtual void defer(move_only_function) = 0; virtual bool running_in_this_thread() const = 0; virtual as::ip::tcp::socket::lowest_layer_type& lowest_layer() = 0; virtual any native_handle() = 0; virtual void clean_shutdown_and_close(boost::system::error_code&) = 0; - virtual void async_clean_shutdown_and_close(std::function) = 0; + virtual void async_clean_shutdown_and_close(move_only_function) = 0; virtual void force_shutdown_and_close(boost::system::error_code&) = 0; virtual as::any_io_executor get_executor() = 0; }; diff --git a/include/mqtt/ws_endpoint.hpp b/include/mqtt/ws_endpoint.hpp index 7b5025de6..9d784ea86 100644 --- a/include/mqtt/ws_endpoint.hpp +++ b/include/mqtt/ws_endpoint.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace MQTT_NS { @@ -44,12 +45,12 @@ class ws_endpoint : public socket { MQTT_ALWAYS_INLINE void async_read( as::mutable_buffer buffers, - std::function handler + move_only_function handler ) override final { auto req_size = as::buffer_size(buffers); using beast_read_handler_t = - std::function)>; + move_only_function)>; std::shared_ptr beast_read_handler; if (req_size <= buffer_.size()) { @@ -107,7 +108,7 @@ class ws_endpoint : public socket { MQTT_ALWAYS_INLINE void async_write( std::vector buffers, - std::function handler + move_only_function handler ) override final { ws_.async_write( buffers, @@ -126,21 +127,21 @@ class ws_endpoint : public socket { return as::buffer_size(buffers); } - MQTT_ALWAYS_INLINE void post(std::function handler) override final { + MQTT_ALWAYS_INLINE void post(move_only_function handler) override final { as::post( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void dispatch(std::function handler) override final { + MQTT_ALWAYS_INLINE void dispatch(move_only_function handler) override final { as::dispatch( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void defer(std::function handler) override final { + MQTT_ALWAYS_INLINE void defer(move_only_function handler) override final { as::defer( strand_, force_move(handler) @@ -187,7 +188,7 @@ class ws_endpoint : public socket { shutdown_and_close_impl(next_layer(), ec); } - MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(std::function handler) override final { + MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_function handler) override final { if (ws_.is_open()) { // WebSocket closing process MQTT_LOG("mqtt_impl", trace) @@ -272,7 +273,7 @@ class ws_endpoint : public socket { } private: - void async_read_until_closed(std::function handler) { + void async_read_until_closed(move_only_function handler) { auto buffer = std::make_shared(); ws_.async_read( *buffer, @@ -311,7 +312,7 @@ class ws_endpoint : public socket { << ec.message(); } - void async_shutdown_and_close_impl(as::basic_socket& s, std::function handler) { + void async_shutdown_and_close_impl(as::basic_socket& s, move_only_function handler) { post( [this, &s, handler = force_move(handler)] () mutable { error_code ec; @@ -330,7 +331,7 @@ class ws_endpoint : public socket { << ec.message(); shutdown_and_close_impl(lowest_layer(), ec); } - void async_shutdown_and_close_impl(tls::stream& s, std::function handler) { + void async_shutdown_and_close_impl(tls::stream& s, move_only_function handler) { s.async_shutdown( as::bind_executor( strand_, diff --git a/test/system/st_offline.cpp b/test/system/st_offline.cpp index fb60d0199..35d75e54d 100644 --- a/test/system/st_offline.cpp +++ b/test/system/st_offline.cpp @@ -545,12 +545,12 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) { "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no, - [&chk](MQTT_NS::error_code ec){ + [&](MQTT_NS::error_code ec){ BOOST_TEST( ! ec); MQTT_CHK("h_pub_finish"); + async_connect_no_clean(c); } ); - async_connect_no_clean(c); }, [&] { MQTT_CHK("h_close2"); diff --git a/test/system/st_pubsub_no_strand.cpp b/test/system/st_pubsub_no_strand.cpp index d9795f838..500f68f42 100644 --- a/test/system/st_pubsub_no_strand.cpp +++ b/test/system/st_pubsub_no_strand.cpp @@ -78,13 +78,11 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { () { MQTT_CHK("h_close"); finish(); - return true; }); c->set_error_handler( [] (MQTT_NS::error_code) { BOOST_CHECK(false); - return true; }); c->set_puback_handler( [] diff --git a/update_external.sh b/update_external.sh new file mode 100755 index 000000000..0cf05898d --- /dev/null +++ b/update_external.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +git submodule update --init +cp external/function2/include/function2/function2.hpp include/mqtt/external/ From c10583d53da29a29673f9b8db172f681feb6c4d0 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Fri, 7 Oct 2022 20:01:39 +0900 Subject: [PATCH 2/5] Version updated. --- CHANGELOG.md | 6 ++++++ CMakeLists.txt | 2 +- README.md | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94824b689..dc5aed3f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 14.0.0 +* <<<< breaking change >>>> Replaced std::function with move_only_function. (#953) +* Removed old NetworkTS code. (#952) +* Fixed invalid timing async_shutdown handler call. (#950) +* Improved build system. (#948) + ## 13.1.0 * Added clear username and password functionality. (#944) * Refined utility tools. (#941, #942) diff --git a/CMakeLists.txt b/CMakeLists.txt index c75282465..2c4833fc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED (VERSION 3.13.0) -PROJECT (mqtt_cpp_iface VERSION 13.1.0) +PROJECT (mqtt_cpp_iface VERSION 14.0.0) SET(CMAKE_CXX_STANDARD 14) SET(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/README.md b/README.md index a4a544d53..63cdbc130 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MQTT client/server for C++14 based on Boost.Asio -Version 13.1.0 [![Actions Status](https://github.com/redboltz/mqtt_cpp/workflows/CI/badge.svg)](https://github.com/redboltz/mqtt_cpp/actions)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.mqtt_cpp?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=6&branchName=master)[![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp) +Version 14.0.0 [![Actions Status](https://github.com/redboltz/mqtt_cpp/workflows/CI/badge.svg)](https://github.com/redboltz/mqtt_cpp/actions)[![Build Status](https://dev.azure.com/redboltz/redboltz/_apis/build/status/redboltz.mqtt_cpp?branchName=master)](https://dev.azure.com/redboltz/redboltz/_build/latest?definitionId=6&branchName=master)[![codecov](https://codecov.io/gh/redboltz/mqtt_cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/redboltz/mqtt_cpp) Important note https://github.com/redboltz/mqtt_cpp/wiki/News. From 213f48288163d5c1cd6802d553a3f42dbd40ab0c Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Fri, 7 Oct 2022 21:26:53 +0900 Subject: [PATCH 3/5] Introduced move_only_handler. This supports bind_executor. It was siltently ingored. --- .github/workflows/gha.yml | 5 + example/bench.cpp | 12 +- example/client_cli.cpp | 45 +- example/logging.cpp | 14 - example/long_lived_client.cpp | 6 - example/no_tls_async_client.cpp | 6 - example/no_tls_async_client_reconnect.cpp | 1 - example/no_tls_both.cpp | 14 - example/no_tls_client.cpp | 6 - example/no_tls_server.cpp | 8 - example/no_tls_ws_both.cpp | 14 - example/no_tls_ws_client.cpp | 6 - example/no_tls_ws_server.cpp | 8 - example/redirect.cpp | 19 +- example/tls_both.cpp | 14 - example/tls_both_client_cert.cpp | 14 - example/tls_client.cpp | 6 - example/tls_server.cpp | 8 - example/tls_ws_both.cpp | 14 - example/tls_ws_client.cpp | 6 - example/tls_ws_server.cpp | 8 - example/v5_no_tls_both.cpp | 14 - example/v5_no_tls_client.cpp | 6 - example/v5_no_tls_prop.cpp | 2 - example/v5_no_tls_server.cpp | 8 - include/mqtt/apply.hpp | 56 + include/mqtt/async_handler.hpp | 22 + include/mqtt/broker/broker.hpp | 144 +- include/mqtt/broker/session_state.hpp | 6 +- include/mqtt/callable_overlay.hpp | 334 ++-- include/mqtt/client.hpp | 2 - include/mqtt/endpoint.hpp | 614 +++---- include/mqtt/move_only_handler.hpp | 66 + include/mqtt/server.hpp | 34 +- include/mqtt/store.hpp | 2 +- include/mqtt/tcp_endpoint.hpp | 18 +- include/mqtt/type_erased_socket.hpp | 14 +- include/mqtt/ws_endpoint.hpp | 26 +- test/system/st_as_buffer_async_pubsub_1.cpp | 84 - test/system/st_as_buffer_async_pubsub_2.cpp | 84 - test/system/st_as_buffer_pubsub.cpp | 154 -- test/system/st_as_buffer_sub.cpp | 36 - test/system/st_async_pubsub_1.cpp | 84 - test/system/st_async_pubsub_2.cpp | 150 -- test/system/st_broker_offline_message.cpp | 21 - test/system/st_connect.cpp | 48 - test/system/st_issue_749.cpp | 1 - test/system/st_length_check.cpp | 3 - test/system/st_manual_publish.cpp | 14 - test/system/st_maximum_packet_size.cpp | 3 - test/system/st_multi_sub.cpp | 40 - test/system/st_offline.cpp | 18 - test/system/st_pubsub_1.cpp | 1700 ------------------ test/system/st_pubsub_2.cpp | 1489 ++++++++++++++- test/system/st_pubsub_no_strand.cpp | 70 - test/system/st_receive_maximum.cpp | 8 - test/system/st_remaining_length.cpp | 21 - test/system/st_reqres.cpp | 7 - test/system/st_resend.cpp | 68 - test/system/st_resend_new_client.cpp | 28 - test/system/st_resend_serialize.cpp | 28 - test/system/st_resend_serialize_ptr_size.cpp | 28 - test/system/st_retain_1.cpp | 28 - test/system/st_retain_2.cpp | 63 - test/system/st_shared_sub.cpp | 20 - test/system/st_sub.cpp | 54 - test/system/st_topic_alias.cpp | 30 - test/system/st_utf8string_validate.cpp | 13 - test/system/st_will.cpp | 39 - 69 files changed, 2147 insertions(+), 3889 deletions(-) create mode 100644 include/mqtt/apply.hpp create mode 100644 include/mqtt/async_handler.hpp create mode 100644 include/mqtt/move_only_handler.hpp diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 8953f1b3c..12142191f 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -51,6 +51,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Set up GCC + uses: egor-tensin/setup-gcc@v1 + with: + version: 11 + platform: x64 - name: Cache boost id: cache-boost uses: actions/cache@v1 diff --git a/example/bench.cpp b/example/bench.cpp index 35571e75c..5f7a0af5b 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -709,7 +709,7 @@ int main(int argc, char **argv) { MQTT_NS::v5::properties /*props*/) { if (pubopts.get_retain() == MQTT_NS::retain::yes) { locked_cout() << "retained publish received and ignored topic:" << topic_name << std::endl; - return true; + return; } BOOST_ASSERT(rest_times > 0); --rest_times; @@ -742,8 +742,6 @@ int main(int argc, char **argv) { --ci.recv_times; if (rest_times == 0) finish_proc(); } - - return true; }; // ==== end local lambda expressions @@ -764,7 +762,6 @@ int main(int argc, char **argv) { else { std::cout << "connack error:" << connack_return_code << std::endl; } - return true; } ); ci.c->set_v5_connack_handler( @@ -776,7 +773,6 @@ int main(int argc, char **argv) { else { std::cout << "connack error:" << reason_code << std::endl; } - return true; } ); @@ -796,7 +792,6 @@ int main(int argc, char **argv) { } } } - return true; } ); ci.c->set_v5_suback_handler( @@ -817,7 +812,6 @@ int main(int argc, char **argv) { } } } - return true; } ); @@ -827,7 +821,7 @@ int main(int argc, char **argv) { MQTT_NS::publish_options pubopts, MQTT_NS::buffer topic_name, MQTT_NS::buffer contents) { - return publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::v5::properties{}); + publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::v5::properties{}); } ); ci.c->set_v5_publish_handler( @@ -837,7 +831,7 @@ int main(int argc, char **argv) { MQTT_NS::buffer topic_name, MQTT_NS::buffer contents, MQTT_NS::v5::properties props) { - return publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::force_move(props)); + publish_handler(ci, packet_id, pubopts, topic_name, contents, MQTT_NS::force_move(props)); } ); } diff --git a/example/client_cli.cpp b/example/client_cli.cpp index 0a641b7dd..5e2bd6943 100644 --- a/example/client_cli.cpp +++ b/example/client_cli.cpp @@ -591,7 +591,6 @@ int main(int argc, char* argv[]) { std::cout << "< props:" << std::endl; print_props("< ", props); print_menu(); - return true; }; client.set_connack_handler( @@ -615,7 +614,6 @@ int main(int argc, char* argv[]) { } ); } - return true; } ); client.set_v5_connack_handler( @@ -641,7 +639,6 @@ int main(int argc, char* argv[]) { } ); } - return true; } ); client.set_publish_handler( @@ -651,14 +648,13 @@ int main(int argc, char* argv[]) { MQTT_NS::buffer topic_name, MQTT_NS::buffer contents) { std::cout << "< publish (v3.1.1)" << std::endl; - return - publish_handler( - packet_id, - pubopts, - topic_name, - contents, - MQTT_NS::v5::properties{} - ); + publish_handler( + packet_id, + pubopts, + topic_name, + contents, + MQTT_NS::v5::properties{} + ); } ); client.set_v5_publish_handler( @@ -669,14 +665,13 @@ int main(int argc, char* argv[]) { MQTT_NS::buffer contents, MQTT_NS::v5::properties props) { std::cout << "< publish (v5)" << std::endl; - return - publish_handler( - packet_id, - pubopts, - topic_name, - contents, - MQTT_NS::force_move(props) - ); + publish_handler( + packet_id, + pubopts, + topic_name, + contents, + MQTT_NS::force_move(props) + ); } ); client.set_puback_handler( @@ -684,7 +679,6 @@ int main(int argc, char* argv[]) { (packet_id_t packet_id){ std::cout << "< puback (v3.1.1)" << std::endl; std::cout << "< packet_id:" << packet_id << std::endl; - return true; } ); client.set_v5_puback_handler( // use v5 handler @@ -695,7 +689,6 @@ int main(int argc, char* argv[]) { std::cout << "< reason_code:" << reason_code << std::endl; std::cout << "< props:" << std::endl; print_props("< ", props); - return true; } ); client.set_pubrec_handler( @@ -703,7 +696,6 @@ int main(int argc, char* argv[]) { (packet_id_t packet_id){ std::cout << "< pubrec (v3.1.1)" << std::endl; std::cout << "< packet_id:" << packet_id << std::endl; - return true; } ); client.set_v5_pubrec_handler( // use v5 handler @@ -714,7 +706,6 @@ int main(int argc, char* argv[]) { std::cout << "< reason_code:" << reason_code << std::endl; std::cout << "< props:" << std::endl; print_props("< ", props); - return true; } ); client.set_pubrel_handler( @@ -722,7 +713,6 @@ int main(int argc, char* argv[]) { (packet_id_t packet_id){ std::cout << "< pubrel (v3.1.1)" << std::endl; std::cout << "< packet_id:" << packet_id << std::endl; - return true; } ); client.set_v5_pubrel_handler( // use v5 handler @@ -733,7 +723,6 @@ int main(int argc, char* argv[]) { std::cout << "< reason_code:" << reason_code << std::endl; std::cout << "< props:" << std::endl; print_props("< ", props); - return true; } ); client.set_pubcomp_handler( @@ -741,7 +730,6 @@ int main(int argc, char* argv[]) { (packet_id_t packet_id){ std::cout << "< pubcomp (v3.1.1)" << std::endl; std::cout << "< packet_id:" << packet_id << std::endl; - return true; } ); client.set_v5_pubcomp_handler( // use v5 handler @@ -752,7 +740,6 @@ int main(int argc, char* argv[]) { std::cout << "< reason_code:" << reason_code << std::endl; std::cout << "< props:" << std::endl; print_props("< ", props); - return true; } ); client.set_suback_handler( @@ -765,7 +752,6 @@ int main(int argc, char* argv[]) { std::cout << "< " << e << std::endl; } print_menu(); - return true; } ); client.set_v5_suback_handler( @@ -782,7 +768,6 @@ int main(int argc, char* argv[]) { std::cout << "< props:" << std::endl; print_props("< ", props); print_menu(); - return true; } ); client.set_unsuback_handler( @@ -791,7 +776,6 @@ int main(int argc, char* argv[]) { std::cout << "< unsuback (v3.1.1)" << std::endl; std::cout << "< packet_id: " << packet_id << std::endl; print_menu(); - return true; } ); client.set_v5_unsuback_handler( @@ -808,7 +792,6 @@ int main(int argc, char* argv[]) { std::cout << "< props:" << std::endl; print_props("< ", props); print_menu(); - return true; } ); diff --git a/example/logging.cpp b/example/logging.cpp index b2079e059..195d35039 100644 --- a/example/logging.cpp +++ b/example/logging.cpp @@ -47,7 +47,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -64,20 +63,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -93,7 +89,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -110,7 +105,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -225,7 +219,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -240,25 +233,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -283,7 +272,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -300,7 +288,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -314,7 +301,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { auto sp = wp.lock(); BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/long_lived_client.cpp b/example/long_lived_client.cpp index e810e72ce..01d97f041 100644 --- a/example/long_lived_client.cpp +++ b/example/long_lived_client.cpp @@ -120,7 +120,6 @@ int main(int argc, char** argv) { ); publish_message(publish_timer, c, packet_counter); - return true; }); c->set_close_handler( [] @@ -139,13 +138,11 @@ int main(int argc, char** argv) { [&] (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] @@ -157,7 +154,6 @@ int main(int argc, char** argv) { } packet_counter += 1; - return true; }); c->set_suback_handler( [&] @@ -166,7 +162,6 @@ int main(int argc, char** argv) { for (auto const& e : results) { std::cout << "[client] subscribe result: " << e << std::endl; } - return true; }); c->set_publish_handler( [&] @@ -183,7 +178,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; - return true; }); // Connect diff --git a/example/no_tls_async_client.cpp b/example/no_tls_async_client.cpp index 3b50764de..c8abc69b1 100644 --- a/example/no_tls_async_client.cpp +++ b/example/no_tls_async_client.cpp @@ -80,7 +80,6 @@ int main(int argc, char** argv) { ); } - return true; }); c->set_close_handler( [] @@ -97,20 +96,17 @@ int main(int argc, char** argv) { (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ std::cout << "pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -153,7 +149,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_publish_handler( [&] @@ -170,7 +165,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/no_tls_async_client_reconnect.cpp b/example/no_tls_async_client_reconnect.cpp index 7179dc2e6..19508f73a 100644 --- a/example/no_tls_async_client_reconnect.cpp +++ b/example/no_tls_async_client_reconnect.cpp @@ -85,7 +85,6 @@ int main(int argc, char** argv) { else { reconnect(); } - return true; }); c->set_close_handler( [&] diff --git a/example/no_tls_both.cpp b/example/no_tls_both.cpp index 121cf90c1..2659c3dad 100644 --- a/example/no_tls_both.cpp +++ b/example/no_tls_both.cpp @@ -46,7 +46,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -63,20 +62,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -92,7 +88,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -109,7 +104,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -234,7 +228,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -249,25 +242,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -292,7 +281,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -309,7 +297,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -326,7 +313,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/no_tls_client.cpp b/example/no_tls_client.cpp index bed78188c..680b0b469 100644 --- a/example/no_tls_client.cpp +++ b/example/no_tls_client.cpp @@ -54,7 +54,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_close_handler( [] @@ -71,20 +70,17 @@ int main(int argc, char** argv) { (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ std::cout << "pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -100,7 +96,6 @@ int main(int argc, char** argv) { c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -117,7 +112,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/no_tls_server.cpp b/example/no_tls_server.cpp index 06446f02c..13689eaba 100644 --- a/example/no_tls_server.cpp +++ b/example/no_tls_server.cpp @@ -141,7 +141,6 @@ int main(int argc, char** argv) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -156,25 +155,21 @@ int main(int argc, char** argv) { [] (packet_id_t packet_id){ std::cout << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -199,7 +194,6 @@ int main(int argc, char** argv) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -216,7 +210,6 @@ int main(int argc, char** argv) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -233,7 +226,6 @@ int main(int argc, char** argv) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/no_tls_ws_both.cpp b/example/no_tls_ws_both.cpp index 21f60ae21..6e17486a9 100644 --- a/example/no_tls_ws_both.cpp +++ b/example/no_tls_ws_both.cpp @@ -46,7 +46,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -63,20 +62,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -92,7 +88,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -109,7 +104,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -233,7 +227,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -248,25 +241,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -291,7 +280,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -308,7 +296,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -325,7 +312,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/no_tls_ws_client.cpp b/example/no_tls_ws_client.cpp index 838d34078..587e57b42 100644 --- a/example/no_tls_ws_client.cpp +++ b/example/no_tls_ws_client.cpp @@ -54,7 +54,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_close_handler( [] @@ -71,20 +70,17 @@ int main(int argc, char** argv) { (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ std::cout << "pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -100,7 +96,6 @@ int main(int argc, char** argv) { c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -117,7 +112,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/no_tls_ws_server.cpp b/example/no_tls_ws_server.cpp index e8a481469..5438ccbf7 100644 --- a/example/no_tls_ws_server.cpp +++ b/example/no_tls_ws_server.cpp @@ -141,7 +141,6 @@ int main(int argc, char** argv) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -156,25 +155,21 @@ int main(int argc, char** argv) { [] (packet_id_t packet_id){ std::cout << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -199,7 +194,6 @@ int main(int argc, char** argv) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -216,7 +210,6 @@ int main(int argc, char** argv) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -233,7 +226,6 @@ int main(int argc, char** argv) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/redirect.cpp b/example/redirect.cpp index a78214c93..4100e3cd3 100644 --- a/example/redirect.cpp +++ b/example/redirect.cpp @@ -66,12 +66,12 @@ void set_client_handlers( } if (server_reference.empty()) { locked_cout() << "[client] redirect requested but no server_reference" << std::endl; - return false; + return; } auto pos = server_reference.find(':'); if (pos == std::string::npos) { locked_cout() << "[client] no port specified in server_reference" << std::endl; - return false; + return; } auto host = server_reference.substr(0, pos); auto port = server_reference.substr(pos + 1); @@ -98,7 +98,6 @@ void set_client_handlers( default: locked_cout() << "[client] handler not implemented" << std::endl; } - return true; }); c.set_close_handler( // this handler doesn't depend on MQTT protocol version [] @@ -117,7 +116,6 @@ void set_client_handlers( "[client] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(c); - return true; }); c.set_v5_pubrec_handler( // use v5 handler [&] @@ -125,7 +123,6 @@ void set_client_handlers( locked_cout() << "[client] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); c.set_v5_pubcomp_handler( // use v5 handler [&] @@ -134,7 +131,6 @@ void set_client_handlers( "[client] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(c); - return true; }); c.set_v5_suback_handler( // use v5 handler [&] @@ -165,7 +161,6 @@ void set_client_handlers( c.publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c.publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c.set_v5_publish_handler( // use v5 handler [&] @@ -183,7 +178,6 @@ void set_client_handlers( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(c); - return true; }); } @@ -305,7 +299,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s { MQTT_NS::v5::property::server_reference(MQTT_NS::allocate_buffer("localhost:" + std::to_string(s2.port()))) } ); sp->force_disconnect(); - return false; } ); } @@ -376,7 +369,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s false, MQTT_NS::v5::connect_reason_code::success ); - return true; } ); ep.set_v5_disconnect_handler( // use v5 handler @@ -395,7 +387,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s locked_cout() << "[server] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrec_handler( // use v5 handler [] @@ -403,7 +394,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s locked_cout() << "[server] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrel_handler( // use v5 handler [] @@ -411,7 +401,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s locked_cout() << "[server] pubrel received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubcomp_handler( // use v5 handler [] @@ -419,7 +408,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_publish_handler( // use v5 handler [&subs] @@ -453,7 +441,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s std::move(props) ); } - return true; }); ep.set_v5_subscribe_handler( // use v5 handler [&subs, wp] @@ -474,7 +461,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos(), e.subopts.get_rap()); } sp->suback(packet_id, res); - return true; } ); ep.set_v5_unsubscribe_handler( // use v5 handler @@ -489,7 +475,6 @@ void server_proc(Server1& s1, Server2& s2, std::set& connections, mi_s auto sp = wp.lock(); BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 991b769b1..e82ab9a8b 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -47,7 +47,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -64,20 +63,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -93,7 +89,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -110,7 +105,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -235,7 +229,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -250,25 +243,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -293,7 +282,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -310,7 +298,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -327,7 +314,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/tls_both_client_cert.cpp b/example/tls_both_client_cert.cpp index 09b0ae7e0..a8227c178 100644 --- a/example/tls_both_client_cert.cpp +++ b/example/tls_both_client_cert.cpp @@ -47,7 +47,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -64,20 +63,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -93,7 +89,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -110,7 +105,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -225,7 +219,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -240,25 +233,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -283,7 +272,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -300,7 +288,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -314,7 +301,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { auto sp = wp.lock(); BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/tls_client.cpp b/example/tls_client.cpp index 1e066277f..abf5c566b 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -70,7 +70,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_close_handler( [] @@ -87,20 +86,17 @@ int main(int argc, char** argv) { (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ std::cout << "pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -116,7 +112,6 @@ int main(int argc, char** argv) { c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -133,7 +128,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/tls_server.cpp b/example/tls_server.cpp index 266d45598..c2a9e5dd5 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -153,7 +153,6 @@ int main(int argc, char** argv) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -168,25 +167,21 @@ int main(int argc, char** argv) { [] (packet_id_t packet_id){ std::cout << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -211,7 +206,6 @@ int main(int argc, char** argv) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -228,7 +222,6 @@ int main(int argc, char** argv) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -245,7 +238,6 @@ int main(int argc, char** argv) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index ae3ca04d2..d263335cc 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -46,7 +46,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( [] @@ -63,20 +62,17 @@ void client_proc( (packet_id_t packet_id){ locked_cout() << "[client] puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ locked_cout() << "[client] pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -92,7 +88,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -109,7 +104,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -234,7 +228,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -249,25 +242,21 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { [] (packet_id_t packet_id){ locked_cout() << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -292,7 +281,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -309,7 +297,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -326,7 +313,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/tls_ws_client.cpp b/example/tls_ws_client.cpp index 98d3ea614..563a45a94 100644 --- a/example/tls_ws_client.cpp +++ b/example/tls_ws_client.cpp @@ -60,7 +60,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_close_handler( [] @@ -77,20 +76,17 @@ int main(int argc, char** argv) { (packet_id_t packet_id){ std::cout << "puback received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_pubrec_handler( [&] (packet_id_t packet_id){ std::cout << "pubrec received. packet_id: " << packet_id << std::endl; - return true; }); c->set_pubcomp_handler( [&] (packet_id_t packet_id){ std::cout << "pubcomp received. packet_id: " << packet_id << std::endl; disconnect(); - return true; }); c->set_suback_handler( [&] @@ -106,7 +102,6 @@ int main(int argc, char** argv) { c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_publish_handler( [&] @@ -123,7 +118,6 @@ int main(int argc, char** argv) { std::cout << "topic_name: " << topic_name << std::endl; std::cout << "contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 5cab8c323..7941c0509 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -153,7 +153,6 @@ int main(int argc, char** argv) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::connect_return_code::accepted); - return true; } ); ep.set_disconnect_handler( @@ -168,25 +167,21 @@ int main(int argc, char** argv) { [] (packet_id_t packet_id){ std::cout << "[server] puback received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrec_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrec received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubrel_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubrel received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_pubcomp_handler( [] (packet_id_t packet_id){ std::cout << "[server] pubcomp received. packet_id: " << packet_id << std::endl; - return true; }); ep.set_publish_handler( [&subs] @@ -211,7 +206,6 @@ int main(int argc, char** argv) { std::min(r.first->qos_value, pubopts.get_qos()) ); } - return true; }); ep.set_subscribe_handler( [&subs, wp] @@ -228,7 +222,6 @@ int main(int argc, char** argv) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos()); } sp->suback(packet_id, res); - return true; } ); ep.set_unsubscribe_handler( @@ -245,7 +238,6 @@ int main(int argc, char** argv) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/v5_no_tls_both.cpp b/example/v5_no_tls_both.cpp index 8089ba175..f9c517d71 100644 --- a/example/v5_no_tls_both.cpp +++ b/example/v5_no_tls_both.cpp @@ -45,7 +45,6 @@ void client_proc( } ); } - return true; }); c->set_close_handler( // this handler doesn't depend on MQTT protocol version [] @@ -64,7 +63,6 @@ void client_proc( "[client] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(); - return true; }); c->set_v5_pubrec_handler( // use v5 handler [&] @@ -72,7 +70,6 @@ void client_proc( locked_cout() << "[client] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); c->set_v5_pubcomp_handler( // use v5 handler [&] @@ -81,7 +78,6 @@ void client_proc( "[client] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(); - return true; }); c->set_v5_suback_handler( // use v5 handler [&] @@ -112,7 +108,6 @@ void client_proc( c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_v5_publish_handler( // use v5 handler [&] @@ -130,7 +125,6 @@ void client_proc( locked_cout() << "[client] topic_name: " << topic_name << std::endl; locked_cout() << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect @@ -256,7 +250,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::v5::connect_reason_code::success); - return true; } ); ep.set_v5_disconnect_handler( // use v5 handler @@ -275,7 +268,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { locked_cout() << "[server] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrec_handler( // use v5 handler [] @@ -283,7 +275,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { locked_cout() << "[server] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrel_handler( // use v5 handler [] @@ -291,7 +282,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { locked_cout() << "[server] pubrel received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubcomp_handler( // use v5 handler [] @@ -299,7 +289,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { locked_cout() << "[server] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_publish_handler( // use v5 handler [&subs] @@ -333,7 +322,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { std::move(props) ); } - return true; }); ep.set_v5_subscribe_handler( // use v5 handler [&subs, wp] @@ -354,7 +342,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos(), e.subopts.get_rap()); } sp->suback(packet_id, res); - return true; } ); ep.set_v5_unsubscribe_handler( // use v5 handler @@ -372,7 +359,6 @@ void server_proc(Server& s, std::set& connections, mi_sub_con& subs) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/example/v5_no_tls_client.cpp b/example/v5_no_tls_client.cpp index e37b7e3e6..02f2f649f 100644 --- a/example/v5_no_tls_client.cpp +++ b/example/v5_no_tls_client.cpp @@ -54,7 +54,6 @@ int main(int argc, char** argv) { } ); } - return true; }); c->set_close_handler( // this handler doesn't depend on MQTT protocol version [] @@ -73,7 +72,6 @@ int main(int argc, char** argv) { "[client] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(); - return true; }); c->set_v5_pubrec_handler( // use v5 handler [&] @@ -81,7 +79,6 @@ int main(int argc, char** argv) { std::cout << "[client] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); c->set_v5_pubcomp_handler( // use v5 handler [&] @@ -90,7 +87,6 @@ int main(int argc, char** argv) { "[client] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; disconnect(); - return true; }); c->set_v5_suback_handler( // use v5 handler [&] @@ -121,7 +117,6 @@ int main(int argc, char** argv) { c->publish("mqtt_client_cpp/topic2_1", "test2_1", MQTT_NS::qos::at_least_once); c->publish("mqtt_client_cpp/topic2_2", "test2_2", MQTT_NS::qos::exactly_once); } - return true; }); c->set_v5_publish_handler( // use v5 handler [&] @@ -139,7 +134,6 @@ int main(int argc, char** argv) { std::cout << "[client] topic_name: " << topic_name << std::endl; std::cout << "[client] contents: " << contents << std::endl; disconnect(); - return true; }); // Connect diff --git a/example/v5_no_tls_prop.cpp b/example/v5_no_tls_prop.cpp index f92ef4542..05acb503f 100644 --- a/example/v5_no_tls_prop.cpp +++ b/example/v5_no_tls_prop.cpp @@ -97,7 +97,6 @@ void client_proc(Client& c) { c->disconnect(); - return true; }); c->set_close_handler( // this handler doesn't depend on MQTT protocol version [] @@ -265,7 +264,6 @@ void server_proc(Server& s, std::set& connections) { MQTT_NS::v5::property::authentication_data("test authentication data"_mb) }; sp->connack(false, MQTT_NS::v5::connect_reason_code::success, std::move(connack_ps)); - return true; } ); ep.set_v5_disconnect_handler( // use v5 handler diff --git a/example/v5_no_tls_server.cpp b/example/v5_no_tls_server.cpp index 929847802..fb8605f8a 100644 --- a/example/v5_no_tls_server.cpp +++ b/example/v5_no_tls_server.cpp @@ -142,7 +142,6 @@ int main(int argc, char** argv) { BOOST_ASSERT(sp); connections.insert(sp); sp->connack(false, MQTT_NS::v5::connect_reason_code::success); - return true; } ); ep.set_v5_disconnect_handler( // use v5 handler @@ -161,7 +160,6 @@ int main(int argc, char** argv) { std::cout << "[server] puback received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrec_handler( // use v5 handler [] @@ -169,7 +167,6 @@ int main(int argc, char** argv) { std::cout << "[server] pubrec received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubrel_handler( // use v5 handler [] @@ -177,7 +174,6 @@ int main(int argc, char** argv) { std::cout << "[server] pubrel received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_pubcomp_handler( // use v5 handler [] @@ -185,7 +181,6 @@ int main(int argc, char** argv) { std::cout << "[server] pubcomp received. packet_id: " << packet_id << " reason_code: " << reason_code << std::endl; - return true; }); ep.set_v5_publish_handler( // use v5 handler [&subs] @@ -219,7 +214,6 @@ int main(int argc, char** argv) { std::move(props) ); } - return true; }); ep.set_v5_subscribe_handler( // use v5 handler [&subs, wp] @@ -240,7 +234,6 @@ int main(int argc, char** argv) { subs.emplace(std::move(e.topic_filter), sp, e.subopts.get_qos(), e.subopts.get_rap()); } sp->suback(packet_id, res); - return true; } ); ep.set_v5_unsubscribe_handler( // use v5 handler @@ -258,7 +251,6 @@ int main(int argc, char** argv) { } BOOST_ASSERT(sp); sp->unsuback(packet_id); - return true; } ); } diff --git a/include/mqtt/apply.hpp b/include/mqtt/apply.hpp new file mode 100644 index 000000000..fef2ac1f6 --- /dev/null +++ b/include/mqtt/apply.hpp @@ -0,0 +1,56 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_APPLY_HPP) +#define MQTT_APPLY_HPP + +#include +#include +#include + +#include + +namespace MQTT_NS { + +#if cplusplus >= 201703L + +template +decltype(auto) apply(F&& f, Tuple&& t) { + return std::apply(std::forward(f), std::forward(t)); +} + +#else // __cplusplus >= 201703L + +namespace detail { + +template < typename F, typename Tuple, std::size_t... Idx> +constexpr decltype(auto) +apply_impl(F&& f, Tuple&& t, std::index_sequence) { + return static_cast(f)(std::get(static_cast(t))...); +} + +} // namespace detail + +template +constexpr decltype(auto) apply(F&& f, Tuple&& t) { + return + detail::apply_impl( + static_cast(f), + static_cast(t), + std::make_index_sequence< + std::tuple_size< + std::remove_reference_t + >::value + >{} + ); +} + + +#endif // __cplusplus >= 201703L + +} // namespace MQTT_NS + +#endif // MQTT_APPLY_HPP diff --git a/include/mqtt/async_handler.hpp b/include/mqtt/async_handler.hpp new file mode 100644 index 000000000..b23d8d20b --- /dev/null +++ b/include/mqtt/async_handler.hpp @@ -0,0 +1,22 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_ASYNC_HANDLER_HPP) +#define MQTT_ASYNC_HANDLER_HPP + +#include + +#include +#include +#include + +namespace MQTT_NS { + +using async_handler_t = move_only_handler; + +} // namespace MQTT_NS + +#endif // MQTT_ASYNC_HANDLER_HPP diff --git a/include/mqtt/broker/broker.hpp b/include/mqtt/broker/broker.hpp index a326dfc03..06c80dc1f 100644 --- a/include/mqtt/broker/broker.hpp +++ b/include/mqtt/broker/broker.hpp @@ -236,7 +236,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return connect_handler( + connect_handler( force_move(sp), force_move(client_id), force_move(username), @@ -251,7 +251,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -268,7 +267,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return connect_handler( + connect_handler( force_move(sp), force_move(client_id), force_move(username), @@ -283,7 +282,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -327,7 +325,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return puback_handler( + puback_handler( force_move(sp), packet_id, v5::puback_reason_code::success, @@ -338,7 +336,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -351,7 +348,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return puback_handler( + puback_handler( force_move(sp), packet_id, reason_code, @@ -362,7 +359,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -373,7 +369,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubrec_handler( + pubrec_handler( force_move(sp), packet_id, v5::pubrec_reason_code::success, @@ -384,7 +380,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -397,7 +392,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubrec_handler( + pubrec_handler( force_move(sp), packet_id, reason_code, @@ -408,7 +403,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -419,7 +413,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubrel_handler( + pubrel_handler( force_move(sp), packet_id, v5::pubrel_reason_code::success, @@ -430,7 +424,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -443,7 +436,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubrel_handler( + pubrel_handler( force_move(sp), packet_id, reason_code, @@ -454,7 +447,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -465,7 +457,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubcomp_handler( + pubcomp_handler( force_move(sp), packet_id, v5::pubcomp_reason_code::success, @@ -476,7 +468,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -489,7 +480,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return pubcomp_handler( + pubcomp_handler( force_move(sp), packet_id, reason_code, @@ -500,7 +491,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -514,7 +504,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return publish_handler( + publish_handler( force_move(sp), packet_id, pubopts, @@ -527,7 +517,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -544,7 +533,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return publish_handler( + publish_handler( force_move(sp), packet_id, pubopts, @@ -557,7 +546,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -569,7 +557,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return subscribe_handler( + subscribe_handler( force_move(sp), packet_id, force_move(entries), @@ -580,7 +568,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -594,7 +581,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return subscribe_handler( + subscribe_handler( force_move(sp), packet_id, force_move(entries), @@ -605,7 +592,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -617,7 +603,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return unsubscribe_handler( + unsubscribe_handler( force_move(sp), packet_id, force_move(entries), @@ -628,7 +614,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -642,7 +627,7 @@ class broker_t { BOOST_ASSERT(sp); auto p = sp.get(); try { - return unsubscribe_handler( + unsubscribe_handler( force_move(sp), packet_id, force_move(entries), @@ -653,7 +638,6 @@ class broker_t { MQTT_LOG("mqtt_broker", error) << MQTT_ADD_VALUE(address, p) << ex.what(); - return true; } } ); @@ -674,7 +658,6 @@ class broker_t { } ); } - return true; } ); ep.set_v5_auth_handler( @@ -683,7 +666,6 @@ class broker_t { v5::properties props ) { if (h_auth_props_) h_auth_props_(force_move(props)); - return true; } ); @@ -721,43 +703,43 @@ class broker_t { pubcomp_props_ = force_move(props); } - void set_connect_props_handler(move_only_function h) { + void set_connect_props_handler(move_only_handler h) { h_connect_props_ = force_move(h); } - void set_disconnect_props_handler(move_only_function h) { + void set_disconnect_props_handler(move_only_handler h) { h_disconnect_props_ = force_move(h); } - void set_publish_props_handler(move_only_function h) { + void set_publish_props_handler(move_only_handler h) { h_publish_props_ = force_move(h); } - void set_puback_props_handler(move_only_function h) { + void set_puback_props_handler(move_only_handler h) { h_puback_props_ = force_move(h); } - void set_pubrec_props_handler(move_only_function h) { + void set_pubrec_props_handler(move_only_handler h) { h_pubrec_props_ = force_move(h); } - void set_pubrel_props_handler(move_only_function h) { + void set_pubrel_props_handler(move_only_handler h) { h_pubrel_props_ = force_move(h); } - void set_pubcomp_props_handler(move_only_function h) { + void set_pubcomp_props_handler(move_only_handler h) { h_pubcomp_props_ = force_move(h); } - void set_subscribe_props_handler(move_only_function h) { + void set_subscribe_props_handler(move_only_handler h) { h_subscribe_props_ = force_move(h); } - void set_unsubscribe_props_handler(move_only_function h) { + void set_unsubscribe_props_handler(move_only_handler h) { h_unsubscribe_props_ = force_move(h); } - void set_auth_props_handler(move_only_function h) { + void set_auth_props_handler(move_only_handler h) { h_auth_props_ = force_move(h); } @@ -815,7 +797,7 @@ class broker_t { * @param req_client_id - the id that the client wants to use (username will be prepended) * @param will - the last-will-and-testiment of the connection, if any. */ - bool connect_handler( + void connect_handler( con_sp_t spep, buffer client_id, optional noauth_username, @@ -862,12 +844,12 @@ class broker_t { } ); - return true; + return; } if (client_id.empty()) { if (!handle_empty_client_id(spep, client_id, clean_start, connack_props)) { - return false; + return; } // A new client id was generated client_id = buffer(string_view(spep->get_client_id())); @@ -1125,8 +1107,6 @@ class broker_t { ); } } - - return true; } struct connect_param { @@ -1174,7 +1154,7 @@ class broker_t { bool session_present, bool authenticated, v5::properties props, - move_only_function finish = [](error_code){} + move_only_handler finish = [](error_code){} ) { // Reply to the connect message. switch (ep.get_protocol_version()) { @@ -1462,7 +1442,7 @@ class broker_t { return close_proc_no_lock(force_move(spep), send_will, rc); } - bool publish_handler( + void publish_handler( con_sp_t spep, optional packet_id, publish_options pubopts, @@ -1481,7 +1461,7 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; auto send_pubres = [&] (bool authorized = true) { @@ -1528,7 +1508,7 @@ class broker_t { // Publish not authorized send_pubres(false); - return true; + return; } v5::properties forward_props; @@ -1564,10 +1544,9 @@ class broker_t { ); send_pubres(); - return true; } - bool puback_handler( + void puback_handler( con_sp_t spep, packet_id_t packet_id, v5::puback_reason_code /*reason_code*/, @@ -1581,18 +1560,16 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; // const_cast is appropriate here // See https://github.com/boostorg/multi_index/issues/50 auto& ss = const_cast(*it); ss.erase_inflight_message_by_packet_id(packet_id); ss.send_offline_messages_by_packet_id_release(); - - return true; } - bool pubrec_handler( + void pubrec_handler( con_sp_t spep, packet_id_t packet_id, v5::pubrec_reason_code reason_code, @@ -1606,14 +1583,14 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; // const_cast is appropriate here // See https://github.com/boostorg/multi_index/issues/50 auto& ss = const_cast(*it); ss.erase_inflight_message_by_packet_id(packet_id); - if (is_error(reason_code)) return true; + if (is_error(reason_code)) return; auto& ep = *spep; @@ -1650,10 +1627,9 @@ class broker_t { BOOST_ASSERT(false); break; } - return true; } - bool pubrel_handler( + void pubrel_handler( con_sp_t spep, packet_id_t packet_id, v5::pubrel_reason_code reason_code, @@ -1667,7 +1643,7 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; auto& ep = *spep; @@ -1705,10 +1681,9 @@ class broker_t { BOOST_ASSERT(false); break; } - return true; } - bool pubcomp_handler( + void pubcomp_handler( con_sp_t spep, packet_id_t packet_id, v5::pubcomp_reason_code /*reason_code*/, @@ -1722,18 +1697,16 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; // const_cast is appropriate here // See https://github.com/boostorg/multi_index/issues/50 auto& ss = const_cast(*it); ss.erase_inflight_message_by_packet_id(packet_id); ss.send_offline_messages_by_packet_id_release(); - - return true; } - bool subscribe_handler( + void subscribe_handler( con_sp_t spep, packet_id_t packet_id, std::vector entries, @@ -1750,7 +1723,7 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; // The element of sessions_ must have longer lifetime // than corresponding subscription. @@ -1792,7 +1765,7 @@ class broker_t { ); }; - std::vector> retain_deliver; + std::vector> retain_deliver; retain_deliver.reserve(entries.size()); // subscription identifier @@ -1909,10 +1882,9 @@ class broker_t { for (auto& f : retain_deliver) { f(); } - return true; } - bool unsubscribe_handler( + void unsubscribe_handler( con_sp_t spep, packet_id_t packet_id, std::vector entries, @@ -1929,7 +1901,7 @@ class broker_t { // and/or async_force_disconnect () is called. // During async operation, spep is valid but it has already been // erased from sessions_ - if (it == idx.end()) return true; + if (it == idx.end()) return; // The element of sessions_ must have longer lifetime // than corresponding subscription. @@ -1988,8 +1960,6 @@ class broker_t { BOOST_ASSERT(false); break; } - - return true; } /** @@ -2175,16 +2145,16 @@ class broker_t { v5::properties pubrec_props_; v5::properties pubrel_props_; v5::properties pubcomp_props_; - move_only_function h_connect_props_; - move_only_function h_disconnect_props_; - move_only_function h_publish_props_; - move_only_function h_puback_props_; - move_only_function h_pubrec_props_; - move_only_function h_pubrel_props_; - move_only_function h_pubcomp_props_; - move_only_function h_subscribe_props_; - move_only_function h_unsubscribe_props_; - move_only_function h_auth_props_; + move_only_handler h_connect_props_; + move_only_handler h_disconnect_props_; + move_only_handler h_publish_props_; + move_only_handler h_puback_props_; + move_only_handler h_pubrec_props_; + move_only_handler h_pubrel_props_; + move_only_handler h_pubcomp_props_; + move_only_handler h_subscribe_props_; + move_only_handler h_unsubscribe_props_; + move_only_handler h_auth_props_; bool pingresp_ = true; bool connack_ = true; }; diff --git a/include/mqtt/broker/session_state.hpp b/include/mqtt/broker/session_state.hpp index 7bcf2bc8e..158645d4b 100644 --- a/include/mqtt/broker/session_state.hpp +++ b/include/mqtt/broker/session_state.hpp @@ -52,7 +52,7 @@ class session_states; * Retained messages do not form part of the Session State in the Server, they are not deleted as a result of a Session ending. */ struct session_state { - using will_sender_t = move_only_function< + using will_sender_t = move_only_handler< void( session_state const& source_ss, buffer topic, @@ -283,7 +283,7 @@ struct session_state { } } - void set_clean_handler(move_only_function handler) { + void set_clean_handler(move_only_handler handler) { clean_handler_ = force_move(handler); } @@ -601,7 +601,7 @@ struct session_state { std::set qos2_publish_handled_; optional response_topic_; - move_only_function clean_handler_; + move_only_handler clean_handler_; }; class session_states { diff --git a/include/mqtt/callable_overlay.hpp b/include/mqtt/callable_overlay.hpp index 01648fb5d..75d0f5326 100644 --- a/include/mqtt/callable_overlay.hpp +++ b/include/mqtt/callable_overlay.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace MQTT_NS { template @@ -38,20 +38,18 @@ struct callable_overlay final : public Impl * @brief Pingreq handler * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086
* 3.13 PINGREQ – PING request - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_pingreq() noexcept override final { - return ! h_pingreq_ || h_pingreq_(); + MQTT_ALWAYS_INLINE void on_pingreq() noexcept override final { + if ( h_pingreq_) h_pingreq_(); } /** * @brief Pingresp handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200
* 3.13 PINGRESP – PING response - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_pingresp() noexcept override final { - return ! h_pingresp_ || h_pingresp_(); + MQTT_ALWAYS_INLINE void on_pingresp() noexcept override final { + if (h_pingresp_) h_pingresp_(); } // MQTT v3_1_1 handlers @@ -90,22 +88,23 @@ struct callable_overlay final : public Impl * Keep Alive
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237
* 3.1.2.10 Keep Alive - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - MQTT_ALWAYS_INLINE bool on_connect(buffer client_id, + MQTT_ALWAYS_INLINE void on_connect(buffer client_id, optional user_name, optional password, optional will, bool clean_session, std::uint16_t keep_alive) noexcept override final { - return ! h_connect_ - || h_connect_(force_move(client_id), - force_move(user_name), - force_move(password), - force_move(will), - clean_session, - keep_alive); + if (h_connect_) + h_connect_( + force_move(client_id), + force_move(user_name), + force_move(password), + force_move(will), + clean_session, + keep_alive + ); } /** @@ -118,11 +117,9 @@ struct callable_overlay final : public Impl * connect_return_code
* See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036
* 3.2.2.3 Connect Return code - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_connack(bool session_present, connect_return_code return_code) noexcept override final { - return ! h_connack_ - || h_connack_(session_present, return_code); + MQTT_ALWAYS_INLINE void on_connack(bool session_present, connect_return_code return_code) noexcept override final { + if (h_connack_) h_connack_(session_present, return_code); } /** @@ -140,17 +137,18 @@ struct callable_overlay final : public Impl * Topic name * @param contents * Published contents - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_publish(optional packet_id, + MQTT_ALWAYS_INLINE void on_publish(optional packet_id, publish_options pubopts, buffer topic_name, buffer contents) noexcept override final { - return ! h_publish_ - || h_publish_(packet_id, - pubopts, - force_move(topic_name), - force_move(contents)); + if (h_publish_) + h_publish_( + packet_id, + pubopts, + force_move(topic_name), + force_move(contents) + ); } /** @@ -159,11 +157,9 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.4.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_puback(packet_id_t packet_id) noexcept override final { - return ! h_puback_ - || h_puback_(packet_id); + MQTT_ALWAYS_INLINE void on_puback(packet_id_t packet_id) noexcept override final { + if (h_puback_) h_puback_(packet_id); } /** @@ -172,11 +168,9 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050
* 3.5.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_pubrec(packet_id_t packet_id) noexcept override final { - return ! h_pubrec_ - || h_pubrec_(packet_id); + MQTT_ALWAYS_INLINE void on_pubrec(packet_id_t packet_id) noexcept override final { + if (h_pubrec_) h_pubrec_(packet_id); } /** @@ -185,11 +179,9 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791
* 3.6.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_pubrel(packet_id_t packet_id) noexcept override final { - return ! h_pubrel_ - || h_pubrel_(packet_id); + MQTT_ALWAYS_INLINE void on_pubrel(packet_id_t packet_id) noexcept override final { + if (h_pubrel_) h_pubrel_(packet_id); } /** @@ -198,11 +190,9 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060
* 3.7.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_pubcomp(packet_id_t packet_id) noexcept override final { - return ! h_pubcomp_ - || h_pubcomp_(packet_id); + MQTT_ALWAYS_INLINE void on_pubcomp(packet_id_t packet_id) noexcept override final { + if (h_pubcomp_) h_pubcomp_(packet_id); } /** @@ -213,12 +203,10 @@ struct callable_overlay final : public Impl * @param entries * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_subscribe(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_subscribe(packet_id_t packet_id, std::vector entries) noexcept override final { - return ! h_subscribe_ - || h_subscribe_(packet_id, force_move(entries)); + if (h_subscribe_) h_subscribe_(packet_id, force_move(entries)); } /** @@ -230,12 +218,10 @@ struct callable_overlay final : public Impl * Collection of QoS that is corresponding to subscribed topic order.
* If subscription is failure, the value is nullopt.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_suback(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_suback(packet_id_t packet_id, std::vector reasons) noexcept override final { - return ! h_suback_ - || h_suback_(packet_id, force_move(reasons)); + if (h_suback_) h_suback_(packet_id, force_move(reasons)); } /** @@ -246,12 +232,10 @@ struct callable_overlay final : public Impl * @param topics * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_unsubscribe(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_unsubscribe(packet_id_t packet_id, std::vector entries) noexcept override final { - return ! h_unsubscribe_ - || h_unsubscribe_(packet_id, force_move(entries)); + if (h_unsubscribe_) h_unsubscribe_(packet_id, force_move(entries)); } /** @@ -259,11 +243,9 @@ struct callable_overlay final : public Impl * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.11.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_unsuback(packet_id_t packet_id) noexcept override final { - return ! h_unsuback_ - || h_unsuback_(packet_id); + MQTT_ALWAYS_INLINE void on_unsuback(packet_id_t packet_id) noexcept override final { + if (h_unsuback_) h_unsuback_(packet_id); } /** @@ -272,7 +254,7 @@ struct callable_overlay final : public Impl * 3.14 DISCONNECT – Disconnect notification */ MQTT_ALWAYS_INLINE void on_disconnect() noexcept override final { - if(h_disconnect_) h_disconnect_(); + if (h_disconnect_) h_disconnect_(); } // MQTT v5 handlers @@ -317,24 +299,25 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - MQTT_ALWAYS_INLINE bool on_v5_connect(buffer client_id, + MQTT_ALWAYS_INLINE void on_v5_connect(buffer client_id, optional user_name, optional password, optional will, bool clean_start, std::uint16_t keep_alive, v5::properties props) noexcept override final { - return ! h_v5_connect_ - || h_v5_connect_(force_move(client_id), - force_move(user_name), - force_move(password), - force_move(will), - clean_start, - keep_alive, - force_move(props)); + if (h_v5_connect_) + h_v5_connect_( + force_move(client_id), + force_move(user_name), + force_move(password), + force_move(will), + clean_start, + keep_alive, + force_move(props) + ); } /** @@ -351,13 +334,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080
* 3.2.2.3 CONNACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_connack(bool session_present, + MQTT_ALWAYS_INLINE void on_v5_connack(bool session_present, v5::connect_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_connack_ - || h_v5_connack_(session_present, reason_code, force_move(props)); + if (h_v5_connack_) h_v5_connack_(session_present, reason_code, force_move(props)); } /** @@ -383,19 +364,20 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109
* 3.3.2.3 PUBLISH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_publish(optional packet_id, + MQTT_ALWAYS_INLINE void on_v5_publish(optional packet_id, publish_options pubopts, buffer topic_name, buffer contents, v5::properties props) noexcept override final { - return ! h_v5_publish_ - || h_v5_publish_(packet_id, - pubopts, - force_move(topic_name), - force_move(contents), - force_move(props)); + if (h_v5_publish_) + h_v5_publish_( + packet_id, + pubopts, + force_move(topic_name), + force_move(contents), + force_move(props) + ); } /** @@ -412,13 +394,16 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125
* 3.4.2.2 PUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_puback(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_puback(packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_puback_ - || h_v5_puback_(packet_id, reason_code, force_move(props)); + if (h_v5_puback_) + h_v5_puback_( + packet_id, + reason_code, + force_move(props) + ); } /** @@ -435,13 +420,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135
* 3.5.2.2 PUBREC Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_pubrec(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_pubrec(packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_pubrec_ - || h_v5_pubrec_(packet_id, reason_code, force_move(props)); + if (h_v5_pubrec_) h_v5_pubrec_(packet_id, reason_code, force_move(props)); } /** @@ -458,13 +441,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_pubrel(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_pubrel(packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_pubrel_ - || h_v5_pubrel_(packet_id, reason_code, force_move(props)); + if (h_v5_pubrel_) h_v5_pubrel_(packet_id, reason_code, force_move(props)); } /** @@ -481,13 +462,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155
* 3.7.2.2 PUBCOMP Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_pubcomp(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_pubcomp(packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_pubcomp_ - || h_v5_pubcomp_(packet_id, reason_code, force_move(props)); + if (h_v5_pubcomp_) h_v5_pubcomp_(packet_id, reason_code, force_move(props)); } /** @@ -502,13 +481,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_subscribe(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_subscribe(packet_id_t packet_id, std::vector entries, v5::properties props) noexcept override final { - return ! h_v5_subscribe_ - || h_v5_subscribe_(packet_id, force_move(entries), force_move(props)); + if (h_v5_subscribe_) h_v5_subscribe_(packet_id, force_move(entries), force_move(props)); } /** @@ -524,13 +501,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_suback(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_suback(packet_id_t packet_id, std::vector reasons, v5::properties props) noexcept override final { - return ! h_v5_suback_ - || h_v5_suback_(packet_id, force_move(reasons), force_move(props)); + if (h_v5_suback_) h_v5_suback_(packet_id, force_move(reasons), force_move(props)); } /** @@ -546,13 +521,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_unsubscribe(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_unsubscribe(packet_id_t packet_id, std::vector entries, v5::properties props) noexcept override final { - return ! h_v5_unsubscribe_ - || h_v5_unsubscribe_(packet_id, force_move(entries), force_move(props)); + if (h_v5_unsubscribe_) h_v5_unsubscribe_(packet_id, force_move(entries), force_move(props)); } /** @@ -568,13 +541,11 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_unsuback(packet_id_t packet_id, + MQTT_ALWAYS_INLINE void on_v5_unsuback(packet_id_t packet_id, std::vector reasons, v5::properties props) noexcept override final { - return ! h_v5_unsuback_ - || h_v5_unsuback_(packet_id, force_move(reasons), force_move(props)); + if (h_v5_unsuback_) h_v5_unsuback_(packet_id, force_move(reasons), force_move(props)); } /** @@ -607,12 +578,10 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221
* 3.15.2.2 AUTH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - MQTT_ALWAYS_INLINE bool on_v5_auth(v5::auth_reason_code reason_code, + MQTT_ALWAYS_INLINE void on_v5_auth(v5::auth_reason_code reason_code, v5::properties props) noexcept override final { - return ! h_v5_auth_ - || h_v5_auth_(reason_code, force_move(props)); + if (h_v5_auth_) h_v5_auth_(reason_code, force_move(props)); } @@ -757,17 +726,15 @@ struct callable_overlay final : public Impl * @brief Pingreq handler * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086
* 3.13 PINGREQ – PING request - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pingreq_handler = move_only_function; + using pingreq_handler = move_only_handler; /** * @brief Pingresp handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200
* 3.13 PINGRESP – PING response - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pingresp_handler = move_only_function; + using pingresp_handler = move_only_handler; // MQTT v3_1_1 handlers @@ -806,11 +773,10 @@ struct callable_overlay final : public Impl * Keep Alive
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237
* 3.1.2.10 Keep Alive - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - using connect_handler = move_only_function< - bool(buffer client_id, + using connect_handler = move_only_handler< + void(buffer client_id, optional user_name, optional password, optional will, @@ -827,9 +793,8 @@ struct callable_overlay final : public Impl * connect_return_code
* See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036
* 3.2.2.3 Connect Return code - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using connack_handler = move_only_function; + using connack_handler = move_only_handler; /** * @brief Publish handler @@ -846,9 +811,8 @@ struct callable_overlay final : public Impl * Topic name * @param contents * Published contents - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using publish_handler = move_only_function packet_id, + using publish_handler = move_only_handler packet_id, publish_options pubopts, buffer topic_name, buffer contents)>; @@ -859,9 +823,8 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.4.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using puback_handler = move_only_function; + using puback_handler = move_only_handler; /** * @brief Pubrec handler @@ -869,9 +832,8 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050
* 3.5.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubrec_handler = move_only_function; + using pubrec_handler = move_only_handler; /** * @brief Pubrel handler @@ -879,9 +841,8 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791
* 3.6.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubrel_handler = move_only_function; + using pubrel_handler = move_only_handler; /** * @brief Pubcomp handler @@ -889,9 +850,8 @@ struct callable_overlay final : public Impl * packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060
* 3.7.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using pubcomp_handler = move_only_function; + using pubcomp_handler = move_only_handler; /** * @brief Subscribe handler @@ -901,9 +861,8 @@ struct callable_overlay final : public Impl * @param entries * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - using subscribe_handler = move_only_function entries)>; /** @@ -915,9 +874,8 @@ struct callable_overlay final : public Impl * Collection of QoS that is corresponding to subscribed topic order.
* If subscription is failure, the value is nullopt.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - using suback_handler = move_only_function qoss)>; /** @@ -928,9 +886,8 @@ struct callable_overlay final : public Impl * @param entries * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - using unsubscribe_handler = move_only_function entries)>; /** @@ -938,16 +895,15 @@ struct callable_overlay final : public Impl * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.11.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using unsuback_handler = move_only_function; + using unsuback_handler = move_only_handler; /** * @brief Disconnect handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463
* 3.14 DISCONNECT – Disconnect notification */ - using disconnect_handler = move_only_function; + using disconnect_handler = move_only_handler; // MQTT v5 handlers @@ -991,11 +947,10 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - using v5_connect_handler = move_only_function< - bool(buffer client_id, + using v5_connect_handler = move_only_handler< + void(buffer client_id, optional user_name, optional password, optional will, @@ -1018,10 +973,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080
* 3.2.2.3 CONNACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_connack_handler = move_only_function< - bool(bool session_present, + using v5_connack_handler = move_only_handler< + void(bool session_present, v5::connect_reason_code reason_code, v5::properties props) >; @@ -1049,10 +1003,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109
* 3.3.2.3 PUBLISH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_publish_handler = move_only_function< - bool(optional packet_id, + using v5_publish_handler = move_only_handler< + void(optional packet_id, publish_options pubopts, buffer topic_name, buffer contents, @@ -1073,10 +1026,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125
* 3.4.2.2 PUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_puback_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_puback_handler = move_only_handler< + void(packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props) >; @@ -1095,10 +1047,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135
* 3.5.2.2 PUBREC Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubrec_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_pubrec_handler = move_only_handler< + void(packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props) >; @@ -1117,10 +1068,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubrel_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_pubrel_handler = move_only_handler< + void(packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props) >; @@ -1139,10 +1089,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155
* 3.7.2.2 PUBCOMP Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_pubcomp_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_pubcomp_handler = move_only_handler< + void(packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props) >; @@ -1159,10 +1108,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_subscribe_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_subscribe_handler = move_only_handler< + void(packet_id_t packet_id, std::vector entries, v5::properties props) >; @@ -1180,10 +1128,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_suback_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_suback_handler = move_only_handler< + void(packet_id_t packet_id, std::vector reasons, v5::properties props) >; @@ -1201,10 +1148,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_unsubscribe_handler = move_only_function< - bool(packet_id_t packet_id, + using v5_unsubscribe_handler = move_only_handler< + void(packet_id_t packet_id, std::vector entries, v5::properties props) >; @@ -1222,10 +1168,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_unsuback_handler = move_only_function< - bool(packet_id_t, + using v5_unsuback_handler = move_only_handler< + void(packet_id_t, std::vector reasons, v5::properties props) >; @@ -1243,7 +1188,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
* 3.14.2.2 DISCONNECT Properties */ - using v5_disconnect_handler = move_only_function< + using v5_disconnect_handler = move_only_handler< void(v5::disconnect_reason_code reason_code, v5::properties props) >; @@ -1260,10 +1205,9 @@ struct callable_overlay final : public Impl * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221
* 3.15.2.2 AUTH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - using v5_auth_handler = move_only_function< - bool(v5::auth_reason_code reason_code, + using v5_auth_handler = move_only_handler< + void(v5::auth_reason_code reason_code, v5::properties props) >; @@ -1276,7 +1220,7 @@ struct callable_overlay final : public Impl * This handler is called if the client called `disconnect()` and the server closed the socket cleanly. * If the socket is closed by other reasons, error_handler is called. */ - using close_handler = move_only_function; + using close_handler = move_only_handler; /** * @brief Error handler @@ -1285,7 +1229,7 @@ struct callable_overlay final : public Impl * * @param ec error code */ - using error_handler = move_only_function; + using error_handler = move_only_handler; /** * @brief Publish response sent handler @@ -1295,7 +1239,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026
* 2.2.1 Packet Identifier */ - using pub_res_sent_handler = move_only_function; + using pub_res_sent_handler = move_only_handler; /** * @brief Serialize publish handler @@ -1303,7 +1247,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg publish message */ - using serialize_publish_message_handler = move_only_function msg)>; + using serialize_publish_message_handler = move_only_handler msg)>; /** * @brief Serialize publish handler @@ -1311,7 +1255,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg v5::publish message */ - using serialize_v5_publish_message_handler = move_only_function msg)>; + using serialize_v5_publish_message_handler = move_only_handler msg)>; /** * @brief Serialize publish handler @@ -1321,7 +1265,7 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_publish_handler = move_only_function; + using serialize_publish_handler = move_only_handler; /** * @brief Serialize pubrel handler @@ -1331,7 +1275,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_pubrel_message_handler = move_only_function msg)>; + using serialize_pubrel_message_handler = move_only_handler msg)>; /** * @brief Serialize pubrel handler @@ -1341,7 +1285,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_v5_pubrel_message_handler = move_only_function msg)>; + using serialize_v5_pubrel_message_handler = move_only_handler msg)>; /** * @brief Serialize pubrel handler @@ -1353,19 +1297,19 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_pubrel_handler = move_only_function; + using serialize_pubrel_handler = move_only_handler; /** * @brief Remove serialized message * @param packet_id packet identifier of the removing message */ - using serialize_remove_handler = move_only_function; + using serialize_remove_handler = move_only_handler; /** * @brief Pre-send handler * This handler is called when any mqtt control packet is decided to send. */ - using pre_send_handler = move_only_function; + using pre_send_handler = move_only_handler; /** * @brief is valid length handler @@ -1383,7 +1327,7 @@ struct callable_overlay final : public Impl * @param func A callback function that is called when async operation will finish. */ using mqtt_message_processed_handler = - move_only_function; + move_only_handler; diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index 527bf303d..b4185db58 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -501,8 +501,6 @@ class client : public endpoint { protected: struct constructor_access{}; public: - using async_handler_t = typename base::async_handler_t; - /** * Constructor used by factory functions at the end of this file. */ diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 49dd21e25..82271cc9c 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -71,7 +71,7 @@ #include #include #include -#include +#include #if defined(MQTT_USE_WS) #include @@ -174,7 +174,6 @@ class endpoint : public std::enable_shared_from_this; public: - using async_handler_t = move_only_function; using packet_id_t = typename packet_id_type::type; /** @@ -239,15 +238,14 @@ class endpoint : public std::enable_shared_from_this * 3.13 PINGRESP – PING response - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_pingresp() noexcept = 0; + virtual void on_pingresp() noexcept = 0; // MQTT v3_1_1 handlers @@ -286,10 +284,9 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349237
* 3.1.2.10 Keep Alive - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - virtual bool on_connect(buffer client_id, + virtual void on_connect(buffer client_id, optional user_name, optional password, optional will, @@ -306,9 +303,8 @@ class endpoint : public std::enable_shared_from_this * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036
* 3.2.2.3 Connect Return code - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_connack(bool session_present, connect_return_code return_code) noexcept = 0; + virtual void on_connack(bool session_present, connect_return_code return_code) noexcept = 0; /** * @brief Publish handler @@ -325,9 +321,8 @@ class endpoint : public std::enable_shared_from_this packet_id, + virtual void on_publish(optional packet_id, publish_options pubopts, buffer topic_name, buffer contents) noexcept = 0; @@ -338,9 +333,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.4.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_puback(packet_id_t packet_id) noexcept = 0; + virtual void on_puback(packet_id_t packet_id) noexcept = 0; /** * @brief Pubrec handler @@ -348,9 +342,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050
* 3.5.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_pubrec(packet_id_t packet_id) noexcept = 0; + virtual void on_pubrec(packet_id_t packet_id) noexcept = 0; /** * @brief Pubrel handler @@ -358,9 +351,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791
* 3.6.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_pubrel(packet_id_t packet_id) noexcept = 0; + virtual void on_pubrel(packet_id_t packet_id) noexcept = 0; /** * @brief Pubcomp handler @@ -368,9 +360,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060
* 3.7.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_pubcomp(packet_id_t packet_id) noexcept = 0; + virtual void on_pubcomp(packet_id_t packet_id) noexcept = 0; /** * @brief Subscribe handler @@ -380,9 +371,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_subscribe(packet_id_t packet_id, + virtual void on_subscribe(packet_id_t packet_id, std::vector entries) noexcept = 0; /** @@ -394,9 +384,8 @@ class endpoint : public std::enable_shared_from_this * If subscription is failure, the value is nullopt.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_suback(packet_id_t packet_id, std::vector returns) noexcept = 0; + virtual void on_suback(packet_id_t packet_id, std::vector returns) noexcept = 0; /** * @brief Unsubscribe handler @@ -406,18 +395,16 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
- * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_unsubscribe(packet_id_t packet_id, std::vector entries) noexcept = 0; + virtual void on_unsubscribe(packet_id_t packet_id, std::vector entries) noexcept = 0; /** * @brief Unsuback handler * @param packet_id packet identifier
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.11.2 Variable header - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_unsuback(packet_id_t) noexcept = 0; + virtual void on_unsuback(packet_id_t) noexcept = 0; /** * @brief Disconnect handler @@ -468,10 +455,9 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @return if the handler returns true, then continue receiving, otherwise quit. * */ - virtual bool on_v5_connect(buffer client_id, + virtual void on_v5_connect(buffer client_id, optional user_name, optional password, optional will, @@ -493,9 +479,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080
* 3.2.2.3 CONNACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_connack(bool session_present, + virtual void on_v5_connack(bool session_present, v5::connect_reason_code reason_code, v5::properties props) noexcept = 0; @@ -522,9 +507,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109
* 3.3.2.3 PUBLISH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_publish(optional packet_id, + virtual void on_v5_publish(optional packet_id, publish_options pubopts, buffer topic_name, buffer contents, @@ -544,9 +528,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125
* 3.4.2.2 PUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_puback(packet_id_t packet_id, + virtual void on_v5_puback(packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props) noexcept = 0; @@ -564,9 +547,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135
* 3.5.2.2 PUBREC Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_pubrec(packet_id_t packet_id, + virtual void on_v5_pubrec(packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props) noexcept = 0; @@ -584,9 +566,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_pubrel(packet_id_t packet_id, + virtual void on_v5_pubrel(packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props) noexcept = 0; @@ -604,9 +585,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155
* 3.7.2.2 PUBCOMP Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_pubcomp(packet_id_t packet_id, + virtual void on_v5_pubcomp(packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props) noexcept = 0; @@ -622,9 +602,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_subscribe(packet_id_t packet_id, + virtual void on_v5_subscribe(packet_id_t packet_id, std::vector entries, v5::properties props) noexcept = 0; @@ -641,9 +620,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_suback(packet_id_t packet_id, + virtual void on_v5_suback(packet_id_t packet_id, std::vector reasons, v5::properties props) noexcept = 0; @@ -660,9 +638,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_unsubscribe(packet_id_t packet_id, + virtual void on_v5_unsubscribe(packet_id_t packet_id, std::vector entries, v5::properties props) noexcept = 0; @@ -679,9 +656,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_unsuback(packet_id_t, + virtual void on_v5_unsuback(packet_id_t, std::vector reasons, v5::properties props) noexcept = 0; @@ -713,9 +689,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221
* 3.15.2.2 AUTH Properties - * @return if the handler returns true, then continue receiving, otherwise quit. */ - virtual bool on_v5_auth(v5::auth_reason_code reason_code, + virtual void on_v5_auth(v5::auth_reason_code reason_code, v5::properties props) noexcept = 0; // Original handlers @@ -4323,7 +4298,7 @@ class endpoint : public std::enable_shared_from_this f) { + void for_each_store(move_only_handler f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "for_each_store(ptr, size)"; @@ -4345,7 +4320,7 @@ class endpoint : public std::enable_shared_from_this)> f) { + void for_each_store(move_only_handler)> f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "for_each_store(store_message_variant)"; @@ -4366,7 +4341,7 @@ class endpoint : public std::enable_shared_from_this, any)> f) { + void for_each_store_with_life_keeper(move_only_handler, any)> f) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -5749,7 +5724,7 @@ class endpoint : public std::enable_shared_from_this; using parse_handler = - move_only_function< + move_only_handler< void( this_type_sp&& spep, any&& session_life_keeper, @@ -7370,58 +7345,56 @@ class endpoint : public std::enable_shared_from_this(in_place_init, - force_move(will_topic_), - force_move(will_payload_), - connect_flags::has_will_retain(connect_flag_) | connect_flags::will_qos(connect_flag_)) + ep_.on_connect( + force_move(client_id_), + force_move(user_name_), + force_move(password_), + connect_flags::has_will_flag(connect_flag_) + ? optional( + in_place_init, + force_move(will_topic_), + force_move(will_payload_), + connect_flags::has_will_retain(connect_flag_) | connect_flags::will_qos(connect_flag_)) : optional(nullopt), - ep_.clean_session(), - keep_alive_ - ) - ) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.clean_session(), + keep_alive_ + ); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_connect( - force_move(client_id_), - force_move(user_name_), - force_move(password_), - connect_flags::has_will_flag(connect_flag_) - ? optional(in_place_init, - force_move(will_topic_), - force_move(will_payload_), - connect_flags::has_will_retain(connect_flag_) | connect_flags::will_qos(connect_flag_), - force_move(will_props_)) + ep_.on_v5_connect( + force_move(client_id_), + force_move(user_name_), + force_move(password_), + connect_flags::has_will_flag(connect_flag_) + ? optional( + in_place_init, + force_move(will_topic_), + force_move(will_payload_), + connect_flags::has_will_retain(connect_flag_) | connect_flags::will_qos(connect_flag_), + force_move(will_props_)) : optional(nullopt), - ep_.clean_start(), - keep_alive_, - force_move(props_) - ) - ) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.clean_start(), + keep_alive_, + force_move(props_) + ); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -7543,39 +7516,35 @@ class endpoint : public std::enable_shared_from_this(reason_code_) - ) - ) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_connack( + session_present_, + variant_get(reason_code_) + ); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_connack( - session_present_, - variant_get(reason_code_), - force_move(props_) - ) - ) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_connack( + session_present_, + variant_get(reason_code_), + force_move(props_) + ); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -7775,12 +7744,13 @@ class endpoint : public std::enable_shared_from_this(var)) ); + return true; case protocol_version::v5: switch (qos_value_) { case qos::at_most_once: @@ -7809,7 +7779,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -7838,7 +7808,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -7884,16 +7854,14 @@ class endpoint : public std::enable_shared_from_this(var)), - force_move(props_) - ); - return ret; - } + ep_.on_v5_publish( + packet_id_, + publish_options(ep_.fixed_header_), + force_move(topic_name_), + force_move(variant_get(var)), + force_move(props_) + ); + return true; default: BOOST_ASSERT(false); } @@ -7906,7 +7874,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -7919,7 +7887,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -7954,7 +7922,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -7989,7 +7957,7 @@ class endpoint : public std::enable_shared_from_this( any_cast< - std::tuple + std::tuple >(session_life_keeper) ) ) @@ -8130,31 +8098,29 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_puback(packet_id_); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: if (erased) ep_.send_publish_queue_one(); - if (ep_.on_v5_puback(packet_id_, reason_code_, force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_puback(packet_id_, reason_code_, force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -8325,36 +8291,34 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_pubrec(packet_id_); + res(); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: if (erased && is_error(reason_code_)) { ep_.on_serialize_remove(packet_id_); ep_.send_publish_queue_one(); } - if (ep_.on_v5_pubrec(packet_id_, reason_code_, force_move(props_))) { - if (!is_error(reason_code_)) res(); - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_pubrec(packet_id_, reason_code_, force_move(props_)); + if (!is_error(reason_code_)) res(); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -8488,32 +8452,30 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_pubrel(packet_id_); + res(); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_pubrel(packet_id_, reason_code_, force_move(props_))) { - res(); - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_pubrel(packet_id_, reason_code_, force_move(props_)); + res(); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -8634,17 +8596,16 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_pubcomp(packet_id_); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: if ( @@ -8656,17 +8617,16 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_pubcomp(packet_id_, reason_code_, force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -8802,30 +8762,28 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_subscribe(packet_id_, force_move(entries_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_subscribe(packet_id_, force_move(entries_), force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_subscribe(packet_id_, force_move(entries_), force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -8953,17 +8911,16 @@ class endpoint : public std::enable_shared_from_this(e); } ); - if (ep_.on_suback(packet_id_, force_move(results))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_suback(packet_id_, force_move(results)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; } case protocol_version::v5: @@ -8989,17 +8946,16 @@ class endpoint : public std::enable_shared_from_this(e); } ); - if (ep_.on_v5_suback(packet_id_, force_move(reasons), force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_suback(packet_id_, force_move(reasons), force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; } default: @@ -9113,30 +9069,28 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_unsubscribe(packet_id_, force_move(entries_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_unsubscribe(packet_id_, force_move(entries_), force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_unsubscribe(packet_id_, force_move(entries_), force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -9252,30 +9206,28 @@ class endpoint : public std::enable_shared_from_this( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_unsuback(packet_id_); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; case protocol_version::v5: - if (ep_.on_v5_unsuback(packet_id_, force_move(reasons_), force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) + ep_.on_v5_unsuback(packet_id_, force_move(reasons_), force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) ) - ); - } + ) + ); break; default: BOOST_ASSERT(false); @@ -9306,9 +9258,8 @@ class endpoint : public std::enable_shared_from_this(var)); BOOST_ASSERT(ep_.version_ == protocol_version::v5); - if (ep_.on_v5_auth(reason_code_, force_move(props_))) { - ep_.on_mqtt_message_processed( - force_move( - std::get<0>( - any_cast< - std::tuple - >(session_life_keeper) - ) - ) - ); - } - return; - } - BOOST_ASSERT(ep_.version_ == protocol_version::v5); - if (ep_.on_v5_auth(reason_code_, force_move(props_))) { + ep_.on_v5_auth(reason_code_, force_move(props_)); ep_.on_mqtt_message_processed( force_move( - session_life_keeper + std::get<0>( + any_cast< + std::tuple + >(session_life_keeper) + ) ) ); + return; } + BOOST_ASSERT(ep_.version_ == protocol_version::v5); + ep_.on_v5_auth(reason_code_, force_move(props_)); + ep_.on_mqtt_message_processed( + force_move( + session_life_keeper + ) + ); } } diff --git a/include/mqtt/move_only_handler.hpp b/include/mqtt/move_only_handler.hpp new file mode 100644 index 000000000..03e041bd4 --- /dev/null +++ b/include/mqtt/move_only_handler.hpp @@ -0,0 +1,66 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_MOVE_ONLY_HANDLER_HPP) +#define MQTT_MOVE_ONLY_HANDLER_HPP + +#include + +#include + +#include +#include +#include +#include + +namespace MQTT_NS { + +namespace as = boost::asio; + +template +struct move_only_handler { + using executor_type = as::any_io_executor; + + move_only_handler() = default; + + template < + typename Func, + typename std::enable_if_t< + std::is_convertible>::value + >* = nullptr + > + move_only_handler(Func&& f) + : exe_{as::get_associated_executor(f)}, + func_{std::forward(f)} + { + } + + executor_type get_executor() const { return exe_; } + + template + void operator()(Params&&... params) { + if (exe_ == as::system_executor()) { + func_(std::forward(params)...); + return; + } + as::dispatch( + exe_, + [func = force_move(func_), pt = std::tuple(std::forward(params)...)] () mutable { + MQTT_NS::apply(force_move(func), std::move(pt)); + } + ); + } + + operator bool() const { return static_cast(func_); } + +private: + executor_type exe_; + move_only_function func_; +}; + +} // namespace MQTT_NS + +#endif // MQTT_MOVE_ONLY_HANDLER_HPP diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 1e8c85fdc..b44b10a28 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include namespace MQTT_NS { @@ -54,7 +54,7 @@ class server { * After this handler called, the next accept will automatically start. * @param ep endpoint of the connecting client */ - using accept_handler = move_only_function ep)>; + using accept_handler = move_only_handler ep)>; /** * @brief Error handler during after accepted before connection established @@ -62,7 +62,7 @@ class server { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = move_only_function; + using connection_error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -70,7 +70,7 @@ class server { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = move_only_function; + using error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -79,7 +79,7 @@ class server { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = move_only_function; + using error_handler_with_ioc = move_only_handler; template server( @@ -259,7 +259,7 @@ class server_tls { * After this handler called, the next accept will automatically start. * @param ep endpoint of the connecting client */ - using accept_handler = move_only_function ep)>; + using accept_handler = move_only_handler ep)>; /** * @brief Error handler during after accepted before connection established @@ -267,7 +267,7 @@ class server_tls { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = move_only_function; + using connection_error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -275,7 +275,7 @@ class server_tls { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = move_only_function; + using error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -284,7 +284,7 @@ class server_tls { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = move_only_function; + using error_handler_with_ioc = move_only_handler; template server_tls( @@ -583,7 +583,7 @@ class server_ws { * @brief Accept handler * @param ep endpoint of the connecting client */ - using accept_handler = move_only_function ep)>; + using accept_handler = move_only_handler ep)>; /** * @brief Error handler during after accepted before connection established @@ -591,7 +591,7 @@ class server_ws { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = move_only_function; + using connection_error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -599,7 +599,7 @@ class server_ws { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = move_only_function; + using error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -608,7 +608,7 @@ class server_ws { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = move_only_function; + using error_handler_with_ioc = move_only_handler; template server_ws( @@ -947,7 +947,7 @@ class server_tls_ws { * @brief Accept handler * @param ep endpoint of the connecting client */ - using accept_handler = move_only_function ep)>; + using accept_handler = move_only_handler ep)>; /** * @brief Error handler during after accepted before connection established @@ -955,7 +955,7 @@ class server_tls_ws { * @param ec error code * @param ioc_con io_context for incoming connection */ - using connection_error_handler = move_only_function; + using connection_error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -963,7 +963,7 @@ class server_tls_ws { * You need to call listen() again if you want to restart accepting. * @param ec error code */ - using error_handler = move_only_function; + using error_handler = move_only_handler; /** * @brief Error handler for listen and accpet @@ -972,7 +972,7 @@ class server_tls_ws { * @param ec error code * @param ioc_con io_context for listen or accept */ - using error_handler_with_ioc = move_only_function; + using error_handler_with_ioc = move_only_handler; template server_tls_ws( diff --git a/include/mqtt/store.hpp b/include/mqtt/store.hpp index 3fa0cdcc9..d947eb5db 100644 --- a/include/mqtt/store.hpp +++ b/include/mqtt/store.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace MQTT_NS { diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 295294d71..4331d322c 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include namespace MQTT_NS { @@ -33,7 +33,7 @@ class tcp_endpoint : public socket { MQTT_ALWAYS_INLINE void async_read( as::mutable_buffer buffers, - move_only_function handler + move_only_handler handler ) override final { as::async_read( tcp_, @@ -47,7 +47,7 @@ class tcp_endpoint : public socket { MQTT_ALWAYS_INLINE void async_write( std::vector buffers, - move_only_function handler + move_only_handler handler ) override final { as::async_write( tcp_, @@ -66,21 +66,21 @@ class tcp_endpoint : public socket { return as::write(tcp_,force_move(buffers), ec); } - MQTT_ALWAYS_INLINE void post(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void post(move_only_handler handler) override final { as::post( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void dispatch(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void dispatch(move_only_handler handler) override final { as::dispatch( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void defer(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void defer(move_only_handler handler) override final { as::defer( strand_, force_move(handler) @@ -103,7 +103,7 @@ class tcp_endpoint : public socket { shutdown_and_close_impl(tcp_, ec); } - MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_handler handler) override final { async_shutdown_and_close_impl(tcp_, force_move(handler)); } @@ -157,7 +157,7 @@ class tcp_endpoint : public socket { << ec.message(); } - void async_shutdown_and_close_impl(as::basic_socket& s, move_only_function handler) { + void async_shutdown_and_close_impl(as::basic_socket& s, move_only_handler handler) { post( [this, &s, handler = force_move(handler)] () mutable { error_code ec; @@ -176,7 +176,7 @@ class tcp_endpoint : public socket { << ec.message(); shutdown_and_close_impl(lowest_layer(), ec); } - void async_shutdown_and_close_impl(tls::stream& s, move_only_function handler) { + void async_shutdown_and_close_impl(tls::stream& s, move_only_handler handler) { s.async_shutdown( as::bind_executor( strand_, diff --git a/include/mqtt/type_erased_socket.hpp b/include/mqtt/type_erased_socket.hpp index 4041311dc..c77fdf34d 100644 --- a/include/mqtt/type_erased_socket.hpp +++ b/include/mqtt/type_erased_socket.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace MQTT_NS { @@ -23,17 +23,17 @@ namespace as = boost::asio; class socket { public: virtual ~socket() = default; - virtual void async_read(as::mutable_buffer, move_only_function) = 0; - virtual void async_write(std::vector, move_only_function) = 0; + virtual void async_read(as::mutable_buffer, move_only_handler) = 0; + virtual void async_write(std::vector, move_only_handler) = 0; virtual std::size_t write(std::vector, boost::system::error_code&) = 0; - virtual void post(move_only_function) = 0; - virtual void dispatch(move_only_function) = 0; - virtual void defer(move_only_function) = 0; + virtual void post(move_only_handler) = 0; + virtual void dispatch(move_only_handler) = 0; + virtual void defer(move_only_handler) = 0; virtual bool running_in_this_thread() const = 0; virtual as::ip::tcp::socket::lowest_layer_type& lowest_layer() = 0; virtual any native_handle() = 0; virtual void clean_shutdown_and_close(boost::system::error_code&) = 0; - virtual void async_clean_shutdown_and_close(move_only_function) = 0; + virtual void async_clean_shutdown_and_close(move_only_handler) = 0; virtual void force_shutdown_and_close(boost::system::error_code&) = 0; virtual as::any_io_executor get_executor() = 0; }; diff --git a/include/mqtt/ws_endpoint.hpp b/include/mqtt/ws_endpoint.hpp index 9d784ea86..595937676 100644 --- a/include/mqtt/ws_endpoint.hpp +++ b/include/mqtt/ws_endpoint.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include namespace MQTT_NS { @@ -45,12 +45,12 @@ class ws_endpoint : public socket { MQTT_ALWAYS_INLINE void async_read( as::mutable_buffer buffers, - move_only_function handler + move_only_handler handler ) override final { auto req_size = as::buffer_size(buffers); using beast_read_handler_t = - move_only_function)>; + move_only_handler)>; std::shared_ptr beast_read_handler; if (req_size <= buffer_.size()) { @@ -65,13 +65,13 @@ class ws_endpoint : public socket { [this, req_size, buffers, handler = force_move(handler)] (error_code ec, std::shared_ptr const& v) mutable { if (ec) { - force_move(handler)(ec, 0); + force_move(handler)(ec, std::size_t(0)); return; } if (!ws_.got_binary()) { buffer_.consume(buffer_.size()); force_move(handler) - (boost::system::errc::make_error_code(boost::system::errc::bad_message), 0); + (boost::system::errc::make_error_code(boost::system::errc::bad_message), std::size_t(0)); return; } if (req_size > buffer_.size()) { @@ -108,7 +108,7 @@ class ws_endpoint : public socket { MQTT_ALWAYS_INLINE void async_write( std::vector buffers, - move_only_function handler + move_only_handler handler ) override final { ws_.async_write( buffers, @@ -127,21 +127,21 @@ class ws_endpoint : public socket { return as::buffer_size(buffers); } - MQTT_ALWAYS_INLINE void post(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void post(move_only_handler handler) override final { as::post( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void dispatch(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void dispatch(move_only_handler handler) override final { as::dispatch( strand_, force_move(handler) ); } - MQTT_ALWAYS_INLINE void defer(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void defer(move_only_handler handler) override final { as::defer( strand_, force_move(handler) @@ -188,7 +188,7 @@ class ws_endpoint : public socket { shutdown_and_close_impl(next_layer(), ec); } - MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_function handler) override final { + MQTT_ALWAYS_INLINE void async_clean_shutdown_and_close(move_only_handler handler) override final { if (ws_.is_open()) { // WebSocket closing process MQTT_LOG("mqtt_impl", trace) @@ -273,7 +273,7 @@ class ws_endpoint : public socket { } private: - void async_read_until_closed(move_only_function handler) { + void async_read_until_closed(move_only_handler handler) { auto buffer = std::make_shared(); ws_.async_read( *buffer, @@ -312,7 +312,7 @@ class ws_endpoint : public socket { << ec.message(); } - void async_shutdown_and_close_impl(as::basic_socket& s, move_only_function handler) { + void async_shutdown_and_close_impl(as::basic_socket& s, move_only_handler handler) { post( [this, &s, handler = force_move(handler)] () mutable { error_code ec; @@ -331,7 +331,7 @@ class ws_endpoint : public socket { << ec.message(); shutdown_and_close_impl(lowest_layer(), ec); } - void async_shutdown_and_close_impl(tls::stream& s, move_only_function handler) { + void async_shutdown_and_close_impl(tls::stream& s, move_only_handler handler) { s.async_shutdown( as::bind_executor( strand_, diff --git a/test/system/st_as_buffer_async_pubsub_1.cpp b/test/system/st_as_buffer_async_pubsub_1.cpp index 0a34a7ffc..f252c2ad3 100644 --- a/test/system/st_as_buffer_async_pubsub_1.cpp +++ b/test/system/st_as_buffer_async_pubsub_1.cpp @@ -56,25 +56,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -89,7 +85,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::any{} ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -97,7 +92,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -119,7 +113,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -137,25 +130,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -170,7 +159,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::any{} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -180,7 +168,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -203,7 +190,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; default: @@ -275,7 +261,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -289,19 +274,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -320,7 +302,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -328,7 +309,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -343,7 +323,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -361,7 +340,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -375,19 +353,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -406,7 +381,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -416,7 +390,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -432,7 +405,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -505,20 +477,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_unsub, &pid_pub] @@ -532,7 +501,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub] @@ -551,7 +519,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -559,7 +526,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -574,7 +540,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -592,20 +557,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_unsub, &pid_pub] @@ -619,7 +581,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub] @@ -638,7 +599,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -648,7 +608,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -664,7 +623,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -733,25 +691,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -766,7 +720,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::any{} ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -774,7 +727,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -796,7 +748,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -814,25 +765,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -847,7 +794,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::any{} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -857,7 +803,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -880,7 +825,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; default: @@ -967,26 +911,22 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1005,7 +945,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1013,7 +952,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1029,7 +967,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1047,26 +984,22 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1085,7 +1018,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1095,7 +1027,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1112,7 +1043,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1188,20 +1118,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -1215,7 +1142,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1234,7 +1160,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1242,7 +1167,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1258,7 +1182,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1276,20 +1199,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -1303,7 +1223,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1322,7 +1241,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1332,7 +1250,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1348,7 +1265,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: diff --git a/test/system/st_as_buffer_async_pubsub_2.cpp b/test/system/st_as_buffer_async_pubsub_2.cpp index f0134d84a..a574f4e73 100644 --- a/test/system/st_as_buffer_async_pubsub_2.cpp +++ b/test/system/st_as_buffer_async_pubsub_2.cpp @@ -57,25 +57,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -92,7 +88,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -100,7 +95,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -122,7 +116,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -140,25 +133,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -175,7 +164,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -185,7 +173,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -208,7 +195,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; default: @@ -289,7 +275,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -303,19 +288,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -334,7 +316,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -342,7 +323,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -358,7 +338,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -376,7 +355,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -390,19 +368,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -421,7 +396,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_NS::qos::at_least_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -431,7 +405,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -448,7 +421,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -526,20 +498,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -553,7 +522,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -572,7 +540,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -580,7 +547,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -596,7 +562,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -614,20 +579,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_NS::qos::exactly_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -641,7 +603,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -660,7 +621,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_NS::qos::exactly_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -670,7 +630,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -687,7 +646,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -751,25 +709,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -786,7 +740,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_NS::qos::at_most_once, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -794,7 +747,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -816,7 +768,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -834,25 +785,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_NS::qos::at_most_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -869,7 +816,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_NS::qos::at_most_once, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -879,7 +825,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -902,7 +847,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); break; default: @@ -965,25 +909,21 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { std::move(topic1), MQTT_NS::qos::at_most_once ); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -999,7 +939,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { std::move(contents), MQTT_NS::qos::at_most_once ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1007,7 +946,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -1028,7 +966,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { pid_unsub, std::move(topic1) ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1045,25 +982,21 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { std::move(topic1), MQTT_NS::qos::at_most_once ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1079,7 +1012,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { std::move(contents), MQTT_NS::qos::at_most_once ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1089,7 +1021,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -1111,7 +1042,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { pid_unsub, std::move(topic1) ); - return true; }); break; default: @@ -1176,7 +1106,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1190,19 +1119,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1221,7 +1147,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes, std::make_pair(topic1, contents) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1229,7 +1154,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1244,7 +1168,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1262,7 +1185,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_NS::qos::at_least_once, [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -1276,19 +1198,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { as::buffer(*topic1), [topic1](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1307,7 +1226,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes, std::make_pair(topic1, contents) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1317,7 +1235,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -1333,7 +1250,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: diff --git a/test/system/st_as_buffer_pubsub.cpp b/test/system/st_as_buffer_pubsub.cpp index 4bfc773e7..571aafe28 100644 --- a/test/system/st_as_buffer_pubsub.cpp +++ b/test/system/st_as_buffer_pubsub.cpp @@ -47,25 +47,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -75,7 +71,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -83,7 +78,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -99,7 +93,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -110,25 +103,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -138,7 +127,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -148,7 +136,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -165,7 +152,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -233,7 +219,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe(std::vector> { { "topic1", MQTT_NS::qos::at_most_once } }); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -242,19 +227,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe(std::vector{ "topic1" }); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -264,7 +246,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -272,7 +253,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -287,7 +267,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -299,7 +278,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe(std::vector> { { "topic1", MQTT_NS::qos::at_most_once } }); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -308,19 +286,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe(std::vector{ "topic1" }); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -330,7 +305,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -340,7 +314,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -356,7 +329,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -425,20 +397,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_unsub, &pid_pub] @@ -447,7 +416,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub] @@ -457,7 +425,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -465,7 +432,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -480,7 +446,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -491,20 +456,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_unsub, &pid_pub] @@ -513,7 +475,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub] @@ -523,7 +484,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -533,7 +493,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -549,7 +508,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -611,25 +569,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -639,7 +593,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -647,7 +600,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -663,7 +615,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -674,25 +625,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -702,7 +649,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -712,7 +658,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -729,7 +674,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -806,7 +750,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -815,19 +758,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -837,7 +777,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -845,7 +784,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -861,7 +799,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -872,7 +809,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -881,19 +817,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -903,7 +836,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -913,7 +845,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -930,7 +861,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1003,20 +933,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1025,7 +952,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1035,7 +961,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1043,7 +968,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1059,7 +983,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1070,20 +993,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1092,7 +1012,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1102,7 +1021,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1112,7 +1030,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1129,7 +1046,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1188,25 +1104,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1216,7 +1128,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1224,7 +1135,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -1240,7 +1150,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1251,25 +1160,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1279,7 +1184,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1289,7 +1193,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -1306,7 +1209,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -1383,7 +1285,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1392,19 +1293,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1414,7 +1312,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1422,7 +1319,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1438,7 +1334,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1449,7 +1344,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1458,19 +1352,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1480,7 +1371,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1490,7 +1380,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1507,7 +1396,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1580,20 +1468,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1602,7 +1487,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1612,7 +1496,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1620,7 +1503,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1636,7 +1518,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1647,20 +1528,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1669,7 +1547,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1679,7 +1556,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1689,7 +1565,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1706,7 +1581,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1765,25 +1639,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1793,7 +1663,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1801,7 +1670,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -1817,7 +1685,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1828,25 +1695,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1856,7 +1719,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1866,7 +1728,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -1883,7 +1744,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -1943,7 +1803,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1951,19 +1810,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == 1); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1974,7 +1830,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); BOOST_TEST(c->register_packet_id(1) == true); c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1982,7 +1837,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1997,7 +1851,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -2008,7 +1861,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -2016,19 +1868,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == 1); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -2039,7 +1888,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); BOOST_TEST(c->register_packet_id(1) == true); c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -2049,7 +1897,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -2065,7 +1912,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: diff --git a/test/system/st_as_buffer_sub.cpp b/test/system/st_as_buffer_sub.cpp index 5b42b2973..020a41db0 100644 --- a/test/system/st_as_buffer_sub.cpp +++ b/test/system/st_as_buffer_sub.cpp @@ -45,21 +45,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->unsubscribe("topic1"); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -70,21 +67,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe("topic1"); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -145,21 +139,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg ) { {"topic2", MQTT_NS::qos::exactly_once} } ); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->unsubscribe( std::vector{"topic1", "topic2"} ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -176,21 +167,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg ) { {"topic2", MQTT_NS::qos::exactly_once} } ); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe( std::vector{"topic1", "topic2"}); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -250,21 +238,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec ) { { "topic2", MQTT_NS::qos::exactly_once } }; c->subscribe(std::move(v)); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->unsubscribe(std::vector{"topic1", "topic2"}); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -280,21 +265,18 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec ) { { "topic2", MQTT_NS::qos::exactly_once } }; c->subscribe(std::move(v)); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe(std::vector{"topic1", "topic2"}); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -352,7 +334,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) { as::buffer(*topic), MQTT_NS::qos::at_most_once, [topic](MQTT_NS::error_code) {}); - return true; }); c->set_suback_handler( [&chk, &c] @@ -362,14 +343,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) { c->async_unsubscribe( as::buffer(*topic), [topic](MQTT_NS::error_code) {}); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -384,7 +363,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) { as::buffer(*topic), MQTT_NS::qos::at_most_once, [topic](MQTT_NS::error_code) {}); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -394,14 +372,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_single_async ) { c->async_unsubscribe( as::buffer(*topic), [topic](MQTT_NS::error_code) {}); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: @@ -465,7 +441,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) { }, [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c] @@ -477,14 +452,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) { std::vector{ as::buffer(*topic1), as::buffer(*topic2) }, [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -504,7 +477,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) { }, [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -516,14 +488,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_arg_async ) { std::vector{ as::buffer(*topic1), as::buffer(*topic2) }, [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: @@ -588,7 +558,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec_async ) { std::move(v), [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c] @@ -605,14 +574,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec_async ) { std::move(v), [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -633,7 +600,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec_async ) { std::move(v), [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -650,14 +616,12 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_string_multi_vec_async ) { std::move(v), [topic1, topic2](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: diff --git a/test/system/st_async_pubsub_1.cpp b/test/system/st_async_pubsub_1.cpp index 805aead97..94393fff7 100644 --- a/test/system/st_async_pubsub_1.cpp +++ b/test/system/st_async_pubsub_1.cpp @@ -51,7 +51,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -61,7 +60,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -69,7 +67,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -86,25 +83,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -116,7 +109,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -126,7 +118,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -136,7 +127,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -154,25 +144,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); break; default: @@ -244,7 +230,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { std::make_tuple("topic1", MQTT_NS::qos::at_most_once) } ); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -253,19 +238,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, std::vector{"topic1"}); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -276,7 +258,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -284,7 +265,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -299,7 +279,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -316,7 +295,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { std::make_tuple("topic1", MQTT_NS::qos::at_most_once) } ); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -325,19 +303,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, std::vector{"topic1"}); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -348,7 +323,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -358,7 +332,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -374,7 +347,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -442,20 +414,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_unsub, &pid_pub] @@ -464,7 +433,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub] @@ -475,7 +443,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -483,7 +450,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -498,7 +464,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -510,20 +475,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_unsub, &pid_pub] @@ -532,7 +494,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub] @@ -543,7 +504,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -553,7 +513,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -569,7 +528,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -634,25 +592,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -662,7 +616,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -670,7 +623,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -687,7 +639,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -699,25 +650,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -727,7 +674,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -737,7 +683,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -755,7 +700,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; default: @@ -833,26 +777,22 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -863,7 +803,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -871,7 +810,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -887,7 +825,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -899,26 +836,22 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -929,7 +862,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -939,7 +871,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -956,7 +887,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1028,20 +958,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -1050,7 +977,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1061,7 +987,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1069,7 +994,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1085,7 +1009,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1097,20 +1020,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -1119,7 +1039,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1130,7 +1049,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1140,7 +1058,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1157,7 +1074,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: diff --git a/test/system/st_async_pubsub_2.cpp b/test/system/st_async_pubsub_2.cpp index e5dd1279b..e3043e4d7 100644 --- a/test/system/st_async_pubsub_2.cpp +++ b/test/system/st_async_pubsub_2.cpp @@ -53,25 +53,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -81,7 +77,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -89,7 +84,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -106,7 +100,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -118,25 +111,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -146,7 +135,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -156,7 +144,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -174,7 +161,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; default: @@ -250,7 +236,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -259,19 +244,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -282,7 +264,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -290,7 +271,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -306,7 +286,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -318,7 +297,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -327,19 +305,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -350,7 +325,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -360,7 +334,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -377,7 +350,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -450,20 +422,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -472,7 +441,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -483,7 +451,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -491,7 +458,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -507,7 +473,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -519,20 +484,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -541,7 +503,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -552,7 +513,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -562,7 +522,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -579,7 +538,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -648,27 +606,23 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); auto pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &c] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); c->async_pubrel(packet_id); - return true; }); c->set_pubcomp_handler( [&chk, g] (packet_id_t) mutable { MQTT_CHK("h_pubcomp"); g.reset(); - return true; }); c->set_suback_handler( [&chk, &c] @@ -678,14 +632,12 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); auto pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c] @@ -703,7 +655,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { // send pubrec twice c->async_pubrec(*packet_id); c->async_pubrec(*packet_id); - return true; }); c->set_pubrel_handler( [&chk, &c, g] @@ -720,7 +671,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -732,27 +682,23 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); auto pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &c] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); c->async_pubrel(packet_id); - return true; }); c->set_v5_pubcomp_handler( [&chk, g] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) mutable { MQTT_CHK("h_pubcomp"); g.reset(); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -762,7 +708,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); auto pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -771,7 +716,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -790,7 +734,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { // send pubrec twice c->async_pubrec(*packet_id); c->async_pubrec(*packet_id); - return true; }); c->set_v5_pubrel_handler( [&chk, &c, g] @@ -807,7 +750,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -868,25 +810,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -896,7 +834,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -904,7 +841,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -921,7 +857,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -933,25 +868,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -961,7 +892,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -971,7 +901,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -989,7 +918,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); break; default: @@ -1050,7 +978,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1059,19 +986,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1082,7 +1006,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->register_packet_id(1); c->async_publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1090,7 +1013,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1105,7 +1027,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1117,7 +1038,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -1126,19 +1046,16 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1149,7 +1066,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); c->register_packet_id(1); c->async_publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1159,7 +1075,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -1175,7 +1090,6 @@ BOOST_AUTO_TEST_CASE( publish_dup_function ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1236,7 +1150,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1245,19 +1158,16 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1268,7 +1178,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->register_packet_id(1); c->async_publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1276,7 +1185,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1291,7 +1199,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1303,7 +1210,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -1312,19 +1218,16 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1335,7 +1238,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); c->register_packet_id(1); c->async_publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1345,7 +1247,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -1361,7 +1262,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1422,7 +1322,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1431,19 +1330,16 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1460,7 +1356,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { "contents"_mb, }; c->async_publish(1, "topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1468,7 +1363,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1483,7 +1377,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1495,7 +1388,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -1504,19 +1396,16 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1533,7 +1422,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { "contents"_mb, }; c->async_publish(1, "topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1543,7 +1431,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -1559,7 +1446,6 @@ BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1620,7 +1506,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pid_unsub] @@ -1629,19 +1514,16 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1669,7 +1551,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes, std::make_tuple(topic_name, s1, s2, s3, s4) ); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1677,7 +1558,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->async_disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -1692,7 +1572,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1704,7 +1583,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1"_mb, MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_unsub] @@ -1713,19 +1591,16 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_TEST(packet_id == 1); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1753,7 +1628,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes, std::make_tuple(topic_name, s1, s2, s3, s4) ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1763,7 +1637,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -1779,7 +1652,6 @@ BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { BOOST_CHECK(packet_id.value() == 1); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1855,7 +1727,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_prop ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, ps = std::move(ps)] @@ -1865,7 +1736,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, std::move(ps)); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1875,7 +1745,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub, &user_prop_count, prop_size] @@ -1939,25 +1808,21 @@ BOOST_AUTO_TEST_CASE( pub_sub_prop ) { pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_close_handler( [&chk, &finish] @@ -2074,26 +1939,22 @@ BOOST_AUTO_TEST_CASE( puback_props ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -2104,7 +1965,6 @@ BOOST_AUTO_TEST_CASE( puback_props ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -2114,7 +1974,6 @@ BOOST_AUTO_TEST_CASE( puback_props ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &recv_packet_id, pubackps = std::move(pubackps)] @@ -2133,7 +1992,6 @@ BOOST_AUTO_TEST_CASE( puback_props ) { BOOST_TEST(contents == "topic1_contents"); // pubackps doesn't contain *_ref property, so you don't need to care the lifetime of pubackprops c->async_puback(*packet_id, MQTT_NS::v5::puback_reason_code::success, std::move(pubackps)); - return true; }); c->set_close_handler( [&chk, &finish] @@ -2339,13 +2197,11 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->acquire_unique_packet_id(); c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &c, &pid_pub, pubrelps = std::move(pubrelps)] @@ -2353,7 +2209,6 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c->async_pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(pubrelps)); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -2362,7 +2217,6 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { BOOST_TEST(packet_id == pid_pub); pid_unsub = c->acquire_unique_packet_id(); c->async_unsubscribe(pid_unsub, "topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -2373,7 +2227,6 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->acquire_unique_packet_id(); c->async_publish(pid_pub, "topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -2383,7 +2236,6 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->async_disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &recv_packet_id, pubrecps = std::move(pubrecps)] @@ -2401,13 +2253,11 @@ BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); c->async_pubrec(*packet_id, MQTT_NS::v5::pubrec_reason_code::success, std::move(pubrecps)); - return true; }); c->set_v5_pubrel_handler( [&c, pubcompps = std::move(pubcompps)] (packet_id_t packet_id, MQTT_NS::v5::pubrel_reason_code, MQTT_NS::v5::properties /*props*/) { c->async_pubcomp(packet_id, MQTT_NS::v5::pubcomp_reason_code::success, std::move(pubcompps)); - return true; }); c->set_close_handler( [&chk, &finish] diff --git a/test/system/st_broker_offline_message.cpp b/test/system/st_broker_offline_message.cpp index 2ba674431..8bcb287c5 100644 --- a/test/system/st_broker_offline_message.cpp +++ b/test/system/st_broker_offline_message.cpp @@ -95,7 +95,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c2->connect(); - return true; } ); c2->set_connack_handler( @@ -115,7 +114,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { } ); BOOST_TEST(ret); - return true; } ); c2->set_suback_handler( @@ -125,7 +123,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c2->disconnect(); - return true; } ); c2->set_close_handler( @@ -151,14 +148,12 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { [&chk] (std::uint16_t) { MQTT_CHK("c1_h_puback"); - return true; } ); c1->set_pubrec_handler( [&chk] (std::uint16_t) { MQTT_CHK("c1_h_pubrec"); - return true; } ); c1->set_pubcomp_handler( @@ -166,7 +161,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { (std::uint16_t) { MQTT_CHK("c1_h_pubcomp"); c2->connect(); - return true; } ); c2->set_publish_handler( @@ -207,7 +201,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v3_1_1 ) { } ); BOOST_TEST(ret); - return true; } ); c1->set_close_handler( @@ -341,7 +334,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { ) } ); - return true; } ); c2->set_v5_connack_handler( @@ -361,7 +353,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { } ); BOOST_TEST(ret); - return true; } ); c2->set_v5_suback_handler( @@ -371,7 +362,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c2->disconnect(); - return true; } ); c2->set_close_handler( @@ -397,14 +387,12 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { [&chk] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("c1_h_puback"); - return true; } ); c1->set_v5_pubrec_handler( [&chk] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("c1_h_pubrec"); - return true; } ); c1->set_v5_pubcomp_handler( @@ -421,7 +409,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { } ); - return true; } ); c2->set_v5_publish_handler( @@ -511,7 +498,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5 ) { } ); BOOST_TEST(ret); - return true; } ); c1->set_close_handler( @@ -645,7 +631,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { ) } ); - return true; } ); c2->set_v5_connack_handler( @@ -676,7 +661,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { } ); BOOST_TEST(ret); - return true; } ); c2->set_v5_suback_handler( @@ -686,7 +670,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c2->disconnect(); - return true; } ); c2->set_close_handler( @@ -712,14 +695,12 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { [&chk] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("c1_h_puback"); - return true; } ); c1->set_v5_pubrec_handler( [&chk] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("c1_h_pubrec"); - return true; } ); c1->set_v5_pubcomp_handler( @@ -743,7 +724,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { } ); - return true; } ); c2->set_v5_publish_handler( @@ -755,7 +735,6 @@ BOOST_AUTO_TEST_CASE( offline_pubsub_v5_timeout ) { MQTT_NS::v5::properties) { // We should not received any published message when offline messages timeout BOOST_TEST(false); - return true; } ); c1->set_close_handler( diff --git a/test/system/st_connect.cpp b/test/system/st_connect.cpp index 9082a613f..f79686ea1 100644 --- a/test/system/st_connect.cpp +++ b/test/system/st_connect.cpp @@ -41,7 +41,6 @@ BOOST_AUTO_TEST_CASE( connect ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->disconnect(); BOOST_TEST(c->connected() == true); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -55,7 +54,6 @@ BOOST_AUTO_TEST_CASE( connect ) { c->disconnect(); BOOST_TEST(c->connected() == true); - return true; }); break; default: @@ -107,7 +105,6 @@ BOOST_AUTO_TEST_CASE( connect_no_strand ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -118,7 +115,6 @@ BOOST_AUTO_TEST_CASE( connect_no_strand ) { BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c->disconnect(); - return true; }); break; default: @@ -167,7 +163,6 @@ BOOST_AUTO_TEST_CASE( keep_alive ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -177,7 +172,6 @@ BOOST_AUTO_TEST_CASE( keep_alive ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - return true; }); break; default: @@ -201,7 +195,6 @@ BOOST_AUTO_TEST_CASE( keep_alive ) { () { MQTT_CHK("h_pingresp"); c->disconnect(); - return true; }); c->set_keep_alive_sec(3); c->connect(); @@ -252,7 +245,6 @@ BOOST_AUTO_TEST_CASE( keep_alive_and_send_control_packet ) { ); } ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -277,7 +269,6 @@ BOOST_AUTO_TEST_CASE( keep_alive_and_send_control_packet ) { ); } ); - return true; }); break; default: @@ -302,7 +293,6 @@ BOOST_AUTO_TEST_CASE( keep_alive_and_send_control_packet ) { MQTT_CHK("h_pingresp"); tim.cancel(); c->disconnect(); - return true; }); c->set_keep_alive_sec(3, std::chrono::seconds(3)); c->connect(); @@ -337,7 +327,6 @@ BOOST_AUTO_TEST_CASE( pingresp_timeout ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -347,7 +336,6 @@ BOOST_AUTO_TEST_CASE( pingresp_timeout ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - return true; }); break; default: @@ -408,7 +396,6 @@ BOOST_AUTO_TEST_CASE( connect_again ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -424,7 +411,6 @@ BOOST_AUTO_TEST_CASE( connect_again ) { BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c->disconnect(); - return true; }); break; default: @@ -479,7 +465,6 @@ BOOST_AUTO_TEST_CASE( nocid ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -500,7 +485,6 @@ BOOST_AUTO_TEST_CASE( nocid ) { ); BOOST_TEST(times == 1); c->disconnect(); - return true; }); break; default: @@ -546,7 +530,6 @@ BOOST_AUTO_TEST_CASE( nocid_noclean ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::identifier_rejected); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -571,7 +554,6 @@ BOOST_AUTO_TEST_CASE( nocid_noclean ) { ); BOOST_TEST(times == 1); c->force_disconnect(); - return true; }); break; default: @@ -648,7 +630,6 @@ BOOST_AUTO_TEST_CASE( noclean ) { } BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -679,7 +660,6 @@ BOOST_AUTO_TEST_CASE( noclean ) { } BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c->disconnect(); - return true; }); break; default: @@ -766,7 +746,6 @@ BOOST_AUTO_TEST_CASE( disconnect_timeout ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); b.set_disconnect_delay(std::chrono::seconds(2)); c->disconnect(std::chrono::seconds(1)); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -778,7 +757,6 @@ BOOST_AUTO_TEST_CASE( disconnect_timeout ) { BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); b.set_disconnect_delay(std::chrono::seconds(2)); c->disconnect(std::chrono::seconds(1)); - return true; }); break; default: @@ -828,7 +806,6 @@ BOOST_AUTO_TEST_CASE( disconnect_not_timeout ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); b.set_disconnect_delay(std::chrono::seconds(1)); c->disconnect(std::chrono::seconds(2)); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -840,7 +817,6 @@ BOOST_AUTO_TEST_CASE( disconnect_not_timeout ) { BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); b.set_disconnect_delay(std::chrono::seconds(1)); c->disconnect(std::chrono::seconds(2)); - return true; }); break; default: @@ -890,7 +866,6 @@ BOOST_AUTO_TEST_CASE( async_disconnect_timeout ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); b.set_disconnect_delay(std::chrono::seconds(2)); c->async_disconnect(std::chrono::seconds(1)); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -902,7 +877,6 @@ BOOST_AUTO_TEST_CASE( async_disconnect_timeout ) { BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); b.set_disconnect_delay(std::chrono::seconds(2)); c->async_disconnect(std::chrono::seconds(1)); - return true; }); break; default: @@ -963,7 +937,6 @@ BOOST_AUTO_TEST_CASE( async_disconnect_not_timeout ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); b.set_disconnect_delay(std::chrono::seconds(1)); c->async_disconnect(std::chrono::seconds(2)); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -975,7 +948,6 @@ BOOST_AUTO_TEST_CASE( async_disconnect_not_timeout ) { BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); b.set_disconnect_delay(std::chrono::seconds(1)); c->async_disconnect(std::chrono::seconds(2)); - return true; }); break; default: @@ -1046,7 +1018,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1056,7 +1027,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - return true; }); break; default: @@ -1080,7 +1050,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive ) { () { MQTT_CHK("h_pingresp"); c->async_disconnect(); - return true; }); c->set_keep_alive_sec(3); c->async_connect(); @@ -1131,7 +1100,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive_and_send_control_packet ) { ); } ); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1156,7 +1124,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive_and_send_control_packet ) { ); } ); - return true; }); break; default: @@ -1181,7 +1148,6 @@ BOOST_AUTO_TEST_CASE( async_keep_alive_and_send_control_packet ) { MQTT_CHK("h_pingresp"); tim.cancel(); c->async_disconnect(); - return true; }); c->set_keep_alive_sec(3, std::chrono::seconds(3)); c->async_connect(); @@ -1216,7 +1182,6 @@ BOOST_AUTO_TEST_CASE( async_pingresp_timeout ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1226,7 +1191,6 @@ BOOST_AUTO_TEST_CASE( async_pingresp_timeout ) { MQTT_CHK("h_connack"); BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - return true; }); break; default: @@ -1291,7 +1255,6 @@ BOOST_AUTO_TEST_CASE( async_connect_session_present_empty_store ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1313,7 +1276,6 @@ BOOST_AUTO_TEST_CASE( async_connect_session_present_empty_store ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -1376,7 +1338,6 @@ BOOST_AUTO_TEST_CASE( async_connect_retry_before_cb ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1387,7 +1348,6 @@ BOOST_AUTO_TEST_CASE( async_connect_retry_before_cb ) { BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c->async_disconnect(); - return true; }); break; default: @@ -1473,7 +1433,6 @@ BOOST_AUTO_TEST_CASE( async_connect_retry_broker_no_connack ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1485,7 +1444,6 @@ BOOST_AUTO_TEST_CASE( async_connect_retry_broker_no_connack ) { BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c->async_disconnect(); - return true; }); break; default: @@ -1650,7 +1608,6 @@ BOOST_AUTO_TEST_CASE( connect_prop ) { c->disconnect(MQTT_NS::v5::disconnect_reason_code::normal_disconnection, {}); BOOST_TEST(c->connected() == true); - return true; }); c->set_close_handler( @@ -1753,7 +1710,6 @@ BOOST_AUTO_TEST_CASE( disconnect_prop ) { c->disconnect(MQTT_NS::v5::disconnect_reason_code::normal_disconnection, std::move(discon_ps)); BOOST_TEST(c->connected() == true); - return true; }); c->set_close_handler( @@ -1912,7 +1868,6 @@ BOOST_AUTO_TEST_CASE( connack_prop ) { c->disconnect(); BOOST_TEST(c->connected() == true); - return true; }); c->set_close_handler( [&chk, &finish, &c] @@ -1979,7 +1934,6 @@ BOOST_AUTO_TEST_CASE( session_taken_over ) { ) } ); - return true; } ); c1->set_v5_disconnect_handler( @@ -2002,7 +1956,6 @@ BOOST_AUTO_TEST_CASE( session_taken_over ) { BOOST_TEST(sp == true); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c3->connect(); - return true; } ); c2->set_v5_disconnect_handler( @@ -2025,7 +1978,6 @@ BOOST_AUTO_TEST_CASE( session_taken_over ) { BOOST_TEST(sp == false); BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); c3->disconnect(); - return true; } ); c3->set_close_handler( diff --git a/test/system/st_issue_749.cpp b/test/system/st_issue_749.cpp index 9266d4f24..8c94fb11c 100644 --- a/test/system/st_issue_749.cpp +++ b/test/system/st_issue_749.cpp @@ -63,7 +63,6 @@ BOOST_AUTO_TEST_CASE( broker_assertion_fail ) { c1->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_most_once); } c1->disconnect(); - return true; } ); diff --git a/test/system/st_length_check.cpp b/test/system/st_length_check.cpp index 994855e46..3fc319451 100644 --- a/test/system/st_length_check.cpp +++ b/test/system/st_length_check.cpp @@ -46,7 +46,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [] @@ -66,7 +65,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_publish_handler( [] @@ -75,7 +73,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_NS::buffer /*topic*/, MQTT_NS::buffer /*contents*/) { BOOST_CHECK(false); - return false; }); c->set_is_valid_length_handler( [&chk] diff --git a/test/system/st_manual_publish.cpp b/test/system/st_manual_publish.cpp index acd59be2a..62b9c0f2b 100644 --- a/test/system/st_manual_publish.cpp +++ b/test/system/st_manual_publish.cpp @@ -48,7 +48,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->subscribe(1, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [&chk, &c] @@ -59,19 +58,16 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->unsubscribe(1, "topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c] @@ -84,7 +80,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c] @@ -92,7 +87,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == 1); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -107,7 +101,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); MQTT_CHK("h_publish"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -121,7 +114,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->subscribe(1, "topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [&chk, &c] @@ -132,19 +124,16 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->unsubscribe(1, "topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -157,7 +146,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(c->register_packet_id(1) == true); BOOST_TEST(c->register_packet_id(1) == false); c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -167,7 +155,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -183,7 +170,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); MQTT_CHK("h_publish"); - return true; }); break; default: diff --git a/test/system/st_maximum_packet_size.cpp b/test/system/st_maximum_packet_size.cpp index 47f3e61a7..a3277cd31 100644 --- a/test/system/st_maximum_packet_size.cpp +++ b/test/system/st_maximum_packet_size.cpp @@ -66,7 +66,6 @@ BOOST_AUTO_TEST_CASE( sync ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c, header_size] @@ -108,7 +107,6 @@ BOOST_AUTO_TEST_CASE( sync ) { catch (MQTT_NS::packet_size_error const&) { MQTT_CHK("publish101_exception"); } - return true; }); c->set_v5_publish_handler( [&chk, &c, header_size] @@ -130,7 +128,6 @@ BOOST_AUTO_TEST_CASE( sync ) { } ); BOOST_TEST(ret); - return true; }); c->set_close_handler( diff --git a/test/system/st_multi_sub.cpp b/test/system/st_multi_sub.cpp index 1783c6ee2..b9d6067af 100644 --- a/test/system/st_multi_sub.cpp +++ b/test/system/st_multi_sub.cpp @@ -61,7 +61,6 @@ BOOST_AUTO_TEST_CASE( multi_channel ) { } ); - return true; }); c->set_close_handler( [&chk, &finish] @@ -78,19 +77,16 @@ BOOST_AUTO_TEST_CASE( multi_channel ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -101,7 +97,6 @@ BOOST_AUTO_TEST_CASE( multi_channel ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); BOOST_TEST(results[1] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -109,7 +104,6 @@ BOOST_AUTO_TEST_CASE( multi_channel ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -142,7 +136,6 @@ BOOST_AUTO_TEST_CASE( multi_channel ) { } ); BOOST_TEST(ret); - return true; }); c->connect(); ioc.run(); @@ -221,7 +214,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub1 = c1->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c1->set_close_handler( [&chk, &server_close] @@ -238,19 +230,16 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c1->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c1->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c1->set_suback_handler( [&chk, &c1, &sub_count, &pid_sub1] @@ -261,7 +250,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); if (++sub_count == 2) c1->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c1->set_unsuback_handler( [&chk, &c1, &pid_unsub1] @@ -269,7 +257,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { MQTT_CHK("h_unsuback_1"); BOOST_TEST(packet_id == pid_unsub1); c1->disconnect(); - return true; }); c1->set_publish_handler( [&chk, &c1, &pid_unsub1] @@ -285,7 +272,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub1 = c1->unsubscribe("topic1"); - return true; }); auto c2 = MQTT_NS::make_client(ioc, broker_url, broker_notls_port); @@ -302,7 +288,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &server_close] @@ -319,19 +304,16 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c2->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c2->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c2->set_suback_handler( [&chk, &c2, &sub_count, &pid_sub2] @@ -342,7 +324,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); if (++sub_count == 2) c2->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -350,7 +331,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_publish_handler( [&chk, &c2, &pid_unsub2] @@ -366,7 +346,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub2 = c2->unsubscribe("topic1"); - return true; }); c1->connect(); @@ -463,7 +442,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub1 = c1->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c1->set_close_handler( [&chk, &server_close] @@ -488,7 +466,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { if (c1ready && c2ready && c3ready) { pid_pub3 = c3->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); } - return true; }); c1->set_unsuback_handler( [&chk, &c1, &pid_unsub1] @@ -496,7 +473,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { MQTT_CHK("h_unsuback_1"); BOOST_TEST(packet_id == pid_unsub1); c1->disconnect(); - return true; }); c1->set_publish_handler( [&chk, &c1, &pid_unsub1] @@ -512,7 +488,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub1 = c1->unsubscribe("topic1"); - return true; }); std::uint16_t pid_sub2; @@ -525,7 +500,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c2->set_close_handler( [&chk, &server_close] @@ -550,7 +524,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { if (c1ready && c2ready && c3ready) { pid_pub3 = c3->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); } - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -558,7 +531,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_publish_handler( [&chk, &c2, &pid_unsub2] @@ -574,7 +546,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub2 = c2->unsubscribe("topic1"); - return true; }); c3->set_connack_handler( @@ -587,7 +558,6 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { if (c1ready && c2ready && c3ready) { pid_pub3 = c3->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); } - return true; }); c3->set_close_handler( [&chk, &server_close] @@ -606,19 +576,16 @@ BOOST_AUTO_TEST_CASE( multi_client_qos1 ) { MQTT_CHK("h_puback_3"); BOOST_TEST(packet_id == pid_pub3); c3->disconnect(); - return true; }); c3->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c3->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c1->connect(); @@ -699,7 +666,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c2->connect(); - return true; } ); @@ -710,7 +676,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c1->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::nl::yes); - return true; } ); @@ -721,7 +686,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c2->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::nl::no); - return true; } ); @@ -732,7 +696,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c1->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_most_once); - return true; } ); @@ -751,7 +714,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents2"); c1->disconnect(); - return true; } ); @@ -786,7 +748,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { ); BOOST_TEST(ret); - return true; } ); @@ -813,7 +774,6 @@ BOOST_AUTO_TEST_CASE( multi_client_nl ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c1->connect(); diff --git a/test/system/st_offline.cpp b/test/system/st_offline.cpp index 35d75e54d..1374cd5f0 100644 --- a/test/system/st_offline.cpp +++ b/test/system/st_offline.cpp @@ -92,7 +92,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub] @@ -100,7 +99,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -121,7 +119,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub] @@ -129,7 +126,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -212,14 +208,12 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub] @@ -227,7 +221,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -248,14 +241,12 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code /*reason*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub] @@ -263,7 +254,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -348,7 +338,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub1, &pid_pub2] @@ -365,7 +354,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -386,7 +374,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub1, &pid_pub2] @@ -403,7 +390,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -487,7 +473,6 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub] @@ -495,7 +480,6 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -516,7 +500,6 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub] @@ -524,7 +507,6 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->async_disconnect(); - return true; }); break; default: diff --git a/test/system/st_pubsub_1.cpp b/test/system/st_pubsub_1.cpp index 859f40a26..fe952a34c 100644 --- a/test/system/st_pubsub_1.cpp +++ b/test/system/st_pubsub_1.cpp @@ -48,25 +48,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -76,7 +72,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -84,7 +79,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -100,7 +94,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -111,25 +104,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -139,7 +128,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -149,7 +137,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -166,7 +153,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -237,7 +223,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { std::make_tuple("topic1", MQTT_NS::qos::at_most_once) } ); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -247,19 +232,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { pub_seq_finished = true; pid_unsub = c->unsubscribe( std::vector {"topic1"}); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -269,7 +251,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -277,7 +258,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -292,7 +272,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -307,7 +286,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { std::make_tuple("topic1", MQTT_NS::qos::at_most_once) } ); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -317,19 +295,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { pub_seq_finished = true; pid_unsub = c->unsubscribe( std::vector {"topic1"}); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -339,7 +314,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -349,7 +323,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -365,7 +338,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -434,20 +406,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_unsub, &pid_pub] @@ -456,7 +425,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub] @@ -466,7 +434,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -474,7 +441,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -489,7 +455,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -500,20 +465,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_unsub, &pid_pub] @@ -522,7 +484,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_pub] @@ -532,7 +493,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -542,7 +502,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk] @@ -558,7 +517,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -621,25 +579,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -649,7 +603,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -657,7 +610,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -673,7 +625,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -684,25 +635,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -712,7 +659,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -722,7 +668,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -739,7 +684,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -815,7 +759,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -824,19 +767,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -846,7 +786,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -854,7 +793,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -870,7 +808,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -881,7 +818,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -890,19 +826,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -912,7 +845,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -922,7 +854,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -939,7 +870,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1011,20 +941,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1033,7 +960,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1043,7 +969,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1051,7 +976,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1067,7 +991,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1078,20 +1001,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1100,7 +1020,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1110,7 +1029,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1120,7 +1038,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1137,7 +1054,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1202,25 +1118,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1230,7 +1142,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1238,7 +1149,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -1254,7 +1164,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1265,25 +1174,21 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -1293,7 +1198,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1303,7 +1207,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -1320,7 +1223,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -1392,7 +1294,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1401,19 +1302,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1423,7 +1321,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1431,7 +1328,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1447,7 +1343,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1458,7 +1353,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1467,19 +1361,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1489,7 +1380,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1499,7 +1389,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1516,7 +1405,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1589,20 +1477,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1611,7 +1496,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1621,7 +1505,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1629,7 +1512,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1645,7 +1527,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1656,20 +1537,17 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub] @@ -1678,7 +1556,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(packet_id == pid_pub); pub_seq_finished = true; pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_pub] @@ -1688,7 +1565,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1698,7 +1574,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &recv_packet_id] @@ -1715,7 +1590,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); break; default: @@ -1782,27 +1656,23 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &c] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; }); c->set_pubcomp_handler( [&chk, g] (packet_id_t) mutable { MQTT_CHK("h_pubcomp"); g.reset(); - return true; }); c->set_suback_handler( [&chk, &c] @@ -1811,14 +1681,12 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c] @@ -1836,7 +1704,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { // send pubrec twice c->pubrec(*packet_id); c->pubrec(*packet_id); - return true; }); c->set_pubrel_handler( [&chk, &c, g] @@ -1853,7 +1720,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1864,27 +1730,23 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [&chk, &c] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; }); c->set_v5_pubcomp_handler( [&chk, g] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) mutable { MQTT_CHK("h_pubcomp"); g.reset(); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -1893,7 +1755,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -1902,7 +1763,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -1921,7 +1781,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { // send pubrec twice c->pubrec(*packet_id); c->pubrec(*packet_id); - return true; }); c->set_v5_pubrel_handler( [&chk, &c, g] @@ -1938,7 +1797,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2_protocol_error_resend_pubrec ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -1999,25 +1857,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -2027,7 +1881,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -2035,7 +1888,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -2051,7 +1903,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -2062,25 +1913,21 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -2090,7 +1937,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -2100,7 +1946,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -2117,7 +1962,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -2143,1548 +1987,4 @@ BOOST_AUTO_TEST_CASE( publish_function ) { do_combi_test_sync(test); } -BOOST_AUTO_TEST_CASE( publish_function_buffer ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS0 - cont("h_publish"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_puback_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubrec_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubcomp_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); - c->publish("topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - c->disconnect(); - return true; - }); - c->set_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - c->publish("topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS0 - cont("h_publish"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_puback_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubrec_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubcomp_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); - std::vector bs { - "topic"_mb, - "1"_mb, - "_"_mb, - "contents"_mb, - }; - c->publish("topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_most_once); - return true; - }); - c->set_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - c->disconnect(); - return true; - }); - c->set_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - std::vector bs { - "topic"_mb, - "1"_mb, - "_"_mb, - "contents"_mb, - }; - c->publish("topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS0 - cont("h_publish"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_puback_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubrec_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubcomp_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); - auto topic_name = std::make_shared("topic1"); - auto s1 = std::make_shared("topic"); - auto s2 = std::make_shared("1"); - auto s3 = std::make_shared("_"); - auto s4 = std::make_shared("contents"); - std::vector cbs { - as::buffer(*s1), - as::buffer(*s2), - as::buffer(*s3), - as::buffer(*s4) - }; - c->publish( - as::buffer(*topic_name), - cbs, - MQTT_NS::qos::at_most_once, - std::make_tuple(topic_name, s1, s2, s3, s4) - ); - return true; - }); - c->set_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - c->disconnect(); - return true; - }); - c->set_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - auto topic_name = std::make_shared("topic1"); - auto s1 = std::make_shared("topic"); - auto s2 = std::make_shared("1"); - auto s3 = std::make_shared("_"); - auto s4 = std::make_shared("contents"); - std::vector cbs { - as::buffer(*s1), - as::buffer(*s2), - as::buffer(*s3), - as::buffer(*s4) - }; - c->publish( - as::buffer(*topic_name), - cbs, - MQTT_NS::qos::at_most_once, - std::make_tuple(topic_name, s1, s2, s3, s4) - ); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &c, &pid_unsub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_dup_function ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS1 - cont("h_suback"), - // publish topic1 QoS1 - cont("h_publish"), - cont("h_puback"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; - }); - c->set_puback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == 1); - pid_unsub = c->unsubscribe("topic1"); - return true; - }); - c->set_pubrec_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubcomp_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); - BOOST_TEST(c->register_packet_id(1) == true); - c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; - }); - c->set_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - c->disconnect(); - return true; - }); - c->set_publish_handler( - [&chk] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id.value() == 1); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - return true; - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; - }); - c->set_v5_puback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == 1); - pid_unsub = c->unsubscribe("topic1"); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); - BOOST_TEST(c->register_packet_id(1) == true); - c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id.value() == 1); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - return true; - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_dup_function_buffer ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS1 - cont("h_suback"), - // publish topic1 QoS1 - cont("h_publish"), - cont("h_puback"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_least_once); - return true; - }); - c->set_puback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == 1); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - c->set_pubrec_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_pubcomp_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - return true; - }); - c->set_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); - BOOST_TEST(c->register_packet_id(1) == true); - c->publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; - }); - c->set_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - c->disconnect(); - return true; - }); - c->set_publish_handler( - [&chk] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id.value() == 1); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - return true; - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_least_once); - return true; - }); - c->set_v5_puback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == 1); - pid_unsub = c->unsubscribe("topic1"_mb); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); - BOOST_TEST(c->register_packet_id(1) == true); - c->publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id.value() == 1); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - return true; - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( pub_sub_prop ) { - using namespace std::literals::string_literals; - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_sub; - packet_id_t pid_unsub; - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS0 - cont("h_publish"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - MQTT_NS::v5::properties ps { - MQTT_NS::v5::property::payload_format_indicator(MQTT_NS::v5::property::payload_format_indicator::string), - MQTT_NS::v5::property::message_expiry_interval(0x12345678UL), - MQTT_NS::v5::property::content_type("content type"_mb), - MQTT_NS::v5::property::topic_alias(0x1234U), - MQTT_NS::v5::property::response_topic("response topic"_mb), - MQTT_NS::v5::property::correlation_data("correlation \0data"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - - auto prop_size = ps.size(); - std::size_t user_prop_count = 0; - - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub, ps = MQTT_NS::force_move(ps)] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) mutable { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::force_move(ps)); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &c, &pid_unsub, &user_prop_count, prop_size] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties props) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(!packet_id); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - - // -1 means TopicAlias - // TopicAlias is not forwarded - // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113 - // A receiver MUST NOT carry forward any Topic Alias mappings from - // one Network Connection to another [MQTT-3.3.2-7]. - BOOST_TEST(props.size() == prop_size - 1); - - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::payload_format_indicator const& t) { - BOOST_TEST(t.val() == MQTT_NS::v5::property::payload_format_indicator::string); - }, - [&](MQTT_NS::v5::property::content_type const& t) { - BOOST_TEST(t.val() == "content type"); - }, - [&](MQTT_NS::v5::property::message_expiry_interval const& t) { - BOOST_TEST(t.val() == 0x12345678UL); - }, - [&](MQTT_NS::v5::property::response_topic const& t) { - BOOST_TEST(t.val() == "response topic"); - }, - [&](MQTT_NS::v5::property::correlation_data const& t) { - BOOST_TEST(t.val() == std::string("correlation \0data"s)); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - - pid_unsub = c->unsubscribe("topic1"); - return true; - }); - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->set_pub_res_sent_handler( - [] - (packet_id_t) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( puback_prop ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - packet_id_t pid_sub; - packet_id_t pid_unsub; - - bool pub_seq_finished = false; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS1 - cont("h_publish"), - cont("h_pub_res_sent"), - cont("h_puback"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - MQTT_NS::v5::properties pubackps { - MQTT_NS::v5::property::reason_string("test success"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - auto puback_prop_size = pubackps.size(); - b.set_puback_props(MQTT_NS::force_move(pubackps)); - std::size_t puback_user_prop_count = 0; - - MQTT_NS::optional recv_packet_id; - c->set_pub_res_sent_handler( - [&chk, &recv_packet_id] - (packet_id_t packet_id) { - MQTT_CHK("h_pub_res_sent"); - BOOST_TEST(*recv_packet_id == packet_id); - }); - - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; - }); - c->set_v5_puback_handler( - [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub, puback_prop_size, &puback_user_prop_count] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties props) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == pid_pub); - pub_seq_finished = true; - - BOOST_TEST(props.size() == puback_prop_size); - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::reason_string const& t) { - BOOST_TEST(t.val() == "test success"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (puback_user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - - pid_unsub = c->unsubscribe("topic1"); - return true; - }); - c->set_v5_pubrec_handler( - [] - (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubcomp_handler( - [] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub, &pid_pub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &recv_packet_id] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_TEST(*packet_id != 0); - recv_packet_id = packet_id; - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - return true; - }); - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - packet_id_t pid_sub; - packet_id_t pid_unsub; - - bool pub_seq_finished = false; - - - checker chk = { - // connect - cont("h_connack"), - // subscribe topic1 QoS0 - cont("h_suback"), - // publish topic1 QoS2 - cont("h_publish"), - cont("h_pubrec"), - cont("h_pub_res_sent"), - cont("h_pubcomp"), - cont("h_unsuback"), - // disconnect - cont("h_close"), - }; - - MQTT_NS::v5::properties pubrecps { - MQTT_NS::v5::property::reason_string("test success"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - auto pubrec_prop_size = pubrecps.size(); - b.set_pubrec_props(MQTT_NS::force_move(pubrecps)); - std::size_t pubrec_user_prop_count = 0; - - MQTT_NS::v5::properties pubrelps { - MQTT_NS::v5::property::reason_string("test success"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - std::size_t pubrel_user_prop_count = 0; - - MQTT_NS::v5::properties pubcompps { - MQTT_NS::v5::property::reason_string("test success"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - auto pubcomp_prop_size = pubcompps.size(); - b.set_pubcomp_props(MQTT_NS::force_move(pubcompps)); - std::size_t pubcomp_user_prop_count = 0; - - b.set_pubrel_props_handler( - [&pubrel_user_prop_count, size = pubrelps.size()] (MQTT_NS::v5::properties const& props) { - BOOST_TEST(props.size() == size); - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::reason_string const& t) { - BOOST_TEST(t.val() == "test success"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (pubrel_user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - } - ); - - MQTT_NS::optional recv_packet_id; - c->set_pub_res_sent_handler( - [&chk, &recv_packet_id] - (packet_id_t packet_id) { - MQTT_CHK("h_pub_res_sent"); - BOOST_TEST(*recv_packet_id == packet_id); - }); - - c->set_v5_connack_handler( - [&chk, &c, &pid_sub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_CHECK(false); - return true; - }); - c->set_v5_pubrec_handler( - [&chk, &c, &pid_pub, pubrec_prop_size, &pubrec_user_prop_count, pubrelps = MQTT_NS::force_move(pubrelps)] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties props) mutable { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - - BOOST_TEST(props.size() == pubrec_prop_size); - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::reason_string const& t) { - BOOST_TEST(t.val() == "test success"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (pubrec_user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - - c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, MQTT_NS::force_move(pubrelps)); - - return true; - }); - c->set_v5_pubcomp_handler( - [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub, pubcomp_prop_size, &pubcomp_user_prop_count] - (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties props) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == pid_pub); - - BOOST_TEST(props.size() == pubcomp_prop_size); - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::reason_string const& t) { - BOOST_TEST(t.val() == "test success"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (pubcomp_user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - - pub_seq_finished = true; - pid_unsub = c->unsubscribe("topic1"); - return true; - }); - c->set_v5_suback_handler( - [&chk, &c, &pid_sub, &pid_pub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(packet_id == pid_sub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; - }); - c->set_v5_unsuback_handler( - [&chk, &c, &pid_unsub] - (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_unsuback"); - BOOST_TEST(packet_id == pid_unsub); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); - c->disconnect(); - return true; - }); - c->set_v5_publish_handler( - [&chk, &c, &recv_packet_id] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_TEST(*packet_id != 0); - recv_packet_id = packet_id; - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - c->pubrec(*packet_id, MQTT_NS::v5::pubrec_reason_code::success, {}); - return true; - }); - c->set_v5_pubrel_handler( - [&c] - (packet_id_t packet_id, MQTT_NS::v5::pubrel_reason_code, MQTT_NS::v5::properties /*props*/) { - c->pubcomp(packet_id, MQTT_NS::v5::pubcomp_reason_code::success, {}); - return true; - }); - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/system/st_pubsub_2.cpp b/test/system/st_pubsub_2.cpp index e81f68518..c0c595dc8 100644 --- a/test/system/st_pubsub_2.cpp +++ b/test/system/st_pubsub_2.cpp @@ -16,6 +16,1458 @@ BOOST_AUTO_TEST_SUITE(st_pubsub_2) using namespace MQTT_NS::literals; +BOOST_AUTO_TEST_CASE( publish_function_buffer ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS0 + cont("h_publish"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_puback_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubrec_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); + c->publish("topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + c->disconnect(); + }); + c->set_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_v5_puback_handler( + [] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); + c->publish("topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_function_buffer_sequence ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS0 + cont("h_publish"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_puback_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubrec_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); + std::vector bs { + "topic"_mb, + "1"_mb, + "_"_mb, + "contents"_mb, + }; + c->publish("topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_most_once); + }); + c->set_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + c->disconnect(); + }); + c->set_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_v5_puback_handler( + [] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); + std::vector bs { + "topic"_mb, + "1"_mb, + "_"_mb, + "contents"_mb, + }; + c->publish("topic1"_mb, MQTT_NS::force_move(bs), MQTT_NS::qos::at_most_once); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_function_const_buffer_sequence ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS0 + cont("h_publish"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_puback_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubrec_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); + auto topic_name = std::make_shared("topic1"); + auto s1 = std::make_shared("topic"); + auto s2 = std::make_shared("1"); + auto s3 = std::make_shared("_"); + auto s4 = std::make_shared("contents"); + std::vector cbs { + as::buffer(*s1), + as::buffer(*s2), + as::buffer(*s3), + as::buffer(*s4) + }; + c->publish( + as::buffer(*topic_name), + cbs, + MQTT_NS::qos::at_most_once, + std::make_tuple(topic_name, s1, s2, s3, s4) + ); + }); + c->set_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + c->disconnect(); + }); + c->set_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_most_once); + }); + c->set_v5_puback_handler( + [] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); + auto topic_name = std::make_shared("topic1"); + auto s1 = std::make_shared("topic"); + auto s2 = std::make_shared("1"); + auto s3 = std::make_shared("_"); + auto s4 = std::make_shared("contents"); + std::vector cbs { + as::buffer(*s1), + as::buffer(*s2), + as::buffer(*s3), + as::buffer(*s4) + }; + c->publish( + as::buffer(*topic_name), + cbs, + MQTT_NS::qos::at_most_once, + std::make_tuple(topic_name, s1, s2, s3, s4) + ); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &c, &pid_unsub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_dup_function ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS1 + cont("h_suback"), + // publish topic1 QoS1 + cont("h_publish"), + cont("h_puback"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); + }); + c->set_puback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == 1); + pid_unsub = c->unsubscribe("topic1"); + }); + c->set_pubrec_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); + BOOST_TEST(c->register_packet_id(1) == true); + c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); + }); + c->set_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + c->disconnect(); + }); + c->set_publish_handler( + [&chk] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id.value() == 1); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); + }); + c->set_v5_puback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == 1); + pid_unsub = c->unsubscribe("topic1"); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); + BOOST_TEST(c->register_packet_id(1) == true); + c->publish(1, "topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id.value() == 1); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_dup_function_buffer ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS1 + cont("h_suback"), + // publish topic1 QoS1 + cont("h_publish"), + cont("h_puback"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_least_once); + }); + c->set_puback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == 1); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + c->set_pubrec_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); + BOOST_TEST(c->register_packet_id(1) == true); + c->publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); + }); + c->set_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + c->disconnect(); + }); + c->set_publish_handler( + [&chk] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id.value() == 1); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1"_mb, MQTT_NS::qos::at_least_once); + }); + c->set_v5_puback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == 1); + pid_unsub = c->unsubscribe("topic1"_mb); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); + BOOST_TEST(c->register_packet_id(1) == true); + c->publish(1, "topic1"_mb, "topic1_contents"_mb, MQTT_NS::qos::at_least_once | MQTT_NS::dup::yes); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id.value() == 1); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( pub_sub_prop ) { + using namespace std::literals::string_literals; + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { + finish(); + return; + } + + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_sub; + packet_id_t pid_unsub; + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS0 + cont("h_publish"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + MQTT_NS::v5::properties ps { + MQTT_NS::v5::property::payload_format_indicator(MQTT_NS::v5::property::payload_format_indicator::string), + MQTT_NS::v5::property::message_expiry_interval(0x12345678UL), + MQTT_NS::v5::property::content_type("content type"_mb), + MQTT_NS::v5::property::topic_alias(0x1234U), + MQTT_NS::v5::property::response_topic("response topic"_mb), + MQTT_NS::v5::property::correlation_data("correlation \0data"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + + auto prop_size = ps.size(); + std::size_t user_prop_count = 0; + + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); + }); + c->set_v5_puback_handler( + [] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub, ps = MQTT_NS::force_move(ps)] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) mutable { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); + c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::no, MQTT_NS::force_move(ps)); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &c, &pid_unsub, &user_prop_count, prop_size] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties props) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_most_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(!packet_id); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + + // -1 means TopicAlias + // TopicAlias is not forwarded + // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113 + // A receiver MUST NOT carry forward any Topic Alias mappings from + // one Network Connection to another [MQTT-3.3.2-7]. + BOOST_TEST(props.size() == prop_size - 1); + + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::payload_format_indicator const& t) { + BOOST_TEST(t.val() == MQTT_NS::v5::property::payload_format_indicator::string); + }, + [&](MQTT_NS::v5::property::content_type const& t) { + BOOST_TEST(t.val() == "content type"); + }, + [&](MQTT_NS::v5::property::message_expiry_interval const& t) { + BOOST_TEST(t.val() == 0x12345678UL); + }, + [&](MQTT_NS::v5::property::response_topic const& t) { + BOOST_TEST(t.val() == "response topic"); + }, + [&](MQTT_NS::v5::property::correlation_data const& t) { + BOOST_TEST(t.val() == std::string("correlation \0data"s)); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + + pid_unsub = c->unsubscribe("topic1"); + }); + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->set_pub_res_sent_handler( + [] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( puback_prop ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { + finish(); + return; + } + + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + packet_id_t pid_sub; + packet_id_t pid_unsub; + + bool pub_seq_finished = false; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS1 + cont("h_publish"), + cont("h_pub_res_sent"), + cont("h_puback"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + MQTT_NS::v5::properties pubackps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + auto puback_prop_size = pubackps.size(); + b.set_puback_props(MQTT_NS::force_move(pubackps)); + std::size_t puback_user_prop_count = 0; + + MQTT_NS::optional recv_packet_id; + c->set_pub_res_sent_handler( + [&chk, &recv_packet_id] + (packet_id_t packet_id) { + MQTT_CHK("h_pub_res_sent"); + BOOST_TEST(*recv_packet_id == packet_id); + }); + + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); + }); + c->set_v5_puback_handler( + [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub, puback_prop_size, &puback_user_prop_count] + (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties props) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == pid_pub); + pub_seq_finished = true; + + BOOST_TEST(props.size() == puback_prop_size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (puback_user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + + pid_unsub = c->unsubscribe("topic1"); + }); + c->set_v5_pubrec_handler( + [] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub, &pid_pub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_1); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &recv_packet_id] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_TEST(*packet_id != 0); + recv_packet_id = packet_id; + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + }); + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( pubrec_rel_comp_prop ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { + finish(); + return; + } + + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + c->set_auto_pub_response(false); + + packet_id_t pid_pub; + packet_id_t pid_sub; + packet_id_t pid_unsub; + + bool pub_seq_finished = false; + + + checker chk = { + // connect + cont("h_connack"), + // subscribe topic1 QoS0 + cont("h_suback"), + // publish topic1 QoS2 + cont("h_publish"), + cont("h_pubrec"), + cont("h_pub_res_sent"), + cont("h_pubcomp"), + cont("h_unsuback"), + // disconnect + cont("h_close"), + }; + + MQTT_NS::v5::properties pubrecps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + auto pubrec_prop_size = pubrecps.size(); + b.set_pubrec_props(MQTT_NS::force_move(pubrecps)); + std::size_t pubrec_user_prop_count = 0; + + MQTT_NS::v5::properties pubrelps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + std::size_t pubrel_user_prop_count = 0; + + MQTT_NS::v5::properties pubcompps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + auto pubcomp_prop_size = pubcompps.size(); + b.set_pubcomp_props(MQTT_NS::force_move(pubcompps)); + std::size_t pubcomp_user_prop_count = 0; + + b.set_pubrel_props_handler( + [&pubrel_user_prop_count, size = pubrelps.size()] (MQTT_NS::v5::properties const& props) { + BOOST_TEST(props.size() == size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (pubrel_user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + } + ); + + MQTT_NS::optional recv_packet_id; + c->set_pub_res_sent_handler( + [&chk, &recv_packet_id] + (packet_id_t packet_id) { + MQTT_CHK("h_pub_res_sent"); + BOOST_TEST(*recv_packet_id == packet_id); + }); + + c->set_v5_connack_handler( + [&chk, &c, &pid_sub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); + }); + c->set_v5_puback_handler( + [] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [&chk, &c, &pid_pub, pubrec_prop_size, &pubrec_user_prop_count, pubrelps = MQTT_NS::force_move(pubrelps)] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties props) mutable { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + + BOOST_TEST(props.size() == pubrec_prop_size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (pubrec_user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + + c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, MQTT_NS::force_move(pubrelps)); + + }); + c->set_v5_pubcomp_handler( + [&chk, &c, &pub_seq_finished, &pid_pub, &pid_unsub, pubcomp_prop_size, &pubcomp_user_prop_count] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties props) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + + BOOST_TEST(props.size() == pubcomp_prop_size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (pubcomp_user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + + pub_seq_finished = true; + pid_unsub = c->unsubscribe("topic1"); + }); + c->set_v5_suback_handler( + [&chk, &c, &pid_sub, &pid_pub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(packet_id == pid_sub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + }); + c->set_v5_unsuback_handler( + [&chk, &c, &pid_unsub] + (packet_id_t packet_id, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(packet_id == pid_unsub); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); + c->disconnect(); + }); + c->set_v5_publish_handler( + [&chk, &c, &recv_packet_id] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_publish"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_TEST(*packet_id != 0); + recv_packet_id = packet_id; + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + c->pubrec(*packet_id, MQTT_NS::v5::pubrec_reason_code::success, {}); + }); + c->set_v5_pubrel_handler( + [&c] + (packet_id_t packet_id, MQTT_NS::v5::pubrel_reason_code, MQTT_NS::v5::properties /*props*/) { + c->pubcomp(packet_id, MQTT_NS::v5::pubcomp_reason_code::success, {}); + }); + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { auto& c = cs[0]; @@ -48,25 +1500,21 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("a/+/b", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -76,7 +1524,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("a/topic1/b", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -84,7 +1531,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -100,7 +1546,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(topic == "a/topic1/b"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("a/+/b"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -111,25 +1556,21 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("a/+/b", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -139,7 +1580,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("a/topic1/b", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -149,7 +1589,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -166,7 +1605,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_plus ) { BOOST_TEST(topic == "a/topic1/b"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("a/+/b"); - return true; }); break; default: @@ -229,25 +1667,21 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("a/#", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (packet_id_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -257,7 +1691,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("a/topic1/b", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -265,7 +1698,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -281,7 +1713,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(topic == "a/topic1/b"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("a/#"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -292,25 +1723,21 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("a/#", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -320,7 +1747,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("a/topic1/b", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -330,7 +1756,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -347,7 +1772,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_wc_sharp ) { BOOST_TEST(topic == "a/topic1/b"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("a/#"); - return true; }); break; default: @@ -412,7 +1836,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid ) { "topic1", MQTT_NS::qos::at_most_once, MQTT_NS::v5::properties{ MQTT_NS::v5::property::subscription_identifier(123) } ); - return true; }); c->set_v5_suback_handler( [&] @@ -421,7 +1844,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_publish_handler( [&] @@ -447,7 +1869,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid ) { ); } c->disconnect(); - return true; }); c->set_close_handler( [&] @@ -507,7 +1928,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_ow ) { "topic1", MQTT_NS::qos::at_most_once, MQTT_NS::v5::properties{ MQTT_NS::v5::property::subscription_identifier(456) } ); - return true; }); c->set_v5_suback_handler( [&] @@ -526,7 +1946,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_ow ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&] @@ -552,7 +1971,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_ow ) { ); } c->disconnect(); - return true; }); c->set_close_handler( [&] @@ -613,7 +2031,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_multi_match ) { "a/#", MQTT_NS::qos::at_most_once, MQTT_NS::v5::properties{ MQTT_NS::v5::property::subscription_identifier(456) } ); - return true; }); c->set_v5_suback_handler( [&] @@ -632,7 +2049,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_multi_match ) { } ); BOOST_TEST(ret); - return true; }); std::set sids { 123, 456 }; @@ -684,7 +2100,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_sid_multi_match ) { } ); BOOST_TEST(ret); - return true; }); c->set_close_handler( [&] diff --git a/test/system/st_pubsub_no_strand.cpp b/test/system/st_pubsub_no_strand.cpp index 500f68f42..73211f42b 100644 --- a/test/system/st_pubsub_no_strand.cpp +++ b/test/system/st_pubsub_no_strand.cpp @@ -71,7 +71,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -88,19 +87,16 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -110,7 +106,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -118,7 +113,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -134,7 +128,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); @@ -197,7 +190,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -216,19 +208,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub, &pid_sub] @@ -238,7 +227,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -246,7 +234,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -261,7 +248,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos0 ) { BOOST_TEST(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -324,7 +310,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -341,14 +326,12 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_unsub, &pid_pub] @@ -356,7 +339,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_suback_handler( [&chk, &c, &pid_pub] @@ -366,7 +348,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -374,7 +355,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk] @@ -389,7 +369,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos0 ) { BOOST_CHECK(!packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -449,7 +428,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -466,19 +444,16 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -488,7 +463,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -496,7 +470,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -512,7 +485,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); @@ -575,7 +547,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -594,19 +565,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); MQTT_NS::optional recv_packet_id; c->set_pub_res_sent_handler( @@ -623,7 +591,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -631,7 +598,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -647,7 +613,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -711,7 +676,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -728,14 +692,12 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -743,7 +705,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); MQTT_NS::optional recv_packet_id; c->set_pub_res_sent_handler( @@ -760,7 +721,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -768,7 +728,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -784,7 +743,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos1 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -845,7 +803,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -862,19 +819,16 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -884,7 +838,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -892,7 +845,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -908,7 +860,6 @@ BOOST_AUTO_TEST_CASE( pub_qos0_sub_qos2 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); @@ -972,7 +923,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -991,19 +941,16 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); MQTT_NS::optional recv_packet_id; c->set_pub_res_sent_handler( @@ -1020,7 +967,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1028,7 +974,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1044,7 +989,6 @@ BOOST_AUTO_TEST_CASE( pub_qos1_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -1109,7 +1053,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -1126,14 +1069,12 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub, &pid_unsub] @@ -1141,7 +1082,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); pid_unsub = c->unsubscribe("topic1"); - return true; }); MQTT_NS::optional recv_packet_id; c->set_pub_res_sent_handler( @@ -1158,7 +1098,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1166,7 +1105,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &recv_packet_id] @@ -1182,7 +1120,6 @@ BOOST_AUTO_TEST_CASE( pub_qos2_sub_qos2 ) { recv_packet_id = packet_id; BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); - return true; }); c->connect(); ioc.run(); @@ -1243,7 +1180,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -1260,19 +1196,16 @@ BOOST_AUTO_TEST_CASE( publish_function ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -1282,7 +1215,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1290,7 +1222,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -1306,7 +1237,6 @@ BOOST_AUTO_TEST_CASE( publish_function ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); diff --git a/test/system/st_receive_maximum.cpp b/test/system/st_receive_maximum.cpp index ae853c6e0..6b90ed369 100644 --- a/test/system/st_receive_maximum.cpp +++ b/test/system/st_receive_maximum.cpp @@ -60,7 +60,6 @@ BOOST_AUTO_TEST_CASE( sync ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -86,7 +85,6 @@ BOOST_AUTO_TEST_CASE( sync ) { "message3", MQTT_NS::qos::at_least_once ); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -126,12 +124,10 @@ BOOST_AUTO_TEST_CASE( sync ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - return true; }); c->set_close_handler( @@ -189,7 +185,6 @@ BOOST_AUTO_TEST_CASE( sync_manual_pubrel ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->pubrel(1); - return true; }); c->set_v5_pubcomp_handler( [&] @@ -197,7 +192,6 @@ BOOST_AUTO_TEST_CASE( sync_manual_pubrel ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c->disconnect(); - return true; } ); c->set_close_handler( @@ -255,7 +249,6 @@ BOOST_AUTO_TEST_CASE( async_manual_pubrel ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->async_pubrel(1); - return true; }); c->set_v5_pubcomp_handler( [&] @@ -263,7 +256,6 @@ BOOST_AUTO_TEST_CASE( async_manual_pubrel ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c->async_disconnect(); - return true; } ); c->set_close_handler( diff --git a/test/system/st_remaining_length.cpp b/test/system/st_remaining_length.cpp index f5fb7f949..27a7899c1 100644 --- a/test/system/st_remaining_length.cpp +++ b/test/system/st_remaining_length.cpp @@ -55,7 +55,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_127 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -72,19 +71,16 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_127 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &test_contents] @@ -94,7 +90,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_127 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", test_contents, MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -102,7 +97,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_127 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub, &test_contents] @@ -118,7 +112,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_127 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == test_contents); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); @@ -168,7 +161,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_16384 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -185,19 +177,16 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_16384 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &test_contents] @@ -207,7 +196,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_16384 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", test_contents, MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -215,7 +203,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_16384 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub, &test_contents] @@ -231,7 +218,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_16384 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == test_contents); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); @@ -283,7 +269,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_2097152 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_close_handler( [&chk, &finish] @@ -300,19 +285,16 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_2097152 ) { [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub, &test_contents] @@ -322,7 +304,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_2097152 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->publish("topic1", test_contents, MQTT_NS::qos::at_most_once); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -330,7 +311,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_2097152 ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub, &test_contents] @@ -346,7 +326,6 @@ BOOST_AUTO_TEST_CASE( pub_sub_over_2097152 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == test_contents); pid_unsub = c->unsubscribe("topic1"); - return true; }); c->connect(); ioc.run(); diff --git a/test/system/st_reqres.cpp b/test/system/st_reqres.cpp index 213b31c70..cbc2806fd 100644 --- a/test/system/st_reqres.cpp +++ b/test/system/st_reqres.cpp @@ -59,7 +59,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { BOOST_TEST(times == 1); c->subscribe(response_topic, MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&] @@ -71,7 +70,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c->publish(response_topic, "response_contents", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_publish_handler( [&] @@ -84,7 +82,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { BOOST_TEST(topic == response_topic); BOOST_TEST(contents == "response_contents"); c->disconnect(); - return true; }); c->set_close_handler( [&] @@ -197,7 +194,6 @@ BOOST_AUTO_TEST_CASE( session ) { ); BOOST_TEST(ret); c->disconnect(); - return true; }); c->set_close_handler( [&] @@ -353,7 +349,6 @@ BOOST_AUTO_TEST_CASE( retain ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_suback_handler( [&] @@ -375,7 +370,6 @@ BOOST_AUTO_TEST_CASE( retain ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&] @@ -389,7 +383,6 @@ BOOST_AUTO_TEST_CASE( retain ) { BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::yes); BOOST_TEST(contents == "response_contents"); c->disconnect(); - return true; }); c->set_close_handler( [&] diff --git a/test/system/st_resend.cpp b/test/system/st_resend.cpp index 6e8ead061..057c958a3 100644 --- a/test/system/st_resend.cpp +++ b/test/system/st_resend.cpp @@ -135,7 +135,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub] @@ -143,7 +142,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -171,7 +169,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub] @@ -179,7 +176,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -284,14 +280,12 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub] @@ -299,7 +293,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -327,14 +320,12 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_pubrec_handler( [&chk, &pid_pub] (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub] @@ -342,7 +333,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -495,7 +485,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_pubrec_handler( [&chk, &c, &pid_pub] @@ -503,7 +492,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c->force_disconnect(); - return true; }); c->set_pubcomp_handler( [&chk, &c] @@ -511,7 +499,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -539,7 +526,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_pubrec_handler( [&chk, &c, &pid_pub, ps = std::move(ps)] @@ -548,7 +534,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { BOOST_TEST(packet_id == pid_pub); c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); c->force_disconnect(); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c] @@ -556,7 +541,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c->disconnect(); - return true; }); break; default: @@ -669,7 +653,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_pubrec_handler( [&chk, &c, &pid_pub] @@ -677,7 +660,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c->force_disconnect(); - return true; }); c->set_pubcomp_handler( [&chk, &c, &pid_pub] @@ -685,7 +667,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -717,7 +698,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_pubrec_handler( [&chk, &c, &pid_pub] @@ -725,7 +705,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c->force_disconnect(); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c, &pid_pub] @@ -733,7 +712,6 @@ BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -863,7 +841,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { } ); BOOST_TEST(ret); - return true; }); c->set_suback_handler( [&chk, &c] @@ -872,7 +849,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; } ); c->set_publish_handler( @@ -909,7 +885,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_puback_handler( @@ -919,7 +894,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { if (chk.passed("h_publish1")) { c->force_disconnect(); } - return true; } ); break; @@ -947,7 +921,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -957,7 +930,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - return true; } ); c->set_v5_publish_handler( @@ -995,7 +967,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_v5_puback_handler( @@ -1005,7 +976,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { if (chk.passed("h_publish1")) { c->force_disconnect(); } - return true; } ); break; @@ -1114,7 +1084,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_suback_handler( @@ -1124,7 +1093,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; } ); c->set_publish_handler( @@ -1144,7 +1112,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { if (chk.passed("h_pubcomp")) { c->force_disconnect(); } - return true; } ); c->set_pubrec_handler( @@ -1152,7 +1119,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; } ); c->set_pubcomp_handler( @@ -1162,7 +1128,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { if (chk.passed("h_publish1")) { c->force_disconnect(); } - return true; } ); break; @@ -1191,7 +1156,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -1201,7 +1165,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; } ); c->set_v5_publish_handler( @@ -1222,7 +1185,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { if (chk.passed("h_pubcomp")) { c->force_disconnect(); } - return true; } ); c->set_v5_pubrec_handler( @@ -1230,7 +1192,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; }); c->set_v5_pubcomp_handler( [&chk, &c] @@ -1239,7 +1200,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { if (chk.passed("h_publish1")) { c->force_disconnect(); } - return true; }); break; default: @@ -1348,7 +1308,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; }); c->set_suback_handler( [&chk, &c] @@ -1357,7 +1316,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; } ); c->set_publish_handler( @@ -1375,7 +1333,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); c->pubrec(packet_id.value()); - return true; } ); c->set_pubrec_handler( @@ -1383,7 +1340,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; } ); c->set_pubrel_handler( @@ -1405,7 +1361,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_pubcomp_handler( @@ -1415,7 +1370,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { if (chk.passed("h_publish")) { c->force_disconnect(); } - return true; } ); break; @@ -1444,7 +1398,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_v5_suback_handler( @@ -1454,7 +1407,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - return true; } ); c->set_v5_publish_handler( @@ -1473,7 +1425,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "topic1_contents"); c->pubrec(packet_id.value()); - return true; } ); c->set_v5_pubrec_handler( @@ -1481,7 +1432,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); c->pubrel(packet_id); - return true; } ); c->set_v5_pubrel_handler( @@ -1503,7 +1453,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_v5_pubcomp_handler( @@ -1513,7 +1462,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { if (chk.passed("h_publish")) { c->force_disconnect(); } - return true; } ); break; @@ -1626,7 +1574,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expired_from_broker ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -1641,7 +1588,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expired_from_broker ) { MQTT_NS::qos::at_least_once, MQTT_NS::v5::properties { MQTT_NS::v5::property::message_expiry_interval(1) } ); - return true; } ); c->set_v5_publish_handler( @@ -1662,7 +1608,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expired_from_broker ) { if (chk.passed("h_puback")) { c->force_disconnect(); } - return true; } ); c->set_v5_puback_handler( @@ -1672,7 +1617,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expired_from_broker ) { if (chk.passed("h_publish")) { c->force_disconnect(); } - return true; } ); @@ -1773,7 +1717,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expiry_update_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_v5_suback_handler( @@ -1789,7 +1732,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expiry_update_from_broker ) { MQTT_NS::qos::at_least_once, MQTT_NS::v5::properties { MQTT_NS::v5::property::message_expiry_interval(5) } ); - return true; } ); c->set_v5_publish_handler( @@ -1841,7 +1783,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expiry_update_from_broker ) { } ); BOOST_TEST(ret); - return true; } ); c->set_v5_puback_handler( @@ -1851,7 +1792,6 @@ BOOST_AUTO_TEST_CASE( publish_message_expiry_update_from_broker ) { if (chk.passed("h_publish1")) { c->force_disconnect(); } - return true; } ); @@ -1948,7 +1888,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_puback_handler( [&chk, &c, &pid_pub1, &pid_pub2] @@ -1965,7 +1904,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -1994,7 +1932,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub1, &pid_pub2] @@ -2011,7 +1948,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -2122,7 +2058,6 @@ BOOST_AUTO_TEST_CASE( publish_session_before_expire ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk, &c, &pid_pub] @@ -2130,7 +2065,6 @@ BOOST_AUTO_TEST_CASE( publish_session_before_expire ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c->disconnect(); - return true; }); break; default: @@ -2253,13 +2187,11 @@ BOOST_AUTO_TEST_CASE( publish_session_after_expire ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_TEST(false); - return true; }); break; default: diff --git a/test/system/st_resend_new_client.cpp b/test/system/st_resend_new_client.cpp index 9bcea6b9f..bd4c076be 100644 --- a/test/system/st_resend_new_client.cpp +++ b/test/system/st_resend_new_client.cpp @@ -90,7 +90,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -131,7 +130,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -145,7 +143,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -229,7 +226,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -270,7 +266,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -283,7 +278,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { (MQTT_NS::broker::packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -291,7 +285,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -373,7 +366,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -413,7 +405,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c1->force_disconnect(); - return true; }); c2->set_connack_handler( @@ -422,7 +413,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -436,7 +426,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -522,7 +511,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -562,7 +550,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -585,7 +572,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -736,7 +722,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -777,7 +762,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -791,7 +775,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -877,7 +860,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -918,7 +900,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -931,7 +912,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { (MQTT_NS::broker::packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_v5_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -939,7 +919,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1073,7 +1052,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1114,7 +1092,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(packet_id == pid_pub); c1->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); c1->force_disconnect(); - return true; }); c2->set_v5_connack_handler( @@ -1123,7 +1100,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1137,7 +1113,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1225,7 +1200,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1265,7 +1239,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1288,7 +1261,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); diff --git a/test/system/st_resend_serialize.cpp b/test/system/st_resend_serialize.cpp index f7b70a990..fe937ec25 100644 --- a/test/system/st_resend_serialize.cpp +++ b/test/system/st_resend_serialize.cpp @@ -182,7 +182,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -227,7 +226,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -241,7 +239,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -339,7 +336,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -384,7 +380,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -397,7 +392,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -405,7 +399,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -501,7 +494,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -545,7 +537,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c1->force_disconnect(); - return true; }); c2->set_connack_handler( @@ -554,7 +545,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -568,7 +558,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -668,7 +657,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -712,7 +700,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -735,7 +722,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -980,7 +966,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1025,7 +1010,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1039,7 +1023,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -1139,7 +1122,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1184,7 +1166,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1197,7 +1178,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_v5_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -1205,7 +1185,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1353,7 +1332,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1398,7 +1376,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(packet_id == pid_pub); c1->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); c1->force_disconnect(); - return true; }); c2->set_v5_connack_handler( @@ -1407,7 +1384,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1421,7 +1397,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1523,7 +1498,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1567,7 +1541,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1590,7 +1563,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); diff --git a/test/system/st_resend_serialize_ptr_size.cpp b/test/system/st_resend_serialize_ptr_size.cpp index 8113abe8b..0c831962b 100644 --- a/test/system/st_resend_serialize_ptr_size.cpp +++ b/test/system/st_resend_serialize_ptr_size.cpp @@ -120,7 +120,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -157,7 +156,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -171,7 +169,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -263,7 +260,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -300,7 +296,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -313,7 +308,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { (packet_id_t packet_id) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -321,7 +315,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -411,7 +404,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -447,7 +439,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); c1->force_disconnect(); - return true; }); c2->set_connack_handler( @@ -456,7 +447,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -470,7 +460,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -564,7 +553,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -600,7 +588,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -623,7 +610,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -806,7 +792,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -843,7 +828,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -857,7 +841,6 @@ BOOST_AUTO_TEST_CASE( publish_qos1_v5 ) { MQTT_CHK("h_puback"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); @@ -951,7 +934,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -988,7 +970,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1001,7 +982,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_pubrec"); BOOST_TEST(packet_id == pid_pub); - return true; }); c2->set_v5_pubcomp_handler( [&chk, &c2, &pid_pub] @@ -1009,7 +989,6 @@ BOOST_AUTO_TEST_CASE( publish_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == pid_pub); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1151,7 +1130,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1188,7 +1166,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(packet_id == pid_pub); c1->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); c1->force_disconnect(); - return true; }); c2->set_v5_connack_handler( @@ -1197,7 +1174,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1211,7 +1187,6 @@ BOOST_AUTO_TEST_CASE( pubrel_qos2_v5 ) { MQTT_CHK("h_pubcomp"); BOOST_TEST(packet_id == 1); c2->disconnect(); - return true; }); MQTT_CHK("start"); c1->connect(); @@ -1307,7 +1282,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c1] @@ -1343,7 +1317,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); MQTT_CHK("h_connack3"); BOOST_TEST(sp == true); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1366,7 +1339,6 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1_v5 ) { } ); BOOST_TEST(ret); - return true; }); MQTT_CHK("start"); c1->connect(); diff --git a/test/system/st_retain_1.cpp b/test/system/st_retain_1.cpp index a11832640..e0053c309 100644 --- a/test/system/st_retain_1.cpp +++ b/test/system/st_retain_1.cpp @@ -52,25 +52,21 @@ BOOST_AUTO_TEST_CASE( simple ) { c->publish("topic1", "retained_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::yes); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &pid_sub] @@ -79,7 +75,6 @@ BOOST_AUTO_TEST_CASE( simple ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -87,7 +82,6 @@ BOOST_AUTO_TEST_CASE( simple ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -103,7 +97,6 @@ BOOST_AUTO_TEST_CASE( simple ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "retained_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -117,25 +110,21 @@ BOOST_AUTO_TEST_CASE( simple ) { c->publish("topic1", "retained_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::yes); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &pid_sub] @@ -144,7 +133,6 @@ BOOST_AUTO_TEST_CASE( simple ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -154,7 +142,6 @@ BOOST_AUTO_TEST_CASE( simple ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -171,7 +158,6 @@ BOOST_AUTO_TEST_CASE( simple ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "retained_contents"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: @@ -237,25 +223,21 @@ BOOST_AUTO_TEST_CASE( overwrite ) { c->publish("topic1", "retained_contents3", MQTT_NS::qos::at_most_once | MQTT_NS::retain::no); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &pid_sub] @@ -264,7 +246,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_unsub] @@ -272,7 +253,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { MQTT_CHK("h_unsuback"); BOOST_TEST(packet_id == pid_unsub); c->disconnect(); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -288,7 +268,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "retained_contents2"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -304,25 +283,21 @@ BOOST_AUTO_TEST_CASE( overwrite ) { c->publish("topic1", "retained_contents3", MQTT_NS::qos::at_most_once | MQTT_NS::retain::no); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &pid_sub] @@ -331,7 +306,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -341,7 +315,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -358,7 +331,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "retained_contents2"); pid_unsub = c->unsubscribe("topic1"); - return true; }); break; default: diff --git a/test/system/st_retain_2.cpp b/test/system/st_retain_2.cpp index 06a069349..9d0499bbc 100644 --- a/test/system/st_retain_2.cpp +++ b/test/system/st_retain_2.cpp @@ -55,25 +55,21 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_puback_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubrec_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_pubcomp_handler( [] (std::uint16_t) { BOOST_CHECK(false); - return true; }); c->set_suback_handler( [&chk, &c, &pid_sub] @@ -91,7 +87,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); c->set_unsuback_handler( [&chk, &c, &pid_sub, &pid_unsub] @@ -108,7 +103,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); c->set_publish_handler( [&chk, &c, &pid_unsub] @@ -133,7 +127,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -144,25 +137,21 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -180,7 +169,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_sub, &pid_unsub] @@ -199,7 +187,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -225,7 +212,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -299,25 +285,21 @@ BOOST_AUTO_TEST_CASE( retain_and_publish_timeout ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub, &pid_unsub, &timeout, message_timeout] @@ -349,7 +331,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish_timeout ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_sub, &pid_unsub, &timeout, message_timeout] @@ -376,7 +357,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish_timeout ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -402,7 +382,6 @@ BOOST_AUTO_TEST_CASE( retain_and_publish_timeout ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -470,25 +449,21 @@ BOOST_AUTO_TEST_CASE( retain_rap ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::rap::retain); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &pid_sub] @@ -506,7 +481,6 @@ BOOST_AUTO_TEST_CASE( retain_rap ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_sub, &pid_unsub] @@ -525,7 +499,6 @@ BOOST_AUTO_TEST_CASE( retain_rap ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub] @@ -551,7 +524,6 @@ BOOST_AUTO_TEST_CASE( retain_rap ) { } ); BOOST_TEST(ret); - return true; }); c->set_close_handler( @@ -612,25 +584,21 @@ BOOST_AUTO_TEST_CASE( retain_rh_send ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::rap::retain); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -650,7 +618,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_send ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -675,7 +642,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_send ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -706,7 +672,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_send ) { } ); BOOST_TEST(ret); - return true; }); c->set_close_handler( @@ -766,25 +731,21 @@ BOOST_AUTO_TEST_CASE( retain_rh_only_newsub ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::rap::retain); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -804,7 +765,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_only_newsub ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -829,7 +789,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_only_newsub ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -855,7 +814,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_only_newsub ) { } ); BOOST_TEST(ret); - return true; }); c->set_close_handler( @@ -914,25 +872,21 @@ BOOST_AUTO_TEST_CASE( retain_rh_not_send ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once | MQTT_NS::rap::retain); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -953,7 +907,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_not_send ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -978,7 +931,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_not_send ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -995,7 +947,6 @@ BOOST_AUTO_TEST_CASE( retain_rh_not_send ) { c->unsubscribe("topic1"); MQTT_CHK("h_publish1"); BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::yes); - return true; }); c->set_close_handler( @@ -1068,25 +1019,21 @@ BOOST_AUTO_TEST_CASE( prop ) { c->publish("topic1", "retained_contents", MQTT_NS::qos::at_most_once | MQTT_NS::retain::yes, MQTT_NS::force_move(ps)); pid_sub = c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &pid_sub] @@ -1095,7 +1042,6 @@ BOOST_AUTO_TEST_CASE( prop ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1105,7 +1051,6 @@ BOOST_AUTO_TEST_CASE( prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c, &pid_unsub, prop_size, &user_prop_count] @@ -1171,7 +1116,6 @@ BOOST_AUTO_TEST_CASE( prop ) { } pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_close_handler( [&chk, &finish] @@ -1233,25 +1177,21 @@ BOOST_AUTO_TEST_CASE( sid ) { "topic1", MQTT_NS::qos::at_most_once, MQTT_NS::v5::properties{ MQTT_NS::v5::property::subscription_identifier(123) } ); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &pid_sub] @@ -1260,7 +1200,6 @@ BOOST_AUTO_TEST_CASE( sid ) { BOOST_TEST(packet_id == pid_sub); BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &pid_unsub] @@ -1270,7 +1209,6 @@ BOOST_AUTO_TEST_CASE( sid ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&] @@ -1302,7 +1240,6 @@ BOOST_AUTO_TEST_CASE( sid ) { } pid_unsub = c->unsubscribe("topic1"); - return true; }); c->set_close_handler( [&chk, &finish] diff --git a/test/system/st_shared_sub.cpp b/test/system/st_shared_sub.cpp index 9a4219f2e..8b084dd70 100644 --- a/test/system/st_shared_sub.cpp +++ b/test/system/st_shared_sub.cpp @@ -97,7 +97,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s1->connect(); - return true; } ); @@ -108,7 +107,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s2->connect(); - return true; } ); @@ -119,7 +117,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s3->connect(); - return true; } ); @@ -136,7 +133,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { {"$share/sn1/t2", MQTT_NS::qos::at_most_once} } ); - return true; } ); @@ -150,7 +146,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { s2->subscribe("$share/sn1/t2", MQTT_NS::qos::at_most_once); - return true; } ); @@ -167,7 +162,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { {"$share/sn1/t2", MQTT_NS::qos::at_most_once} } ); - return true; } ); @@ -188,7 +182,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { p1->publish("t1", "contents7", MQTT_NS::qos::at_most_once); p1->publish("t2", "contents8", MQTT_NS::qos::at_most_once); p1->disconnect(); - return true; } ); @@ -230,7 +223,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { } ); BOOST_TEST(ret); - return true; } ); @@ -263,7 +255,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { } ); BOOST_TEST(ret); - return true; } ); @@ -305,7 +296,6 @@ BOOST_AUTO_TEST_CASE( qos0 ) { } ); BOOST_TEST(ret); - return true; } ); @@ -434,7 +424,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s1->connect(); - return true; } ); @@ -445,7 +434,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s2->connect(); - return true; } ); @@ -456,7 +444,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); s3->connect(); - return true; } ); @@ -469,7 +456,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { s1->subscribe("$share/sn1/t1", MQTT_NS::qos::at_most_once); - return true; } ); @@ -482,7 +468,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { s2->subscribe("$share/sn1/t2", MQTT_NS::qos::at_most_once); - return true; } ); @@ -495,7 +480,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { s3->subscribe("$share/sn1/t1", MQTT_NS::qos::at_most_once); - return true; } ); @@ -508,7 +492,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { p1->publish("t1", "contents1", MQTT_NS::qos::at_most_once); - return true; } ); @@ -527,7 +510,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { BOOST_TEST(topic == "t1"); BOOST_TEST(contents == "contents1"); s2->unsubscribe("$share/sn1/t2"); - return true; } ); @@ -539,7 +521,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); p1->publish("t1", "contents2", MQTT_NS::qos::at_most_once); - return true; } ); @@ -561,7 +542,6 @@ BOOST_AUTO_TEST_CASE( unsub_target ) { s1->disconnect(); s2->disconnect(); s3->disconnect(); - return true; } ); diff --git a/test/system/st_sub.cpp b/test/system/st_sub.cpp index a9d5b9b19..3200eb7b7 100644 --- a/test/system/st_sub.cpp +++ b/test/system/st_sub.cpp @@ -47,7 +47,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_suback_handler( [&chk, &c] @@ -56,14 +55,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single ) { BOOST_TEST(results.size() == 1); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c->unsubscribe("topic1"); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -74,7 +71,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -83,7 +79,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single ) { BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); MQTT_CHK("h_suback"); c->unsubscribe("topic1"); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -92,7 +87,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single ) { BOOST_TEST(reasons.size() == 1); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); break; default: @@ -151,7 +145,6 @@ BOOST_AUTO_TEST_CASE( sub_update ) { c->subscribe("topic1", MQTT_NS::qos::at_most_once); c->subscribe("topic1", MQTT_NS::qos::at_least_once); c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_suback_handler( [&chk, &c] @@ -173,14 +166,12 @@ BOOST_AUTO_TEST_CASE( sub_update ) { } ); BOOST_TEST(ret); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -193,7 +184,6 @@ BOOST_AUTO_TEST_CASE( sub_update ) { c->subscribe("topic1", MQTT_NS::qos::at_most_once); c->subscribe("topic1", MQTT_NS::qos::at_least_once); c->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -215,7 +205,6 @@ BOOST_AUTO_TEST_CASE( sub_update ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -224,7 +213,6 @@ BOOST_AUTO_TEST_CASE( sub_update ) { BOOST_TEST(reasons.size() == 1); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); break; default: @@ -279,21 +267,18 @@ BOOST_AUTO_TEST_CASE( sub_v5_options ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->unsubscribe("topic1"); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -307,21 +292,18 @@ BOOST_AUTO_TEST_CASE( sub_v5_options ) { | MQTT_NS::rap::retain | MQTT_NS::qos::at_most_once | MQTT_NS::retain_handling::not_send); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe("topic1"); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -382,21 +364,18 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg ) { {"topic2", MQTT_NS::qos::exactly_once} } ); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->unsubscribe( std::vector{ MQTT_NS::string_view{"topic1"}, MQTT_NS::string_view{"topic2"} } ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -413,21 +392,18 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg ) { {"topic2", MQTT_NS::qos::exactly_once} } ); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe( std::vector{ MQTT_NS::string_view{"topic1"}, MQTT_NS::string_view{"topic2"} }); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -485,7 +461,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec ) { v.emplace_back("topic1", MQTT_NS::qos::at_most_once); v.emplace_back("topic2", MQTT_NS::qos::exactly_once); c->subscribe(v); - return true; }); c->set_suback_handler( [&chk, &c] @@ -497,14 +472,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec ) { "topic2", }; c->unsubscribe(v); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -518,7 +491,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec ) { v.emplace_back("topic1", MQTT_NS::qos::at_most_once); v.emplace_back("topic2", MQTT_NS::qos::exactly_once); c->subscribe(v); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -530,14 +502,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec ) { "topic2", }; c->unsubscribe(v); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); break; default: @@ -592,21 +562,18 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single_async ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c->async_subscribe("topic1", MQTT_NS::qos::at_most_once, [](MQTT_NS::error_code) {}); - return true; }); c->set_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*results*/) { MQTT_CHK("h_suback"); c->async_unsubscribe("topic1", [](MQTT_NS::error_code) {}); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -617,21 +584,18 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_single_async ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->async_subscribe("topic1", MQTT_NS::qos::at_most_once, [](MQTT_NS::error_code) {}); - return true; }); c->set_v5_suback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->async_unsubscribe("topic1", [](MQTT_NS::error_code) {}); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: @@ -693,7 +657,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg_async ) { }, [](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c] @@ -706,14 +669,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg_async ) { }, [](MQTT_NS::error_code) {} ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -731,7 +692,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg_async ) { }, [](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -744,14 +704,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_arg_async ) { }, [](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: @@ -812,7 +770,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec_async ) { v, [](MQTT_NS::error_code) {} ); - return true; }); c->set_suback_handler( [&chk, &c] @@ -827,14 +784,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec_async ) { v, [](MQTT_NS::error_code) {} ); - return true; }); c->set_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; case MQTT_NS::protocol_version::v5: @@ -851,7 +806,6 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec_async ) { v, [](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -866,14 +820,12 @@ BOOST_AUTO_TEST_CASE( qos0_sub_string_multi_vec_async ) { v, [](MQTT_NS::error_code) {} ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->async_disconnect(); - return true; }); break; default: @@ -1010,21 +962,18 @@ BOOST_AUTO_TEST_CASE( sub_unsub_prop ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once, subps); - return true; }); c->set_v5_suback_handler( [&chk, &c, &unsubps] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_suback"); c->unsubscribe("topic1", unsubps); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback"); c->disconnect(); - return true; }); c->set_close_handler( [&chk, &finish] @@ -1095,7 +1044,6 @@ BOOST_AUTO_TEST_CASE( suback_unsuback_prop ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_suback_handler( [&chk, &c, &sub_user_prop_count, suback_prop_size] @@ -1132,7 +1080,6 @@ BOOST_AUTO_TEST_CASE( suback_unsuback_prop ) { } c->unsubscribe("topic1"); - return true; }); c->set_v5_unsuback_handler( [&chk, &c, &unsub_user_prop_count, unsuback_prop_size] @@ -1168,7 +1115,6 @@ BOOST_AUTO_TEST_CASE( suback_unsuback_prop ) { ); } c->disconnect(); - return true; }); c->set_close_handler( [&chk, &finish] diff --git a/test/system/st_topic_alias.cpp b/test/system/st_topic_alias.cpp index d1d73b00b..241496640 100644 --- a/test/system/st_topic_alias.cpp +++ b/test/system/st_topic_alias.cpp @@ -54,25 +54,21 @@ BOOST_AUTO_TEST_CASE( pubsub ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -98,7 +94,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { MQTT_NS::v5::property::topic_alias(0x1U) } ); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -107,7 +102,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -138,7 +132,6 @@ BOOST_AUTO_TEST_CASE( pubsub ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -256,7 +249,6 @@ BOOST_AUTO_TEST_CASE( auto_replace ) { "topic1_contents_2", MQTT_NS::qos::at_most_once ); - return true; }); break; default: @@ -413,7 +405,6 @@ BOOST_AUTO_TEST_CASE( auto_map ) { "topic5_contents_6", MQTT_NS::qos::at_most_once ); - return true; }); break; default: @@ -486,25 +477,21 @@ BOOST_AUTO_TEST_CASE( overwrite ) { BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); c->subscribe("topic2", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -547,7 +534,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -566,7 +552,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -607,7 +592,6 @@ BOOST_AUTO_TEST_CASE( overwrite ) { } ); BOOST_TEST(ret); - return true; }); break; default: @@ -671,25 +655,21 @@ BOOST_AUTO_TEST_CASE( no_entry ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c->set_v5_puback_handler( [] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c] @@ -713,13 +693,11 @@ BOOST_AUTO_TEST_CASE( no_entry ) { BOOST_TEST(e.what() == "protocol error"); c->disconnect(); } - return true; }); c->set_v5_unsuback_handler( [] (packet_id_t /*packet_id*/, std::vector /*reasons*/, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_publish_handler( [] @@ -729,7 +707,6 @@ BOOST_AUTO_TEST_CASE( no_entry ) { MQTT_NS::buffer /*contents*/, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_disconnect_handler( [&chk] @@ -830,25 +807,21 @@ BOOST_AUTO_TEST_CASE( resend_publish ) { } ); BOOST_TEST(ret); - return true; }); c->set_v5_puback_handler( [&chk] (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_puback"); - return true; }); c->set_v5_pubrec_handler( [] (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_pubcomp_handler( [] (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { BOOST_CHECK(false); - return true; }); c->set_v5_suback_handler( [&chk, &c, &tim] @@ -890,7 +863,6 @@ BOOST_AUTO_TEST_CASE( resend_publish ) { // See https://lists.oasis-open.org/archives/mqtt-comment/202009/msg00000.html c->force_disconnect(); - return true; }); c->set_v5_unsuback_handler( [&chk, &c] @@ -899,7 +871,6 @@ BOOST_AUTO_TEST_CASE( resend_publish ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c->disconnect(); - return true; }); c->set_v5_publish_handler( [&chk, &c] @@ -930,7 +901,6 @@ BOOST_AUTO_TEST_CASE( resend_publish ) { } ); BOOST_TEST(ret); - return true; }); break; default: diff --git a/test/system/st_utf8string_validate.cpp b/test/system/st_utf8string_validate.cpp index 38ea9d871..528a0269b 100644 --- a/test/system/st_utf8string_validate.cpp +++ b/test/system/st_utf8string_validate.cpp @@ -209,19 +209,16 @@ BOOST_AUTO_TEST_CASE( publish_overlength_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->publish(tp, "topic1_contents", MQTT_NS::qos::at_most_once); - return true; } catch (MQTT_NS::utf8string_length_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } catch (boost::bad_numeric_cast const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); @@ -247,13 +244,11 @@ BOOST_AUTO_TEST_CASE( publish_invalid_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->publish(tp, "topic1_contents", MQTT_NS::qos::at_most_once); - return true; } catch (MQTT_NS::utf8string_contents_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); @@ -279,13 +274,11 @@ BOOST_AUTO_TEST_CASE( subscribe_overlength_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->subscribe(tp, MQTT_NS::qos::at_most_once); - return true; } catch (MQTT_NS::utf8string_length_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); @@ -311,13 +304,11 @@ BOOST_AUTO_TEST_CASE( subscribe_invalid_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->subscribe(tp, MQTT_NS::qos::at_most_once); - return true; } catch (MQTT_NS::utf8string_contents_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); @@ -343,13 +334,11 @@ BOOST_AUTO_TEST_CASE( unsubscribe_overlength_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->unsubscribe(tp); - return true; } catch (MQTT_NS::utf8string_length_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); @@ -375,13 +364,11 @@ BOOST_AUTO_TEST_CASE( unsubscribe_invalid_topic ) { (bool, MQTT_NS::connect_return_code) { try { c->unsubscribe(tp); - return true; } catch (MQTT_NS::utf8string_contents_error const&) { BOOST_CHECK(true); finish(); c->force_disconnect(); - return false; } } ); diff --git a/test/system/st_will.cpp b/test/system/st_will.cpp index a0b782ae5..9a79b041e 100644 --- a/test/system/st_will.cpp +++ b/test/system/st_will.cpp @@ -87,7 +87,6 @@ BOOST_AUTO_TEST_CASE( will_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -115,7 +114,6 @@ BOOST_AUTO_TEST_CASE( will_qos0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -136,7 +134,6 @@ BOOST_AUTO_TEST_CASE( will_qos0 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_0); c1_force_disconnect(); - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -144,7 +141,6 @@ BOOST_AUTO_TEST_CASE( will_qos0 ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_publish_handler( [&chk, &c2, &pid_unsub2] @@ -160,7 +156,6 @@ BOOST_AUTO_TEST_CASE( will_qos0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "will_contents"); pid_unsub2 = c2->unsubscribe("topic1"); - return true; }); c1->connect(); @@ -247,7 +242,6 @@ BOOST_AUTO_TEST_CASE( will_qo0_timeout ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -270,7 +264,6 @@ BOOST_AUTO_TEST_CASE( will_qo0_timeout ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -309,7 +302,6 @@ BOOST_AUTO_TEST_CASE( will_qo0_timeout ) { } ); - return true; }); c2->set_v5_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -317,7 +309,6 @@ BOOST_AUTO_TEST_CASE( will_qo0_timeout ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_v5_publish_handler( [] @@ -329,7 +320,6 @@ BOOST_AUTO_TEST_CASE( will_qo0_timeout ) { // Will should not be received BOOST_TEST(false); - return true; }); c1->connect(); @@ -416,7 +406,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_wd0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -436,7 +425,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_wd0 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -456,14 +444,12 @@ BOOST_AUTO_TEST_CASE( will_qos0_wd0 ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c1_force_disconnect(); - return true; }); c2->set_v5_unsuback_handler( [&chk, &c2] (packet_id_t, std::vector, MQTT_NS::v5::properties /*props*/) { MQTT_CHK("h_unsuback_2"); c2->disconnect(); - return true; }); c2->set_v5_publish_handler( [&chk, &c2] @@ -480,7 +466,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_wd0 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "will_contents"); c2->unsubscribe("topic1"); - return true; }); c1->connect(); @@ -578,7 +563,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_cancel ) { } ); BOOST_TEST(ret); - return true; }); c1->set_close_handler( [&chk, &c2] @@ -600,7 +584,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_cancel ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -620,7 +603,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_cancel ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c1_force_disconnect(); - return true; }); c2->set_v5_publish_handler( [] @@ -631,7 +613,6 @@ BOOST_AUTO_TEST_CASE( will_qos0_cancel ) { MQTT_NS::v5::properties /*props*/) { // Will should not be received BOOST_TEST(false); - return true; }); c1->connect( @@ -713,7 +694,6 @@ BOOST_AUTO_TEST_CASE( will_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -737,7 +717,6 @@ BOOST_AUTO_TEST_CASE( will_qos1 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_least_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -758,7 +737,6 @@ BOOST_AUTO_TEST_CASE( will_qos1 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_1); c1_force_disconnect(); - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -766,7 +744,6 @@ BOOST_AUTO_TEST_CASE( will_qos1 ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_publish_handler( [&chk, &c2, &pid_unsub2] @@ -782,7 +759,6 @@ BOOST_AUTO_TEST_CASE( will_qos1 ) { BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "will_contents"); pid_unsub2 = c2->unsubscribe("topic1"); - return true; }); c1->connect(); @@ -861,7 +837,6 @@ BOOST_AUTO_TEST_CASE( will_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -885,7 +860,6 @@ BOOST_AUTO_TEST_CASE( will_qos2 ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::exactly_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -906,7 +880,6 @@ BOOST_AUTO_TEST_CASE( will_qos2 ) { BOOST_TEST(results.size() == 1U); BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); c1_force_disconnect(); - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -914,7 +887,6 @@ BOOST_AUTO_TEST_CASE( will_qos2 ) { MQTT_CHK("h_unsuback_2"); BOOST_TEST(packet_id == pid_unsub2); c2->disconnect(); - return true; }); c2->set_publish_handler( [&chk] @@ -929,7 +901,6 @@ BOOST_AUTO_TEST_CASE( will_qos2 ) { BOOST_CHECK(*packet_id != 0); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "will_contents"); - return true; }); c2->set_pub_res_sent_handler( [&chk, &c2, &pid_unsub2] @@ -1018,7 +989,6 @@ BOOST_AUTO_TEST_CASE( will_retain ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -1042,7 +1012,6 @@ BOOST_AUTO_TEST_CASE( will_retain ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1071,7 +1040,6 @@ BOOST_AUTO_TEST_CASE( will_retain ) { } ); BOOST_TEST(ret); - return true; }); c2->set_unsuback_handler( [&chk, &c2, &pid_unsub2, &pid_sub2] @@ -1088,7 +1056,6 @@ BOOST_AUTO_TEST_CASE( will_retain ) { } ); BOOST_TEST(ret); - return true; }); c2->set_publish_handler( [&chk, &c2, &pid_unsub2] @@ -1113,7 +1080,6 @@ BOOST_AUTO_TEST_CASE( will_retain ) { } ); BOOST_TEST(ret); - return true; }); c1->connect(); @@ -1261,7 +1227,6 @@ BOOST_AUTO_TEST_CASE( will_prop ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); c1_force_disconnect(); - return true; }); c1->set_close_handler( [] @@ -1289,7 +1254,6 @@ BOOST_AUTO_TEST_CASE( will_prop ) { BOOST_TEST(sp == false); BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); pid_sub2 = c2->subscribe("topic1", MQTT_NS::qos::at_most_once); - return true; }); c2->set_close_handler( [&chk, &finish] @@ -1310,7 +1274,6 @@ BOOST_AUTO_TEST_CASE( will_prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_0); c1_force_disconnect(); - return true; }); c2->set_v5_unsuback_handler( [&chk, &c2, &pid_unsub2] @@ -1320,7 +1283,6 @@ BOOST_AUTO_TEST_CASE( will_prop ) { BOOST_TEST(reasons.size() == 1U); BOOST_TEST(reasons[0] == MQTT_NS::v5::unsuback_reason_code::success); c2->disconnect(); - return true; }); c2->set_v5_publish_handler( [&chk, &c2, &pid_unsub2, prop_size, &user_prop_count] @@ -1387,7 +1349,6 @@ BOOST_AUTO_TEST_CASE( will_prop ) { } pid_unsub2 = c2->unsubscribe("topic1"); - return true; }); c1->connect(); From 8413ce257915eca80a246cec06d617daa2a74968 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Wed, 12 Oct 2022 20:47:58 +0900 Subject: [PATCH 4/5] Added copyable handlers. It is also supputs bind_executor. It can work well with non oneshot handler like publish_handler.. --- include/mqtt/callable_overlay.hpp | 84 +++++++++++++++--------------- include/mqtt/copyable_function.hpp | 30 +++++++++++ include/mqtt/copyable_handler.hpp | 66 +++++++++++++++++++++++ 3 files changed, 138 insertions(+), 42 deletions(-) create mode 100644 include/mqtt/copyable_function.hpp create mode 100644 include/mqtt/copyable_handler.hpp diff --git a/include/mqtt/callable_overlay.hpp b/include/mqtt/callable_overlay.hpp index 75d0f5326..41ca3d83f 100644 --- a/include/mqtt/callable_overlay.hpp +++ b/include/mqtt/callable_overlay.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace MQTT_NS { template @@ -727,14 +727,14 @@ struct callable_overlay final : public Impl * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718086
* 3.13 PINGREQ – PING request */ - using pingreq_handler = move_only_handler; + using pingreq_handler = copyable_handler; /** * @brief Pingresp handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200
* 3.13 PINGRESP – PING response */ - using pingresp_handler = move_only_handler; + using pingresp_handler = copyable_handler; // MQTT v3_1_1 handlers @@ -775,7 +775,7 @@ struct callable_overlay final : public Impl * 3.1.2.10 Keep Alive * */ - using connect_handler = move_only_handler< + using connect_handler = copyable_handler< void(buffer client_id, optional user_name, optional password, @@ -794,7 +794,7 @@ struct callable_overlay final : public Impl * See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718036
* 3.2.2.3 Connect Return code */ - using connack_handler = move_only_handler; + using connack_handler = copyable_handler; /** * @brief Publish handler @@ -812,7 +812,7 @@ struct callable_overlay final : public Impl * @param contents * Published contents */ - using publish_handler = move_only_handler packet_id, + using publish_handler = copyable_handler packet_id, publish_options pubopts, buffer topic_name, buffer contents)>; @@ -824,7 +824,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.4.2 Variable header */ - using puback_handler = move_only_handler; + using puback_handler = copyable_handler; /** * @brief Pubrec handler @@ -833,7 +833,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718050
* 3.5.2 Variable header */ - using pubrec_handler = move_only_handler; + using pubrec_handler = copyable_handler; /** * @brief Pubrel handler @@ -842,7 +842,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349791
* 3.6.2 Variable header */ - using pubrel_handler = move_only_handler; + using pubrel_handler = copyable_handler; /** * @brief Pubcomp handler @@ -851,7 +851,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718060
* 3.7.2 Variable header */ - using pubcomp_handler = move_only_handler; + using pubcomp_handler = copyable_handler; /** * @brief Subscribe handler @@ -862,7 +862,7 @@ struct callable_overlay final : public Impl * Collection of Share Name, Topic Filter, and QoS.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349802
*/ - using subscribe_handler = move_only_handler entries)>; /** @@ -875,7 +875,7 @@ struct callable_overlay final : public Impl * If subscription is failure, the value is nullopt.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718071
*/ - using suback_handler = move_only_handler qoss)>; /** @@ -887,7 +887,7 @@ struct callable_overlay final : public Impl * Collection of Share Name and Topic Filter
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800448
*/ - using unsubscribe_handler = move_only_handler entries)>; /** @@ -896,14 +896,14 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718045
* 3.11.2 Variable header */ - using unsuback_handler = move_only_handler; + using unsuback_handler = copyable_handler; /** * @brief Disconnect handler * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc384800463
* 3.14 DISCONNECT – Disconnect notification */ - using disconnect_handler = move_only_handler; + using disconnect_handler = copyable_handler; // MQTT v5 handlers @@ -949,7 +949,7 @@ struct callable_overlay final : public Impl * 3.1.2.11 CONNECT Properties * */ - using v5_connect_handler = move_only_handler< + using v5_connect_handler = copyable_handler< void(buffer client_id, optional user_name, optional password, @@ -974,7 +974,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080
* 3.2.2.3 CONNACK Properties */ - using v5_connack_handler = move_only_handler< + using v5_connack_handler = copyable_handler< void(bool session_present, v5::connect_reason_code reason_code, v5::properties props) @@ -1004,7 +1004,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901109
* 3.3.2.3 PUBLISH Properties */ - using v5_publish_handler = move_only_handler< + using v5_publish_handler = copyable_handler< void(optional packet_id, publish_options pubopts, buffer topic_name, @@ -1027,7 +1027,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125
* 3.4.2.2 PUBACK Properties */ - using v5_puback_handler = move_only_handler< + using v5_puback_handler = copyable_handler< void(packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props) @@ -1048,7 +1048,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135
* 3.5.2.2 PUBREC Properties */ - using v5_pubrec_handler = move_only_handler< + using v5_pubrec_handler = copyable_handler< void(packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props) @@ -1069,7 +1069,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties */ - using v5_pubrel_handler = move_only_handler< + using v5_pubrel_handler = copyable_handler< void(packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props) @@ -1090,7 +1090,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155
* 3.7.2.2 PUBCOMP Properties */ - using v5_pubcomp_handler = move_only_handler< + using v5_pubcomp_handler = copyable_handler< void(packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props) @@ -1109,7 +1109,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties */ - using v5_subscribe_handler = move_only_handler< + using v5_subscribe_handler = copyable_handler< void(packet_id_t packet_id, std::vector entries, v5::properties props) @@ -1129,7 +1129,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties */ - using v5_suback_handler = move_only_handler< + using v5_suback_handler = copyable_handler< void(packet_id_t packet_id, std::vector reasons, v5::properties props) @@ -1149,7 +1149,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties */ - using v5_unsubscribe_handler = move_only_handler< + using v5_unsubscribe_handler = copyable_handler< void(packet_id_t packet_id, std::vector entries, v5::properties props) @@ -1169,7 +1169,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties */ - using v5_unsuback_handler = move_only_handler< + using v5_unsuback_handler = copyable_handler< void(packet_id_t, std::vector reasons, v5::properties props) @@ -1188,7 +1188,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
* 3.14.2.2 DISCONNECT Properties */ - using v5_disconnect_handler = move_only_handler< + using v5_disconnect_handler = copyable_handler< void(v5::disconnect_reason_code reason_code, v5::properties props) >; @@ -1206,7 +1206,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221
* 3.15.2.2 AUTH Properties */ - using v5_auth_handler = move_only_handler< + using v5_auth_handler = copyable_handler< void(v5::auth_reason_code reason_code, v5::properties props) >; @@ -1220,7 +1220,7 @@ struct callable_overlay final : public Impl * This handler is called if the client called `disconnect()` and the server closed the socket cleanly. * If the socket is closed by other reasons, error_handler is called. */ - using close_handler = move_only_handler; + using close_handler = copyable_handler; /** * @brief Error handler @@ -1229,7 +1229,7 @@ struct callable_overlay final : public Impl * * @param ec error code */ - using error_handler = move_only_handler; + using error_handler = copyable_handler; /** * @brief Publish response sent handler @@ -1239,7 +1239,7 @@ struct callable_overlay final : public Impl * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901026
* 2.2.1 Packet Identifier */ - using pub_res_sent_handler = move_only_handler; + using pub_res_sent_handler = copyable_handler; /** * @brief Serialize publish handler @@ -1247,7 +1247,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg publish message */ - using serialize_publish_message_handler = move_only_handler msg)>; + using serialize_publish_message_handler = copyable_handler msg)>; /** * @brief Serialize publish handler @@ -1255,7 +1255,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg v5::publish message */ - using serialize_v5_publish_message_handler = move_only_handler msg)>; + using serialize_v5_publish_message_handler = copyable_handler msg)>; /** * @brief Serialize publish handler @@ -1265,7 +1265,7 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_publish_handler = move_only_handler; + using serialize_publish_handler = copyable_handler; /** * @brief Serialize pubrel handler @@ -1275,7 +1275,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_pubrel_message_handler = move_only_handler msg)>; + using serialize_pubrel_message_handler = copyable_handler msg)>; /** * @brief Serialize pubrel handler @@ -1285,7 +1285,7 @@ struct callable_overlay final : public Impl * To restore the message, use restore_serialized_message(). * @param msg pubrel message */ - using serialize_v5_pubrel_message_handler = move_only_handler msg)>; + using serialize_v5_pubrel_message_handler = copyable_handler msg)>; /** * @brief Serialize pubrel handler @@ -1297,19 +1297,19 @@ struct callable_overlay final : public Impl * @param data pointer to the serializing message * @param size size of the serializing message */ - using serialize_pubrel_handler = move_only_handler; + using serialize_pubrel_handler = copyable_handler; /** * @brief Remove serialized message * @param packet_id packet identifier of the removing message */ - using serialize_remove_handler = move_only_handler; + using serialize_remove_handler = copyable_handler; /** * @brief Pre-send handler * This handler is called when any mqtt control packet is decided to send. */ - using pre_send_handler = move_only_handler; + using pre_send_handler = copyable_handler; /** * @brief is valid length handler @@ -1319,7 +1319,7 @@ struct callable_overlay final : public Impl * @return true if check is success, otherwise false */ using is_valid_length_handler = - move_only_function; + copyable_function; /** * @brief next read handler @@ -1327,7 +1327,7 @@ struct callable_overlay final : public Impl * @param func A callback function that is called when async operation will finish. */ using mqtt_message_processed_handler = - move_only_handler; + copyable_handler; @@ -2019,7 +2019,7 @@ struct callable_overlay final : public Impl * @brief Get error handler * @return handler */ - error_handler const& get_error_handler() const { + error_handler get_error_handler() const { return h_error_; } diff --git a/include/mqtt/copyable_function.hpp b/include/mqtt/copyable_function.hpp new file mode 100644 index 000000000..f59e66e64 --- /dev/null +++ b/include/mqtt/copyable_function.hpp @@ -0,0 +1,30 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_COPYABLE_FUNCTION_HPP) +#define MQTT_COPYABLE_FUNCTION_HPP + +#pragma GCC diagnostic push +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Waddress" +#endif // defined(__GNUC__) + +#include + +#include + +namespace MQTT_NS { + +template +using copyable_function = fu2::function; + +} // namespace MQTT_NS + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif // defined(__GNUC__) + +#endif // MQTT_COPYABLE_FUNCTION_HPP diff --git a/include/mqtt/copyable_handler.hpp b/include/mqtt/copyable_handler.hpp new file mode 100644 index 000000000..919a63885 --- /dev/null +++ b/include/mqtt/copyable_handler.hpp @@ -0,0 +1,66 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_COPYABLE_HANDLER_HPP) +#define MQTT_COPYABLE_HANDLER_HPP + +#include + +#include + +#include +#include +#include +#include + +namespace MQTT_NS { + +namespace as = boost::asio; + +template +struct copyable_handler { + using executor_type = as::any_io_executor; + + copyable_handler() = default; + + template < + typename Func, + typename std::enable_if_t< + std::is_convertible>::value + >* = nullptr + > + copyable_handler(Func&& f) + : exe_{as::get_associated_executor(f)}, + func_{std::forward(f)} + { + } + + executor_type get_executor() const { return exe_; } + + template + void operator()(Params&&... params) { + if (exe_ == as::system_executor()) { + func_(std::forward(params)...); + return; + } + as::dispatch( + exe_, + [func = func_, pt = std::tuple(std::forward(params)...)] () mutable { + MQTT_NS::apply(force_move(func), std::move(pt)); + } + ); + } + + operator bool() const { return static_cast(func_); } + +private: + executor_type exe_; + copyable_function func_; +}; + +} // namespace MQTT_NS + +#endif // MQTT_COPYABLE_HANDLER_HPP From b34ef033d865a25bdf094499143f226adaaebca0 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Wed, 5 Oct 2022 20:31:07 +0900 Subject: [PATCH 5/5] Added completion token support. The async_*() functions can take CompletionToken parameter. It works the same as asio async functions. --- .github/workflows/gha.yml | 16 +- include/mqtt/client.hpp | 754 +++-- include/mqtt/endpoint.hpp | 2561 +++++++++++++---- include/mqtt/is_invocable.hpp | 39 + include/mqtt/move_only_function.hpp | 2 +- include/mqtt/move_only_handler.hpp | 19 +- test/CMakeLists.txt | 1 + test/system/CMakeLists.txt | 7 +- test/system/st_comp_token.cpp | 523 ++++ test/system/st_connect1.cpp | 1062 +++++++ .../{st_connect.cpp => st_connect2.cpp} | 1046 +------ test/system/st_resend.cpp | 2250 --------------- test/system/st_resend_1.cpp | 1030 +++++++ test/system/st_resend_2.cpp | 1031 +++++++ test/unit/CMakeLists.txt | 2 +- 15 files changed, 6138 insertions(+), 4205 deletions(-) create mode 100644 include/mqtt/is_invocable.hpp create mode 100644 test/system/st_comp_token.cpp create mode 100644 test/system/st_connect1.cpp rename test/system/{st_connect.cpp => st_connect2.cpp} (51%) delete mode 100644 test/system/st_resend.cpp create mode 100644 test/system/st_resend_1.cpp create mode 100644 test/system/st_resend_2.cpp diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 12142191f..7c9ffbd28 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -78,14 +78,14 @@ jobs: export CFLAGS=${S_CFLAGS} && export CXXFLAGS=${S_CXXFLAGS} && export LDFLAGS=${S_LDFLAGS} [ ${{ matrix.pattern }} == 0 ] || [ ${{ matrix.pattern }} == 4 ] || [ ${{ matrix.pattern }} == 5 ] || [ ${{ matrix.pattern }} == 6 ] || [ ${{ matrix.pattern }} == 7 ] && \ export CFLAGS=${NS_CFLAGS} && export CXXFLAGS=${NS_CXXFLAGS} && export LDFLAGS=${NS_LDFLAGS} - [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" - [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_TEST_8=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" + [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_TEST_8=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" echo "begin" echo ${{env.BOOST_ROOT}} diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index b4185db58..f907bef77 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace MQTT_NS { @@ -1185,32 +1186,50 @@ class client : public endpoint { * Before calling connect(), call set_xxx member functions to configure the connection. * @param session_life_keeper the passed object lifetime will be kept during the session. */ - template - // to avoid ambiguousness between any and async_handler_t - std::enable_if_t< - !std::is_convertible::value + template < + typename T, + typename std::enable_if_t< + !is_invocable::value + >* = nullptr > - async_connect(T session_life_keeper) { + void async_connect(T session_life_keeper) { async_connect(force_move(session_life_keeper), async_handler_t()); } /** * @brief Connect to a broker * Before calling connect(), call set_xxx member functions to configure the connection. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(async_handler_t func) { - async_connect(any(), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(CompletionToken&& token) { + return async_connect(any(), std::forward(token)); } /** * @brief Connect to a broker * Before calling connect(), call set_xxx member functions to configure the connection. * @param session_life_keeper the passed object lifetime will be kept during the session. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(any session_life_keeper, async_handler_t func) { - async_connect(v5::properties{}, force_move(session_life_keeper), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(any session_life_keeper, CompletionToken&& token) { + return + async_connect( + v5::properties{}, + force_move(session_life_keeper), + std::forward(token) + ); } /** @@ -1221,12 +1240,13 @@ class client : public endpoint { * 3.1.2.11 CONNECT Properties * @param session_life_keeper the passed object lifetime will be kept during the session. */ - template - // to avoid ambiguousness between any and async_handler_t - std::enable_if_t< - !std::is_convertible::value + template < + typename T, + typename std::enable_if_t< + !is_invocable::value + >* = nullptr > - async_connect(v5::properties props, T session_life_keeper) { + void async_connect(v5::properties props, T session_life_keeper) { async_connect(force_move(props), force_move(session_life_keeper), async_handler_t()); } @@ -1236,10 +1256,16 @@ class client : public endpoint { * @param props properties * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(v5::properties props, async_handler_t func) { - async_connect(force_move(props), any(), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(v5::properties props, CompletionToken&& token) { + return async_connect(force_move(props), any(), std::forward(token)); } /** @@ -1249,11 +1275,28 @@ class client : public endpoint { * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties * @param session_life_keeper the passed object lifetime will be kept during the session. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(v5::properties props, any session_life_keeper, async_handler_t func) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(v5::properties props, any session_life_keeper, CompletionToken&& token) { setup_socket(socket_); - async_connect_impl(force_move(props), force_move(session_life_keeper), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_connect_impl{ + *this, + force_move(props), + force_move(session_life_keeper) + }, + token + ); } /** @@ -1273,12 +1316,13 @@ class client : public endpoint { * You can configure the socket prior to connect. * @param session_life_keeper the passed object lifetime will be kept during the session. */ - template - // to avoid ambiguousness between any and async_handler_t - std::enable_if_t< - !std::is_convertible::value + template < + typename T, + typename std::enable_if_t< + !is_invocable::value + >* = nullptr > - async_connect(std::shared_ptr&& socket, T session_life_keeper) { + void async_connect(std::shared_ptr&& socket, T session_life_keeper) { async_connect(force_move(socket), v5::properties{}, force_move(session_life_keeper), async_handler_t()); } @@ -1287,10 +1331,21 @@ class client : public endpoint { * Before calling connect(), call set_xxx member functions to configure the connection. * @param socket The library uses the socket instead of internal generation. * You can configure the socket prior to connect. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(std::shared_ptr&& socket, async_handler_t func) { - async_connect(force_move(socket), v5::properties{}, any(), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(std::shared_ptr&& socket, CompletionToken&& token) { + return + async_connect( + force_move(socket), + v5::properties{}, any(), + std::forward(token) + ); } /** @@ -1299,10 +1354,22 @@ class client : public endpoint { * @param socket The library uses the socket instead of internal generation. * You can configure the socket prior to connect. * @param session_life_keeper the passed object lifetime will be kept during the session. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(std::shared_ptr&& socket, any session_life_keeper, async_handler_t func) { - async_connect(force_move(socket), v5::properties{}, force_move(session_life_keeper), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(std::shared_ptr&& socket, any session_life_keeper, CompletionToken&& token) { + return + async_connect( + force_move(socket), + v5::properties{}, + force_move(session_life_keeper), + std::forward(token) + ); } /** @@ -1328,12 +1395,13 @@ class client : public endpoint { * 3.1.2.11 CONNECT Properties * @param session_life_keeper the passed object lifetime will be kept during the session. */ - template - // to avoid ambiguousness between any and async_handler_t - std::enable_if_t< - !std::is_convertible::value + template < + typename T, + typename std::enable_if_t< + !is_invocable::value + >* = nullptr > - async_connect(std::shared_ptr&& socket, v5::properties props, T session_life_keeper) { + void async_connect(std::shared_ptr&& socket, v5::properties props, T session_life_keeper) { async_connect(force_move(socket), force_move(props), force_move(session_life_keeper), async_handler_t()); } @@ -1345,10 +1413,22 @@ class client : public endpoint { * @param props properties * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionToken that is called when the underlying connection process is finished */ - void async_connect(std::shared_ptr&& socket, v5::properties props, async_handler_t func) { - async_connect(force_move(socket), force_move(props), any(), force_move(func)); + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect(std::shared_ptr&& socket, v5::properties props, CompletionToken&& token) { + return + async_connect( + force_move(socket), + force_move(props), + any(), + std::forward(token) + ); } /** @@ -1360,12 +1440,33 @@ class client : public endpoint { * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties * @param session_life_keeper the passed object lifetime will be kept during the session. - * @param func finish handler that is called when the underlying connection process is finished + * @param token CompletionTokeny that is called when the underlying connection process is finished */ - void async_connect(std::shared_ptr&& socket, v5::properties props, any session_life_keeper, async_handler_t func) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect( + std::shared_ptr&& socket, + v5::properties props, + any session_life_keeper, + CompletionToken&& token) { socket_ = force_move(socket); base::socket_sp_ref() = socket_; - async_connect_impl(force_move(props), force_move(session_life_keeper), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_connect_impl{ + *this, + force_move(props), + force_move(session_life_keeper) + }, + token + ); } /** @@ -1442,30 +1543,51 @@ class client : public endpoint { * When the endpoint disconnects using disconnect(), a will won't send.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205
* @param timeout after timeout elapsed, force_disconnect() is automatically called. - * @param func A callback function that is called when async operation will finish. + * @param reason_code + * DISCONNECT Reason Code
+ * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208
+ * 3.14.2.1 Disconnect Reason Code + * @param props + * Properties
+ * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
+ * 3.14.2.2 DISCONNECT Properties + * @param token CompletionToken that is called when async operation will finish. */ - void async_disconnect( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( std::chrono::steady_clock::duration timeout, - async_handler_t func = async_handler_t()) { + v5::disconnect_reason_code reason_code, + v5::properties props, + CompletionToken&& token = async_handler_t{} + ) { + if (ping_duration_ != std::chrono::steady_clock::duration::zero()) tim_ping_.cancel(); - if (base::connected()) { - std::weak_ptr wp(std::static_pointer_cast(this->shared_from_this())); - tim_close_.expires_after(force_move(timeout)); - tim_close_.async_wait( - [wp = force_move(wp)](error_code ec) { - if (auto sp = wp.lock()) { - if (!ec) { - sp->socket()->post( - [sp] { - sp->force_disconnect(); - } - ); - } + std::weak_ptr wp(std::static_pointer_cast(this->shared_from_this())); + tim_close_.expires_after(force_move(timeout)); + tim_close_.async_wait( + [wp = force_move(wp)](error_code ec) { + if (auto sp = wp.lock()) { + if (!ec) { + sp->socket()->post( + [sp] { + sp->force_disconnect(); + } + ); } } + } + ); + return + base::async_disconnect( + reason_code, + force_move(props), + std::forward(token) ); - base::async_disconnect(force_move(func)); - } } /** @@ -1474,7 +1596,6 @@ class client : public endpoint { * The broker disconnects the endpoint after receives the disconnect packet.
* When the endpoint disconnects using disconnect(), a will won't send.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205
- * @param timeout after timeout elapsed, force_disconnect() is automatically called. * @param reason_code * DISCONNECT Reason Code
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208
@@ -1483,32 +1604,26 @@ class client : public endpoint { * Properties
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
* 3.14.2.2 DISCONNECT Properties - * @param func A callback function that is called when async operation will finish. + * @param token CompletionToken that is called when async operation will finish. */ - void async_disconnect( - std::chrono::steady_clock::duration timeout, + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( v5::disconnect_reason_code reason_code, v5::properties props, - async_handler_t func = async_handler_t()) { + CompletionToken&& token = async_handler_t{} + ) { if (ping_duration_ != std::chrono::steady_clock::duration::zero()) tim_ping_.cancel(); - if (base::connected()) { - std::weak_ptr wp(std::static_pointer_cast(this->shared_from_this())); - tim_close_.expires_after(force_move(timeout)); - tim_close_.async_wait( - [wp = force_move(wp)](error_code ec) { - if (auto sp = wp.lock()) { - if (!ec) { - sp->socket()->post( - [sp] { - sp->force_disconnect(); - } - ); - } - } - } + return + base::async_disconnect( + reason_code, + force_move(props), + std::forward(token) ); - base::async_disconnect(reason_code, force_move(props), force_move(func)); - } } /** @@ -1517,14 +1632,39 @@ class client : public endpoint { * The broker disconnects the endpoint after receives the disconnect packet.
* When the endpoint disconnects using disconnect(), a will won't send.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205
- * @param func A callback function that is called when async operation will finish. + * @param timeout after timeout elapsed, force_disconnect() is automatically called. + * @param token CompletionToken that is called when async operation will finish. */ - void async_disconnect( - async_handler_t func = async_handler_t()) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( + std::chrono::steady_clock::duration timeout, + CompletionToken&& token = async_handler_t{} + ) { if (ping_duration_ != std::chrono::steady_clock::duration::zero()) tim_ping_.cancel(); - if (base::connected()) { - base::async_disconnect(force_move(func)); - } + std::weak_ptr wp(std::static_pointer_cast(this->shared_from_this())); + tim_close_.expires_after(force_move(timeout)); + tim_close_.async_wait( + [wp = force_move(wp)](error_code ec) { + if (auto sp = wp.lock()) { + if (!ec) { + sp->socket()->post( + [sp] { + sp->force_disconnect(); + } + ); + } + } + } + ); + return + base::async_disconnect( + std::forward(token) + ); } /** @@ -1533,24 +1673,19 @@ class client : public endpoint { * The broker disconnects the endpoint after receives the disconnect packet.
* When the endpoint disconnects using disconnect(), a will won't send.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205
- * @param reason_code - * DISCONNECT Reason Code
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901208
- * 3.14.2.1 Disconnect Reason Code - * @param props - * Properties
- * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
- * 3.14.2.2 DISCONNECT Properties - * @param func A callback function that is called when async operation will finish. + * @param token CompletionToken that is called when async operation will finish. */ - void async_disconnect( - v5::disconnect_reason_code reason_code, - v5::properties props, - async_handler_t func = async_handler_t()) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( + CompletionToken&& token = async_handler_t{} + ) { if (ping_duration_ != std::chrono::steady_clock::duration::zero()) tim_ping_.cancel(); - if (base::connected()) { - base::async_disconnect(reason_code, force_move(props), force_move(func)); - } + return base::async_disconnect(token); } /** @@ -1566,15 +1701,22 @@ class client : public endpoint { /** * @brief Disconnect by endpoint - * @param func A callback function that is called when async operation will finish. + * @param token CompletionToken that is called when async operation will finish. * Force disconnect. It is not a clean disconnect sequence.
* When the endpoint disconnects using force_disconnect(), a will will send.
*/ - void async_force_disconnect( - async_handler_t func = async_handler_t()) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_force_disconnect( + CompletionToken&& token = async_handler_t{} + ) { if (ping_duration_ != std::chrono::steady_clock::duration::zero()) tim_ping_.cancel(); tim_close_.cancel(); - base::async_force_disconnect(force_move(func)); + return base::async_force_disconnect(token); } std::shared_ptr const& socket() const { @@ -1663,23 +1805,6 @@ class client : public endpoint { ); } - void async_start_session(v5::properties props, any session_life_keeper, async_handler_t func) { - base::async_read_control_packet_type(force_move(session_life_keeper)); - // sync base::connect() refer to parameters only in the function. - // So they can be passed as view. - base::async_connect( - buffer(string_view(base::get_client_id())), - ( user_name_ ? buffer(string_view(user_name_.value())) - : optional() ), - ( password_ ? buffer(string_view(password_.value())) - : optional() ), - will_, - keep_alive_sec_, - force_move(props), - force_move(func) - ); - } - template void handshake_socket( tcp_endpoint&, @@ -1771,113 +1896,6 @@ class client : public endpoint { #endif // defined(MQTT_USE_WS) -#endif // defined(MQTT_USE_TLS) - - template - void async_handshake_socket( - tcp_endpoint&, - v5::properties props, - any session_life_keeper, - async_handler_t func) { - async_start_session(force_move(props), force_move(session_life_keeper), force_move(func)); - } - -#if defined(MQTT_USE_WS) - template - void async_handshake_socket( - ws_endpoint& socket, - v5::properties props, - any session_life_keeper, - async_handler_t func) { - socket.async_handshake( - host_, - path_, - [ - this, - self = this->shared_from_this(), - session_life_keeper = force_move(session_life_keeper), - props = force_move(props), - func = force_move(func) - ] - (error_code ec) mutable { - if (ec) { - if (func) func(ec); - return; - } - async_start_session(force_move(props), force_move(session_life_keeper), force_move(func)); - }); - } -#endif // defined(MQTT_USE_WS) - -#if defined(MQTT_USE_TLS) - - template - void async_handshake_socket( - tcp_endpoint, Strand>& socket, - v5::properties props, - any session_life_keeper, - async_handler_t func) { - socket.async_handshake( - tls::stream_base::client, - [ - this, - self = this->shared_from_this(), - session_life_keeper = force_move(session_life_keeper), - props = force_move(props), - func = force_move(func) - ] - (error_code ec) mutable { - if (ec) { - if (func) func(ec); - return; - } - async_start_session(force_move(props), force_move(session_life_keeper), force_move(func)); - }); - } - -#if defined(MQTT_USE_WS) - template - void async_handshake_socket( - ws_endpoint, Strand>& socket, - v5::properties props, - any session_life_keeper, - async_handler_t func) { - socket.next_layer().async_handshake( - tls::stream_base::client, - [ - this, - self = this->shared_from_this(), - session_life_keeper = force_move(session_life_keeper), - &socket, - props = force_move(props), - func = force_move(func) - ] - (error_code ec) mutable { - if (ec) { - if (func) func(ec); - return; - } - socket.async_handshake( - host_, - path_, - [ - this, - self, - session_life_keeper = force_move(session_life_keeper), - props = force_move(props), - func = force_move(func) - ] - (error_code ec) mutable { - if (ec) { - if (func) func(ec); - return; - } - async_start_session(force_move(props), force_move(session_life_keeper), force_move(func)); - }); - }); - } -#endif // defined(MQTT_USE_WS) - #endif // defined(MQTT_USE_TLS) void connect_impl( @@ -1909,55 +1927,231 @@ class client : public endpoint { handshake_socket(*socket_, force_move(props), force_move(session_life_keeper), ec); } - void async_connect_impl( - v5::properties props, - any session_life_keeper, - async_handler_t func) { - auto r = std::make_shared(ioc_); - auto p = r.get(); - p->async_resolve( - host_, - port_, - [ - this, - self = this->shared_from_this(), - props = force_move(props), - session_life_keeper = force_move(session_life_keeper), - func = force_move(func), - r = force_move(r) - ] - ( - error_code ec, - as::ip::tcp::resolver::results_type eps - ) mutable { - if (ec) { - if (func) func(ec); - return; - } + template + auto base_async_connect(Params&&... params) { + return base::async_connect(std::forward(params)...); + } + + struct async_connect_impl { + this_type& cl; + v5::properties props = {}; + any session_life_keeper; + as::ip::tcp::resolver resolver{cl.ioc_}; + enum { + initiate, + resolve, + connect, +#if defined(MQTT_USE_TLS) + tls_handshake, +#if defined(MQTT_USE_WS) + tls_ws_handshake_tls, + tls_ws_handshake_ws, +#endif // defined(MQTT_USE_WS) +#endif // defined(MQTT_USE_TLS) + +#if defined(MQTT_USE_WS) + ws_handshake, +#endif // defined(MQTT_USE_WS) + start_session, + complete + } state = initiate; + + template + void operator()( + Self& self + ) { + BOOST_ASSERT(state == initiate); + state = resolve; + auto& a_cl{cl}; + auto& a_resolver{resolver}; + a_resolver.async_resolve( + a_cl.host_, + a_cl.port_, + force_move(self) + ); + } + + template + void operator()( + Self& self, + error_code ec + ) { + if (ec) { + self.complete(ec); + return; + } + switch (state) { +#if defined(MQTT_USE_WS) + case ws_handshake: + async_start_session(force_move(self)); + break; +#endif // defined(MQTT_USE_WS) +#if defined(MQTT_USE_TLS) + case tls_handshake: + async_start_session(force_move(self)); + break; +#if defined(MQTT_USE_WS) + case tls_ws_handshake_tls: { + state = tls_ws_handshake_ws; + auto& socket = *cl.socket_; + async_ws_handshake_socket( + socket, + force_move(self) + ); + } break; + case tls_ws_handshake_ws: + async_start_session(force_move(self)); + break; +#endif // defined(MQTT_USE_WS) +#endif // defined(MQTT_USE_TLS) + case start_session: + async_start_session(force_move(self)); + break; + case complete: + self.complete(ec); + break; + default: + BOOST_ASSERT(false); + break; + } + } + + template + void operator()( + Self& self, + error_code ec, + as::ip::tcp::resolver::results_type eps + ) { + BOOST_ASSERT(state == resolve); + if (ec) { + self.complete(ec); + } + else { + state = connect; + auto& a_cl{cl}; as::async_connect( - socket_->lowest_layer(), eps.begin(), eps.end(), - [ - this, - self = force_move(self), - props = force_move(props), - session_life_keeper = force_move(session_life_keeper), - func = force_move(func) - ] - (error_code ec, auto /* unused */) mutable { - if (ec) { - if (func) func(ec); - return; - } - base::set_connect(); - if (ping_duration_ != std::chrono::steady_clock::duration::zero()) { - set_timer(); - } - async_handshake_socket(*socket_, force_move(props), force_move(session_life_keeper), force_move(func)); - } + a_cl.socket_->lowest_layer(), eps.begin(), eps.end(), force_move(self) ); } - ); - } + } + + template + void operator()( + Self& self, + error_code ec, + Iterator + ) { + BOOST_ASSERT(state == connect); + if (ec) { + self.complete(ec); + } + else { + cl.set_connect(); + if (cl.ping_duration_ != std::chrono::steady_clock::duration::zero()) { + cl.set_timer(); + } + auto& socket = *cl.socket_; + async_handshake_socket( + socket, + force_move(self) + ); + } + } + + template + void async_handshake_socket( + tcp_endpoint&, + Self&& self) { + async_start_session(force_move(self)); + } + +#if defined(MQTT_USE_WS) + + template + void async_handshake_socket( + ws_endpoint& socket, + Self&& self) { + state = ws_handshake; + auto& a_cl{cl}; + socket.async_handshake( + a_cl.host_, + a_cl.path_, + force_move(self) + ); + } + +#endif // defined(MQTT_USE_WS) + +#if defined(MQTT_USE_TLS) + + template + void async_handshake_socket( + tcp_endpoint, Strand>& socket, + Self&& self) { + state = tls_handshake; + socket.async_handshake( + tls::stream_base::client, + force_move(self) + ); + } + +#if defined(MQTT_USE_WS) + + template + void async_handshake_socket( + ws_endpoint, Strand>& socket, + Self&& self) { + state = tls_ws_handshake_tls; + socket.next_layer().async_handshake( + tls::stream_base::client, + force_move(self) + ); + } + + template + void async_ws_handshake_socket( + ws_endpoint, Strand>& socket, + Self&& self) { + state = tls_ws_handshake_ws; + auto& a_cl{cl}; + socket.async_handshake( + a_cl.host_, + a_cl.path_, + force_move(self) + ); + } + + template + void async_ws_handshake_socket(Ignore&, Self&&) { + BOOST_ASSERT(false); + } + + +#endif // defined(MQTT_USE_WS) + +#endif // defined(MQTT_USE_TLS) + + template + void async_start_session(Self&& self) { + state = complete; + auto& a_cl{cl}; + auto a_props = force_move(props); + a_cl.async_read_control_packet_type(force_move(session_life_keeper)); + // sync base::connect() refer to parameters only in the function. + // So they can be passed as view. + a_cl.base_async_connect( + buffer(string_view(static_cast(a_cl).get_client_id())), + (a_cl.user_name_ ? buffer(string_view(a_cl.user_name_.value())) + : optional() ), + (a_cl.password_ ? buffer(string_view(a_cl.password_.value())) + : optional() ), + a_cl.will_, + a_cl.keep_alive_sec_, + force_move(a_props), + force_move(self) + ); + } + }; protected: void on_pre_send() noexcept override { diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 82271cc9c..efa185973 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -72,6 +72,7 @@ #include #include #include +#include #if defined(MQTT_USE_WS) #include @@ -787,7 +788,7 @@ class endpoint : public std::enable_shared_from_this - std::enable_if_t< ! std::is_convertible, packet_id_t>::value > - async_publish(T&& t, Params&&... params) { + template < + typename T, + typename... Params, + typename std::enable_if_t< + !std::is_convertible, packet_id_t>::value + >* = nullptr + > + auto async_publish(T&& t, Params&&... params) { if(detail::should_generate_packet_id(params...)) { packet_id_t packet_id = acquire_unique_packet_id(); - async_publish(packet_id, std::forward(t), std::forward(params)...); + return async_publish(packet_id, std::forward(t), std::forward(params)...); } else { - async_publish(0, std::forward(t), std::forward(params)...); + return async_publish(0, std::forward(t), std::forward(params)...); } } /** * @brief Disconnect - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * Send a disconnect packet to the connected broker. It is a clean disconnecting sequence. * The broker disconnects the endpoint after receives the disconnect packet.
* When the endpoint disconnects using disconnect(), a will won't send.
*/ - void async_disconnect( - async_handler_t func = {} + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_disconnect"; - - if (connected_ && mqtt_connected_) { - disconnect_requested_ = true; - // The reason code and property vector are only used if we're using mqttv5. - async_send_disconnect(v5::disconnect_reason_code::normal_disconnection, - v5::properties{}, - force_move(func)); - } - else { - socket_->post( - [func = force_move(func)] () mutable { - if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); - } + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_disconnect_impl{*this}, + token ); - } } /** @@ -2222,53 +2225,66 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901209
* 3.14.2.2 DISCONNECT Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * Send a disconnect packet to the connected broker. It is a clean disconnecting sequence. * The broker disconnects the endpoint after receives the disconnect packet.
* When the endpoint disconnects using disconnect(), a will won't send.
*/ - void async_disconnect( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_disconnect( v5::disconnect_reason_code reason, v5::properties props = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_disconnect" << " reason:" << reason; - if (connected_ && mqtt_connected_) { - disconnect_requested_ = true; - async_send_disconnect(reason, force_move(props), force_move(func)); - } - else { - socket_->post( - [func = force_move(func)] () mutable { - if (func) func(boost::system::errc::make_error_code(boost::system::errc::success)); - } + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_disconnect_impl{*this, reason, force_move(props)}, + token ); - } } /** * @brief Disconnect by endpoint - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * Force disconnect. It is not a clean disconnect sequence.
* When the endpoint disconnects using force_disconnect(), a will will send.
*/ - void async_force_disconnect( - async_handler_t func = {} + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_force_disconnect( + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_force_disconnect"; - socket_->post( - [this, self = this->shared_from_this(), func = force_move(func)] () mutable { - async_shutdown(socket(), force_move(func)); - } - ); + + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_force_disconnect_impl{*this}, + token + ); } // packet_id manual setting version @@ -2281,34 +2297,44 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * packet_id is automatically generated.
* You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - template - std::enable_if_t< ! std::is_convertible, packet_id_t>::value > - async_subscribe(T&& t, Params&&... params) { + template < + typename T, + typename... Params, + typename std::enable_if_t< + !std::is_convertible, packet_id_t>::value + >* = nullptr + > + auto async_subscribe(T&& t, Params&&... params) { packet_id_t packet_id = acquire_unique_packet_id(); - async_subscribe(packet_id, std::forward(t), std::forward(params)...); + return async_subscribe(packet_id, std::forward(t), std::forward(params)...); } /** * @brief Unsubscribe * @param topic_name * A topic name to unsubscribe - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * packet_id is automatically generated.
* You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - template - std::enable_if_t< ! std::is_convertible, packet_id_t>::value > - async_unsubscribe(T&& t, Params&&... params) { + template < + typename T, + typename... Params, + typename std::enable_if_t< + !std::is_convertible, packet_id_t>::value + >* = nullptr + > + auto async_unsubscribe(T&& t, Params&&... params) { packet_id_t packet_id = acquire_unique_packet_id(); - async_unsubscribe(packet_id, std::forward(t), std::forward(params)...); + return async_unsubscribe(packet_id, std::forward(t), std::forward(params)...); } /** @@ -2323,15 +2349,21 @@ class endpoint : public std::enable_shared_from_this::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, std::string topic_name, std::string contents, publish_options pubopts = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2349,15 +2381,22 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name_buf, + contents_buf, + pubopts, + v5::properties{}, + std::make_pair(force_move(sp_topic_name), force_move(sp_contents)) + ), + token + ); } /** @@ -2380,21 +2419,27 @@ class endpoint : public std::enable_shared_from_this::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, std::string topic_name, std::string contents, publish_options pubopts, v5::properties props, any life_keeper = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2412,19 +2457,26 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name_buf, + contents_buf, + pubopts, + force_move(props), + std::make_tuple( + force_move(life_keeper), + force_move(sp_topic_name), + force_move(sp_contents) + ) + ), + token + ); } /** @@ -2443,24 +2495,28 @@ class endpoint : public std::enable_shared_from_this - typename std::enable_if< - as::is_const_buffer_sequence::value - >::type - async_publish( + template < + typename ConstBufferSequence, + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + as::is_const_buffer_sequence::value && + is_invocable::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, as::const_buffer topic_name, ConstBufferSequence contents, publish_options pubopts = {}, any life_keeper = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2473,15 +2529,22 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name, + force_move(contents), + pubopts, + v5::properties{}, + force_move(life_keeper) + ), + token + ); } /** @@ -2504,21 +2567,25 @@ class endpoint : public std::enable_shared_from_this - typename std::enable_if< - as::is_const_buffer_sequence::value - >::type - async_publish( + * @param token + * CompletionToken will be called when the async operation completes. + */ + template < + typename ConstBufferSequence, + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + as::is_const_buffer_sequence::value && + is_invocable::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, as::const_buffer topic_name, ConstBufferSequence contents, publish_options pubopts, v5::properties props, any life_keeper = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2531,15 +2598,22 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name, + force_move(contents), + pubopts, + force_move(props), + force_move(life_keeper) + ), + token + ); } /** @@ -2558,20 +2632,24 @@ class endpoint : public std::enable_shared_from_this - typename std::enable_if< - is_buffer_sequence::value - >::type - async_publish( + * @param token + * CompletionToken will be called when the async operation completes. + */ + template < + typename BufferSequence, + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_buffer_sequence::value && + is_invocable::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, buffer topic_name, BufferSequence contents, publish_options pubopts = {}, any life_keeper = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2596,19 +2674,26 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name_buf, + force_move(cbs), + pubopts, + v5::properties{}, + std::make_tuple( + force_move(life_keeper), + force_move(topic_name), + force_move(contents) + ) + ), + token + ); } /** @@ -2631,25 +2716,29 @@ class endpoint : public std::enable_shared_from_this - typename std::enable_if< - is_buffer_sequence::value - >::type - async_publish( + template < + typename BufferSequence, + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_buffer_sequence::value && + is_invocable::value + >* = nullptr + > + auto async_publish( packet_id_t packet_id, buffer topic_name, BufferSequence contents, publish_options pubopts, v5::properties props, any life_keeper = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -2674,20 +2763,28 @@ class endpoint : public std::enable_shared_from_this( + make_async_publish_impl( + *this, + packet_id, + topic_name_buf, + force_move(cbs), + pubopts, + force_move(props), + std::make_tuple( + force_move(life_keeper), + force_move(topic_name), + force_move(contents) + ) + ), + token + ); } + /** * @brief Subscribe * @param packet_id @@ -2703,16 +2800,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::string topic_filter, subscribe_options option, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2727,15 +2830,20 @@ class endpoint : public std::enable_shared_from_this(force_move(topic_filter)); auto topic_filter_buf = as::buffer(*sp_topic_filter); - async_send_subscribe( - std::vector>{ { topic_filter_buf, option } }, - packet_id, - v5::properties{}, - [life_keeper = force_move(sp_topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter_buf, option } }, + packet_id, + v5::properties{}, + force_move(sp_topic_filter) + }, + token + ); } /** @@ -2753,17 +2861,23 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::string topic_filter, subscribe_options option, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2778,15 +2892,20 @@ class endpoint : public std::enable_shared_from_this(force_move(topic_filter)); auto topic_filter_buf = as::buffer(*sp_topic_filter); - async_send_subscribe( - std::vector>{ { topic_filter_buf, option } }, - packet_id, - force_move(props), - [life_keeper = force_move(sp_topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter_buf, option } }, + packet_id, + force_move(props), + force_move(sp_topic_filter) + }, + token + ); } /** @@ -2800,17 +2919,23 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * This object should hold the lifetime of the buffers for topic_filter. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, as::const_buffer topic_filter, subscribe_options option, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2822,12 +2947,19 @@ class endpoint : public std::enable_shared_from_this>{ { topic_filter, option } }, - packet_id, - v5::properties{}, - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter, option } }, + packet_id, + v5::properties{} + }, + token + ); } /** @@ -2845,18 +2977,24 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * This object should hold the lifetime of the buffers for topic_filter, and properties. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, as::const_buffer topic_filter, subscribe_options option, v5::properties props, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2868,12 +3006,19 @@ class endpoint : public std::enable_shared_from_this>{ { topic_filter, option } }, - packet_id, - force_move(props), - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter, option } }, + packet_id, + force_move(props) + }, + token + ); } /** @@ -2887,16 +3032,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, buffer topic_filter, subscribe_options option, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2909,15 +3060,20 @@ class endpoint : public std::enable_shared_from_this>{ { topic_filter_buf, option } }, - packet_id, - v5::properties{}, - [life_keeper = force_move(topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter_buf, option } }, + packet_id, + v5::properties{}, + force_move(topic_filter) + }, + token + ); } /** @@ -2935,17 +3091,23 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, buffer topic_filter, subscribe_options option, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -2958,15 +3120,20 @@ class endpoint : public std::enable_shared_from_this>{ { topic_filter_buf, option } }, - packet_id, - force_move(props), - [life_keeper = force_move(topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + std::vector>{ { topic_filter_buf, option } }, + packet_id, + force_move(props), + force_move(topic_filter) + }, + token + ); } /** @@ -2978,15 +3145,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3005,15 +3178,20 @@ class endpoint : public std::enable_shared_from_this( + async_subscribe_impl{ + *this, + force_move(cb_params), + packet_id, + v5::properties{}, + force_move(life_keepers) + }, + token + ); } /** @@ -3029,16 +3207,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901164
* 3.8.2.1 SUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3056,15 +3240,20 @@ class endpoint : public std::enable_shared_from_this(e)); life_keepers.emplace_back(force_move(sp_topic_filter)); } - async_send_subscribe( - force_move(cb_params), - packet_id, - force_move(props), - [life_keeper = force_move(life_keepers), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + force_move(cb_params), + packet_id, + force_move(props), + force_move(life_keepers) + }, + token + ); } /** @@ -3073,28 +3262,41 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_subscribe" << " pid:" << packet_id; - async_send_subscribe( - force_move(params), - packet_id, - v5::properties{}, - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + force_move(params), + packet_id, + v5::properties{} + }, + token + ); } /** @@ -3106,29 +3308,42 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * This object should hold the lifetime of the buffers for params. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, v5::properties props, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_subscribe" << " pid:" << packet_id; - async_send_subscribe( - force_move(params), - packet_id, - force_move(props), - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_subscribe_impl{ + *this, + force_move(params), + packet_id, + force_move(props) + }, + token + ); } /** @@ -3137,15 +3352,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3162,15 +3383,20 @@ class endpoint : public std::enable_shared_from_this( + async_subscribe_impl{ + *this, + force_move(cb_params), + packet_id, + v5::properties{}, + force_move(params) + }, + token + ); } /** @@ -3182,16 +3408,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169
* 3.8.3.1 Subscription Options - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_subscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_subscribe( packet_id_t packet_id, std::vector> params, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3208,15 +3440,20 @@ class endpoint : public std::enable_shared_from_this( + async_subscribe_impl{ + *this, + force_move(cb_params), + packet_id, + force_move(props), + force_move(params) + }, + token + ); } /** @@ -3225,15 +3462,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::string topic_filter, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3243,15 +3486,21 @@ class endpoint : public std::enable_shared_from_this(force_move(topic_filter)); auto topic_filter_buf = as::buffer(*sp_topic_filter); - async_send_unsubscribe( - std::vector{ topic_filter_buf }, - packet_id, - v5::properties{}, - [life_keeper = force_move(sp_topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - } - ); + + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + std::vector{ topic_filter_buf }, + packet_id, + v5::properties{}, + force_move(sp_topic_filter) + }, + token + ); } /** @@ -3260,16 +3509,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, as::const_buffer topic_filter, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3277,7 +3532,19 @@ class endpoint : public std::enable_shared_from_this{ topic_filter }, packet_id, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + std::vector{ topic_filter }, + packet_id, + v5::properties{} + }, + token + ); } /** @@ -3286,15 +3553,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, buffer topic_filter, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3303,13 +3576,21 @@ class endpoint : public std::enable_shared_from_this{ topic_filter_buf }, - packet_id, - v5::properties{}, - [life_keeper = force_move(topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - }); + + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + std::vector{ topic_filter_buf }, + packet_id, + v5::properties{}, + force_move(topic_filter) + }, + token + ); } /** @@ -3322,16 +3603,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, buffer topic_filter, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3340,13 +3627,21 @@ class endpoint : public std::enable_shared_from_this{ topic_filter_buf }, - packet_id, - force_move(props), - [life_keeper = force_move(topic_filter), func = force_move(func)] - (error_code ec) mutable { - if(func) func(ec); - }); + + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + std::vector{ topic_filter_buf }, + packet_id, + force_move(props), + force_move(topic_filter) + }, + token + ); } /** @@ -3356,15 +3651,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3382,15 +3683,20 @@ class endpoint : public std::enable_shared_from_this( + async_unsubscribe_impl{ + *this, + force_move(cb_params), + packet_id, + v5::properties{}, + force_move(life_keepers) + }, + token + ); } /** @@ -3404,16 +3710,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3436,15 +3748,20 @@ class endpoint : public std::enable_shared_from_this( + async_unsubscribe_impl{ + *this, + force_move(cb_params), + packet_id, + force_move(props), + force_move(life_keepers) + }, + token + ); } /** @@ -3454,28 +3771,41 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_unsubscribe" << " pid:" << packet_id; - async_send_unsubscribe( - force_move(params), - packet_id, - v5::properties{}, - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + force_move(params), + packet_id, + v5::properties{} + }, + token + ); } /** @@ -3485,33 +3815,42 @@ class endpoint : public std::enable_shared_from_this - * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
- * 3.10.2.1 UNSUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. - * This object should hold the lifetime of the buffers for params. + * @param token + * CompletionToken will be called when the async operation completes. + * This object may hold the lifetime of the buffers for topic_filter and contents. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, v5::properties props, - async_handler_t func + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_unsubscribe" << " pid:" << packet_id; - async_send_unsubscribe( - force_move(params), - packet_id, - force_move(props), - force_move(func) - ); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsubscribe_impl{ + *this, + force_move(params), + packet_id, + force_move(props) + }, + token + ); } /** @@ -3521,15 +3860,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3542,15 +3887,20 @@ class endpoint : public std::enable_shared_from_this( + async_unsubscribe_impl{ + *this, + force_move(cb_params), + packet_id, + v5::properties{}, + force_move(params) + }, + token + ); } /** @@ -3564,16 +3914,22 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901182
* 3.10.2.1 UNSUBSCRIBE Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * You can subscribe multiple topics all at once.
* See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 */ - void async_unsubscribe( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsubscribe( packet_id_t packet_id, std::vector params, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3586,43 +3942,82 @@ class endpoint : public std::enable_shared_from_this( + async_unsubscribe_impl{ + *this, + force_move(cb_params), + packet_id, + force_move(props), + force_move(params) + }, + token + ); } /** * @brief Send pingreq packet. - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901195 */ - void async_pingreq(async_handler_t func = {}) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pingreq( + CompletionToken&& token = async_handler_t{} + ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_pingreq"; - if (connected_ && mqtt_connected_) async_send_pingreq(force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pingreq_impl{ + *this + }, + token + ); } /** * @brief Send pingresp packet. This function is for broker. - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901200 */ - void async_pingresp(async_handler_t func = {}) { + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pingresp( + CompletionToken&& token = async_handler_t{} + ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_pingrsp"; - async_send_pingresp(force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pingresp_impl{ + *this + }, + token + ); } /** @@ -3635,21 +4030,38 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901221
* 3.15.2.2 AUTH Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718086 */ - void async_auth( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_auth( v5::auth_reason_code reason_code = v5::auth_reason_code::success, v5::properties props = {}, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_auth" << " reason:" << reason_code; - async_send_auth(reason_code, force_move(props), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_auth_impl{ + *this, + reason_code, + force_move(props) + }, + token + ); } /** @@ -3671,26 +4083,32 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045
* 3.1.2.10 Keep Alive - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718028 */ - void async_connect( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect( buffer client_id, optional user_name, optional password, optional w, std::uint16_t keep_alive_sec, - async_handler_t func = {} + CompletionToken&& token = [](error_code){} ) { - async_connect( + return async_connect( force_move(client_id), force_move(user_name), force_move(password), force_move(w), keep_alive_sec, v5::properties{}, - force_move(func)); + token); } /** @@ -3716,18 +4134,24 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901046
* 3.1.2.11 CONNECT Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718028 */ - void async_connect( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connect( buffer client_id, optional user_name, optional password, optional w, std::uint16_t keep_alive_sec, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3735,30 +4159,42 @@ class endpoint : public std::enable_shared_from_this( + async_connect_impl{ + *this, + force_move(client_id), + force_move(user_name), + force_move(password), + force_move(w), + keep_alive_sec, + force_move(props) + }, + token + ); } /** * @brief Send connack packet. This function is for broker. * @param session_present See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349255 * @param return_code See connect_return_code.hpp and https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc385349256 - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718033 */ - void async_connack( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connack( bool session_present, variant reason_code, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3766,7 +4202,19 @@ class endpoint : public std::enable_shared_from_this( + async_connack_impl{ + *this, + session_present, + reason_code, + v5::properties{} + }, + token + ); } /** @@ -3777,15 +4225,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080
* 3.2.2.3 CONNACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718033 */ - void async_connack( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_connack( bool session_present, variant reason_code, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -3793,26 +4247,54 @@ class endpoint : public std::enable_shared_from_this( + async_connack_impl{ + *this, + session_present, + reason_code, + force_move(props) + }, + token + ); } /** * @brief Send puback packet. * @param packet_id packet id corresponding to publish - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_puback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_puback( packet_id_t packet_id, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_puback" << " pid:" << packet_id; - async_send_puback(packet_id, v5::puback_reason_code::success, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_puback_impl{ + *this, + packet_id + }, + token + ); } /** @@ -3826,15 +4308,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901125
* 3.4.2.2 PUBACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_puback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_puback( packet_id_t packet_id, v5::puback_reason_code reason_code, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -3842,26 +4330,54 @@ class endpoint : public std::enable_shared_from_this( + async_puback_impl{ + *this, + packet_id, + reason_code, + force_move(props) + }, + token + ); } /** * @brief Send pubrec packet. * @param packet_id packet id corresponding to publish - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_pubrec( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pubrec( packet_id_t packet_id, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_pubrec" << " pid:" << packet_id; - async_send_pubrec(packet_id, v5::pubrec_reason_code::success, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pubrec_impl{ + *this, + packet_id + }, + token + ); } /** @@ -3875,15 +4391,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901135
* 3.5.2.2 PUBREC Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_pubrec( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pubrec( packet_id_t packet_id, v5::pubrec_reason_code reason_code, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -3891,26 +4413,54 @@ class endpoint : public std::enable_shared_from_this( + async_pubrec_impl{ + *this, + packet_id, + reason_code, + force_move(props) + }, + token + ); } /** * @brief Send pubrel packet. * @param packet_id packet id corresponding to publish - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_pubrel( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pubrel( packet_id_t packet_id, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_pubrel" << " pid:" << packet_id; - async_send_pubrel(packet_id, v5::pubrel_reason_code::success, v5::properties{}, any(), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pubrel_impl{ + *this, + packet_id + }, + token + ); } /** @@ -3924,22 +4474,24 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 * * @note The library may store this message while it communicates with the server for several round trips. * As such, the life_keeper paramter is important. */ - template - std::enable_if_t< - std::is_convertible::value + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr > - async_pubrel( + auto async_pubrel( packet_id_t packet_id, v5::pubrel_reason_code reason_code, v5::properties props = {}, - Func&& func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -3947,7 +4499,19 @@ class endpoint : public std::enable_shared_from_this(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pubrel_impl{ + *this, + packet_id, + reason_code, + force_move(props) + }, + token + ); } /** @@ -3961,8 +4525,8 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901145
* 3.6.2.2 PUBREL Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 * * @param life_keeper @@ -3973,12 +4537,18 @@ class endpoint : public std::enable_shared_from_this::value + >* = nullptr + > + auto async_pubrel( packet_id_t packet_id, v5::pubrel_reason_code reason_code, - v5::properties props = {}, - any life_keeper = {}, - async_handler_t func = {} + v5::properties props, + any life_keeper, + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -3986,26 +4556,55 @@ class endpoint : public std::enable_shared_from_this( + async_pubrel_impl{ + *this, + packet_id, + reason_code, + force_move(props), + force_move(life_keeper) + }, + token + ); } /** * @brief Send pubcomp packet. * @param packet_id packet id corresponding to publish - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_pubcomp( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pubcomp( packet_id_t packet_id, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) << "async_pubcomp" << " pid:" << packet_id; - async_send_pubcomp(packet_id, v5::pubcomp_reason_code::success, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_pubcomp_impl{ + *this, + packet_id + }, + token + ); } /** @@ -4019,15 +4618,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901155
* 3.7.2.2 PUBCOMP Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken 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 */ - void async_pubcomp( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_pubcomp( packet_id_t packet_id, v5::pubcomp_reason_code reason_code, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", trace) << MQTT_ADD_VALUE(address, this) @@ -4035,7 +4640,19 @@ class endpoint : public std::enable_shared_from_this( + async_pubcomp_impl{ + *this, + packet_id, + reason_code, + force_move(props) + }, + token + ); } /** @@ -4045,14 +4662,20 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178
* 3.9.3 SUBACK Payload - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_suback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_suback( packet_id_t packet_id, variant reason, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -4061,10 +4684,34 @@ class endpoint : public std::enable_shared_from_this{ variant_get(reason) }, packet_id, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + std::vector{ variant_get(reason) }, + v5::properties{} + }, + token + ); } else { - async_send_suback(std::vector{ variant_get(reason) }, packet_id, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + std::vector{ variant_get(reason) }, + v5::properties{} + }, + token + ); } } @@ -4079,15 +4726,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_suback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_suback( packet_id_t packet_id, variant reason, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -4096,10 +4749,34 @@ class endpoint : public std::enable_shared_from_this{ variant_get(reason) }, packet_id, force_move(props), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + std::vector{ variant_get(reason) }, + force_move(props) + }, + token + ); } else { - async_send_suback(std::vector{ variant_get(reason) }, packet_id, force_move(props), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + std::vector{ variant_get(reason) }, + force_move(props) + }, + token + ); } } @@ -4110,21 +4787,39 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178
* 3.9.3 SUBACK Payload - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_suback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_suback( packet_id_t packet_id, variant, std::vector> reasons, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_suback" << " pid:" << packet_id; - async_send_suback(force_move(reasons), packet_id, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + force_move(reasons), + v5::properties{} + }, + token + ); } /** @@ -4138,22 +4833,40 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901174
* 3.9.2.1 SUBACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_suback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_suback( packet_id_t packet_id, variant, std::vector> reasons, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_suback" << " pid:" << packet_id; - async_send_suback(force_move(reasons), packet_id, force_move(props), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_suback_impl{ + *this, + packet_id, + force_move(reasons), + force_move(props) + }, + token + ); } /** @@ -4163,14 +4876,20 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194
* 3.11.3 UNSUBACK Payload - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_unsuback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsuback( packet_id_t packet_id, v5::unsuback_reason_code reason, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -4178,7 +4897,18 @@ class endpoint : public std::enable_shared_from_this{ reason }, packet_id, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsuback_impl{ + *this, + packet_id, + std::vector{ reason } + }, + token + ); } /** @@ -4192,15 +4922,21 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_unsuback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsuback( packet_id_t packet_id, v5::unsuback_reason_code reason, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) @@ -4208,7 +4944,19 @@ class endpoint : public std::enable_shared_from_this{ reason }, packet_id, force_move(props), force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsuback_impl{ + *this, + packet_id, + std::vector{ reason }, + force_move(props) + }, + token + ); } /** @@ -4218,21 +4966,38 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194
* 3.11.3 UNSUBACK Payload - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_unsuback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsuback( packet_id_t packet_id, std::vector reasons, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_unsuback" << " pid:" << packet_id; - async_send_unsuback(force_move(reasons), packet_id, v5::properties{}, force_move(func)); + return + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsuback_impl{ + *this, + packet_id, + force_move(reasons) + }, + token + ); } /** @@ -4246,42 +5011,74 @@ class endpoint : public std::enable_shared_from_this * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901190
* 3.11.2.1 UNSUBACK Properties - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718068 */ - void async_unsuback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsuback( packet_id_t packet_id, std::vector reasons, v5::properties props, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_unsuback" << " pid:" << packet_id; - async_send_unsuback(force_move(reasons), packet_id, force_move(props), force_move(func)); + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsuback_impl{ + *this, + packet_id, + force_move(reasons), + force_move(props) + }, + token + ); } /** * @brief Send ununsuback packet. This function is for broker. * @param packet_id * packet id corresponding to unsubscribe - * @param func - * functor object who's operator() will be called when the async operation completes. + * @param token + * CompletionToken will be called when the async operation completes. * See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc398718077 */ - void async_unsuback( + template < + typename CompletionToken = async_handler_t, + typename std::enable_if_t< + is_invocable::value + >* = nullptr + > + auto async_unsuback( packet_id_t packet_id, - async_handler_t func = {} + CompletionToken&& token = async_handler_t{} ) { MQTT_LOG("mqtt_api", info) << MQTT_ADD_VALUE(address, this) << "async_unsuback" << " pid:" << packet_id; - async_send_unsuback(packet_id, force_move(func)); + as::async_compose< + CompletionToken, + void(error_code) + >( + async_unsuback_impl{ + *this, + packet_id + }, + token + ); } /** @@ -10385,6 +11182,50 @@ class endpoint : public std::enable_shared_from_this user_name; + optional password; + optional w; + std::uint16_t keep_alive_sec; + v5::properties props; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + ep.connect_requested_ = true; + auto a_client_id{force_move(client_id)}; + auto a_user_name{force_move(user_name)}; + auto a_password{force_move(password)}; + auto a_w{force_move(w)}; + auto a_keep_alive_sec{keep_alive_sec}; + auto a_props{force_move(props)}; + ep.async_send_connect( + force_move(a_client_id), + force_move(a_user_name), + force_move(a_password), + force_move(a_w), + a_keep_alive_sec, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + + void async_send_connect( buffer client_id, optional user_name, @@ -10430,6 +11271,38 @@ class endpoint : public std::enable_shared_from_this reason; + v5::properties props = {}; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_session_present{session_present}; + auto a_reason{reason}; + auto a_props{force_move(props)}; + ep.async_send_connack( + a_session_present, + a_reason, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_connack( bool session_present, variant reason_code, @@ -10481,6 +11354,74 @@ class endpoint : public std::enable_shared_from_this + struct async_publish_impl { + this_type& ep; + packet_id_t packet_id; + as::const_buffer topic_name; + ConstBufferSequence payloads; + publish_options pubopts; + v5::properties props; + any life_keeper; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_topic_name{topic_name}; + auto a_payloads{force_move(payloads)}; + auto a_pubopts{pubopts}; + auto a_props{force_move(props)}; + auto a_life_keeper{force_move(life_keeper)}; + ep.async_send_publish( + a_packet_id, + a_topic_name, + force_move(a_payloads), + a_pubopts, + force_move(a_props), + force_move(a_life_keeper), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + + template + typename std::enable_if< + as::is_const_buffer_sequence::value, + async_publish_impl + >::type + make_async_publish_impl( + this_type& ep, + packet_id_t packet_id, + as::const_buffer topic_name, + ConstBufferSequence payloads, + publish_options pubopts, + v5::properties props, + any life_keeper + ) { + return + async_publish_impl{ + ep, + packet_id, + topic_name, + force_move(payloads), + pubopts, + force_move(props), + force_move(life_keeper), + }; + } + template typename std::enable_if< as::is_const_buffer_sequence::value @@ -10583,6 +11524,38 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_reason{reason}; + auto a_props{force_move(props)}; + ep.async_send_puback( + a_packet_id, + a_reason, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_puback( packet_id_t packet_id, v5::puback_reason_code reason, @@ -10635,6 +11608,38 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_reason{reason}; + auto a_props{force_move(props)}; + ep.async_send_pubrec( + a_packet_id, + a_reason, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_pubrec( packet_id_t packet_id, v5::pubrec_reason_code reason, @@ -10682,6 +11687,41 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_reason{reason}; + auto a_props{force_move(props)}; + auto a_life_keeper{force_move(life_keeper)}; + ep.async_send_pubrel( + a_packet_id, + a_reason, + force_move(a_props), + force_move(a_life_keeper), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_pubrel( packet_id_t packet_id, v5::pubrel_reason_code reason, @@ -10762,6 +11802,38 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_reason{reason}; + auto a_props{force_move(props)}; + ep.async_send_pubcomp( + a_packet_id, + a_reason, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_pubcomp( packet_id_t packet_id, v5::pubcomp_reason_code reason, @@ -10813,6 +11885,40 @@ class endpoint : public std::enable_shared_from_this> params; + packet_id_t packet_id; + v5::properties props; + any life_keeper = any{}; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + // these are moved before self is moved + auto a_params{force_move(params)}; + auto a_packet_id{packet_id}; + auto a_props{force_move(props)}; + ep.async_send_subscribe( + force_move(a_params), + a_packet_id, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_subscribe( std::vector> params, packet_id_t packet_id, @@ -10872,6 +11978,38 @@ class endpoint : public std::enable_shared_from_this, std::vector> params; + v5::properties props = {}; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_packet_id{packet_id}; + auto a_params{force_move(params)}; + auto a_props{force_move(props)}; + ep.async_send_suback( + force_move(a_params), + a_packet_id, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_suback( variant, std::vector> params, packet_id_t packet_id, @@ -10922,6 +12060,39 @@ class endpoint : public std::enable_shared_from_this params; + packet_id_t packet_id; + v5::properties props = v5::properties{}; + any life_keeper = any{}; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_params{force_move(params)}; + auto a_packet_id{packet_id}; + auto a_props{force_move(props)}; + ep.async_send_unsubscribe( + force_move(a_params), + a_packet_id, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_unsubscribe( std::vector params, packet_id_t packet_id, @@ -10981,33 +12152,70 @@ class endpoint : public std::enable_shared_from_this params = {}; + v5::properties props = {}; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + switch (ep.version_) { + case protocol_version::v3_1_1: { + auto a_packet_id{packet_id}; + ep.async_send_unsuback( + a_packet_id, + force_move(self) + ); + } break; + case protocol_version::v5: { + auto a_packet_id{packet_id}; + auto a_params{force_move(params)}; + auto a_props{force_move(props)}; + ep.async_send_unsuback( + force_move(a_params), + a_packet_id, + force_move(a_props), + force_move(self) + ); + } break; + default: + BOOST_ASSERT(false); + break; + } + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_unsuback( packet_id_t packet_id, async_handler_t func ) { - switch (version_) { - case protocol_version::v3_1_1: { - auto msg = v3_1_1::basic_unsuback_message(packet_id); - if (maximum_packet_size_send_ < size(msg)) { - socket_->post( - [func = force_move(func)] () mutable { - if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); - } - ); - return; - } - do_async_write( - force_move(msg), - force_move(func) + BOOST_ASSERT(version_ == protocol_version::v3_1_1); + auto msg = v3_1_1::basic_unsuback_message(packet_id); + if (maximum_packet_size_send_ < size(msg)) { + socket_->post( + [func = force_move(func)] () mutable { + if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); + } ); - } break; - case protocol_version::v5: - BOOST_ASSERT(false); - break; - default: - BOOST_ASSERT(false); - break; + return; } + do_async_write( + force_move(msg), + force_move(func) + ); } void async_send_unsuback( @@ -11016,31 +12224,48 @@ class endpoint : public std::enable_shared_from_this(force_move(params), packet_id, force_move(props)); - if (maximum_packet_size_send_ < size(msg)) { - socket_->post( - [func = force_move(func)] () mutable { - if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); - } - ); - return; - } - do_async_write( - force_move(msg), - force_move(func) + BOOST_ASSERT(version_ == protocol_version::v5); + auto msg = v5::basic_unsuback_message(force_move(params), packet_id, force_move(props)); + if (maximum_packet_size_send_ < size(msg)) { + socket_->post( + [func = force_move(func)] () mutable { + if (func) func(boost::system::errc::make_error_code(boost::system::errc::message_size)); + } ); - } break; - default: - BOOST_ASSERT(false); - break; + return; } + do_async_write( + force_move(msg), + force_move(func) + ); } + struct async_pingreq_impl { + this_type& ep; + enum { initiate, complete } state = initiate; + + template + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: + state = complete; + if (ep.connected_ && ep.mqtt_connected_) { + ep.async_send_pingreq(force_move(self)); + } + else { + ep.socket_->post(force_move(self)); + } + break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_pingreq(async_handler_t func) { switch (version_) { case protocol_version::v3_1_1: { @@ -11075,6 +12300,27 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: + state = complete; + ep.async_send_pingresp(force_move(self)); + break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_pingresp(async_handler_t func) { switch (version_) { case protocol_version::v3_1_1: { @@ -11107,6 +12353,31 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + auto a_reason{reason}; + auto a_props{force_move(props)}; + ep.async_send_auth(a_reason, force_move(a_props), force_move(self)); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_auth( v5::auth_reason_code reason, v5::properties props, @@ -11134,6 +12405,37 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: { + state = complete; + ep.disconnect_requested_ = true; + auto a_reason{reason}; + auto a_props{force_move(props)}; + // The reason code and property vector are only used if we're using mqttv5. + ep.async_send_disconnect( + a_reason, + force_move(a_props), + force_move(self) + ); + } break; + case complete: + self.complete(ec); + break; + } + } + }; + void async_send_disconnect( v5::disconnect_reason_code reason, v5::properties props, @@ -11170,6 +12472,33 @@ class endpoint : public std::enable_shared_from_this + void operator()( + Self& self, + error_code ec = error_code{} + ) { + switch (state) { + case initiate: + state = shutdown; + ep.socket_->post(force_move(self)); + break; + case shutdown: + state = complete; + ep.async_shutdown(ep.socket(), force_move(self)); + break; + case complete: + self.complete(ec); + sp.reset(); + break; + } + } + }; + template void async_send_store(Func&& func) { // packet_id has already been registered diff --git a/include/mqtt/is_invocable.hpp b/include/mqtt/is_invocable.hpp new file mode 100644 index 000000000..9147c2d69 --- /dev/null +++ b/include/mqtt/is_invocable.hpp @@ -0,0 +1,39 @@ +// Copyright Takatoshi Kondo 2022 +// +// 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_IS_INVOCABLE_HPP) +#define MQTT_IS_INVOCABLE_HPP + +#include +#include + +#if __cplusplus >= 201703L + +namespace MQTT_NS { + +template +using is_invocable = typename std::is_invocable; + +} // namespace MQTT_NS + +#else // __cplusplus >= 201703L + +#include + +namespace MQTT_NS { + +template +struct is_invocable : std::is_constructible< + move_only_function, + std::reference_wrapper::type> +> +{}; + +} // namespace MQTT_NS + +#endif // __cplusplus >= 201703L + +#endif // MQTT_IS_INVOCABLE_HPP diff --git a/include/mqtt/move_only_function.hpp b/include/mqtt/move_only_function.hpp index 08b0513bb..8cd6f1a70 100644 --- a/include/mqtt/move_only_function.hpp +++ b/include/mqtt/move_only_function.hpp @@ -7,8 +7,8 @@ #if !defined(MQTT_MOVE_ONLY_FUNCTION_HPP) #define MQTT_MOVE_ONLY_FUNCTION_HPP -#pragma GCC diagnostic push #if defined(__GNUC__) +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Waddress" #endif // defined(__GNUC__) diff --git a/include/mqtt/move_only_handler.hpp b/include/mqtt/move_only_handler.hpp index 03e041bd4..0767dd73e 100644 --- a/include/mqtt/move_only_handler.hpp +++ b/include/mqtt/move_only_handler.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace MQTT_NS { @@ -29,7 +30,8 @@ struct move_only_handler { template < typename Func, typename std::enable_if_t< - std::is_convertible>::value + std::is_convertible>::value && + std::is_constructible(std::declval()))>::value >* = nullptr > move_only_handler(Func&& f) @@ -38,10 +40,23 @@ struct move_only_handler { { } + template < + typename Func, + typename std::enable_if_t< + std::is_convertible>::value && + !std::is_constructible(std::declval()))>::value + >* = nullptr + > + move_only_handler(Func&& f) + : func_{std::forward(f)} + { + } + executor_type get_executor() const { return exe_; } template void operator()(Params&&... params) { + if (!func_) return; if (exe_ == as::system_executor()) { func_(std::forward(params)...); return; @@ -57,7 +72,7 @@ struct move_only_handler { operator bool() const { return static_cast(func_); } private: - executor_type exe_; + executor_type exe_ = as::system_executor(); move_only_function func_; }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b2424d850..dddd8ae78 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,6 +13,7 @@ OPTION(MQTT_TEST_4 "Build test part4" ON) OPTION(MQTT_TEST_5 "Build test part5" ON) OPTION(MQTT_TEST_6 "Build test part6" ON) OPTION(MQTT_TEST_7 "Build test part7" ON) +OPTION(MQTT_TEST_8 "Build test part8" ON) ADD_SUBDIRECTORY (system) ADD_SUBDIRECTORY (unit) diff --git a/test/system/CMakeLists.txt b/test/system/CMakeLists.txt index 3196c764c..427fd1e00 100644 --- a/test/system/CMakeLists.txt +++ b/test/system/CMakeLists.txt @@ -12,7 +12,8 @@ ENDIF () IF (MQTT_TEST_2) LIST (APPEND check_PROGRAMS - st_connect.cpp + st_connect1.cpp + st_connect2.cpp st_underlying_timeout.cpp st_as_buffer_sub.cpp st_topic_alias.cpp @@ -32,6 +33,7 @@ IF (MQTT_TEST_3) st_as_buffer_async_pubsub_1.cpp st_multi_sub.cpp st_as_buffer_async_pubsub_2.cpp + st_comp_token.cpp ) ENDIF () @@ -44,7 +46,8 @@ ENDIF () IF (MQTT_TEST_5) LIST (APPEND check_PROGRAMS st_reqres.cpp - st_resend.cpp + st_resend_1.cpp + st_resend_2.cpp st_retain_1.cpp st_resend_new_client.cpp st_retain_2.cpp diff --git a/test/system/st_comp_token.cpp b/test/system/st_comp_token.cpp new file mode 100644 index 000000000..1b6250a70 --- /dev/null +++ b/test/system/st_comp_token.cpp @@ -0,0 +1,523 @@ +// Copyright Takatoshi Kondo 20ss +// +// 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) + +#include "../common/test_main.hpp" +#include "combi_test.hpp" +#include "checker.hpp" +#include "ordered_caller.hpp" +#include "test_util.hpp" +#include "../common/global_fixture.hpp" +#include + +BOOST_AUTO_TEST_SUITE(st_comp_token) + +using namespace MQTT_NS::literals; + + +BOOST_AUTO_TEST_CASE( future ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + + auto wg = boost::asio::make_work_guard(ioc.get_executor()); + + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("c_connect"), + cont("g_connect"), + + cont("c_subscribe"), + cont("g_subscribe"), + + cont("c_publish"), + cont("g_publish"), + + cont("c_unsubscribe"), + cont("g_unsubscribe"), + + cont("c_disconnect"), + cont("g_disconnect"), + }; + + // multiple times called handlers is still callback + c->set_close_handler( + [&] { + } + ); + c->set_error_handler( + [&] + (MQTT_NS::error_code) { + } + ); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&] + (bool, MQTT_NS::connect_return_code) { + }); + c->set_puback_handler( + [&] + (packet_id_t) { + BOOST_CHECK(false); + }); + c->set_pubrec_handler( + [&] + (std::uint16_t) { + BOOST_CHECK(false); + }); + c->set_pubcomp_handler( + [&] + (std::uint16_t) { + BOOST_CHECK(false); + }); + c->set_suback_handler( + [&] + (packet_id_t, std::vector) { + }); + c->set_unsuback_handler( + [&] + (packet_id_t) { + }); + c->set_publish_handler( + [&] + (MQTT_NS::optional, + MQTT_NS::publish_options, + MQTT_NS::buffer, + MQTT_NS::buffer) { + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&] + (bool, MQTT_NS::v5::connect_reason_code, MQTT_NS::v5::properties) { + }); + c->set_v5_puback_handler( + [&] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + }); + c->set_v5_pubrec_handler( + [&] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + }); + c->set_v5_pubcomp_handler( + [&] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + }); + c->set_v5_suback_handler( + [&] + (packet_id_t, std::vector, MQTT_NS::v5::properties) { + }); + c->set_v5_unsuback_handler( + [&] + (packet_id_t, std::vector, MQTT_NS::v5::properties) { + }); + c->set_v5_publish_handler( + [&] + (MQTT_NS::optional, + MQTT_NS::publish_options, + MQTT_NS::buffer, + MQTT_NS::buffer, + MQTT_NS::v5::properties) { + }); + break; + default: + BOOST_CHECK(false); + break; + } + + // future based code + + std::thread th_lib { + [&] { + try { + ioc.run(); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + }; + + // one-shot handler can be replaced with boost::asio::use_future + { + MQTT_CHK("c_connect"); + auto f = c->async_connect(boost::asio::use_future); + try { + f.get(); + MQTT_CHK("g_connect"); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + { + MQTT_CHK("c_subscribe"); + auto pid_sub = c->acquire_unique_packet_id(); + auto f = c->async_subscribe(pid_sub, "topic1", MQTT_NS::qos::exactly_once, boost::asio::use_future); + try { + f.get(); + MQTT_CHK("g_subscribe"); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + { + MQTT_CHK("c_publish"); + auto f = c->async_publish("topic1", "topic1_contents", MQTT_NS::qos::at_most_once, boost::asio::use_future); + try { + f.get(); + MQTT_CHK("g_publish"); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + { + MQTT_CHK("c_unsubscribe"); + auto pid_unsub = c->acquire_unique_packet_id(); + auto f = c->async_unsubscribe(pid_unsub, "topic1", boost::asio::use_future); + try { + f.get(); + MQTT_CHK("g_unsubscribe"); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + { + MQTT_CHK("c_disconnect"); + auto f = c->async_disconnect(boost::asio::use_future); + try { + f.get(); + MQTT_CHK("g_disconnect"); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + + wg.reset(); + finish(); + th_lib.join(); + BOOST_TEST(chk.all()); + }; + do_combi_test_async(test); +} + +BOOST_AUTO_TEST_CASE( user_strand ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + + auto str_user = boost::asio::make_strand(ioc.get_executor()); + auto wg = boost::asio::make_work_guard(ioc.get_executor()); + + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + cont("h_suback"), + cont("h_publish"), + cont("h_unsuback"), + cont("h_close"), + }; + + c->set_close_handler( + [&] { + MQTT_CHK("h_close"); + finish(); + wg.reset(); + } + ); + c->set_error_handler( + [&] + (MQTT_NS::error_code) { + } + ); + + switch (c->get_protocol_version()) { + + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + boost::asio::bind_executor( + str_user, + [&] + (bool, MQTT_NS::connect_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(str_user.running_in_this_thread()); + auto pid_sub = c->acquire_unique_packet_id(); + c->async_subscribe( + pid_sub, + "topic1", + MQTT_NS::qos::exactly_once, + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_puback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t) { + BOOST_CHECK(false); + } + ) + ); + c->set_pubrec_handler( + boost::asio::bind_executor( + str_user, + [&] + (std::uint16_t) { + BOOST_CHECK(false); + } + ) + ); + c->set_pubcomp_handler( + boost::asio::bind_executor( + str_user, + [&] + (std::uint16_t) { + BOOST_CHECK(false); + } + ) + ); + c->set_suback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, std::vector) { + MQTT_CHK("h_suback"); + BOOST_TEST(str_user.running_in_this_thread()); + c->async_publish( + "topic1", + "topic1_contents", + MQTT_NS::qos::at_most_once, + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_unsuback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(str_user.running_in_this_thread()); + c->async_disconnect( + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_publish_handler( + boost::asio::bind_executor( + str_user, + [&] + (MQTT_NS::optional, + MQTT_NS::publish_options, + MQTT_NS::buffer, + MQTT_NS::buffer) { + MQTT_CHK("h_publish"); + BOOST_TEST(str_user.running_in_this_thread()); + auto pid_unsub = c->acquire_unique_packet_id(); + c->async_unsubscribe( + pid_unsub, + "topic1", + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + boost::asio::bind_executor( + str_user, + [&] + (bool, MQTT_NS::v5::connect_reason_code, MQTT_NS::v5::properties) { + MQTT_CHK("h_connack"); + BOOST_TEST(str_user.running_in_this_thread()); + auto pid_sub = c->acquire_unique_packet_id(); + c->async_subscribe( + pid_sub, + "topic1", + MQTT_NS::qos::exactly_once, + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_v5_puback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + } + ) + ); + c->set_v5_pubrec_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + } + ) + ); + c->set_v5_pubcomp_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties) { + BOOST_CHECK(false); + } + ) + ); + c->set_v5_suback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, std::vector, MQTT_NS::v5::properties) { + MQTT_CHK("h_suback"); + BOOST_TEST(str_user.running_in_this_thread()); + c->async_publish( + "topic1", + "topic1_contents", + MQTT_NS::qos::at_most_once, + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_v5_unsuback_handler( + boost::asio::bind_executor( + str_user, + [&] + (packet_id_t, std::vector, MQTT_NS::v5::properties) { + MQTT_CHK("h_unsuback"); + BOOST_TEST(str_user.running_in_this_thread()); + c->async_disconnect( + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + c->set_v5_publish_handler( + boost::asio::bind_executor( + str_user, + [&] + (MQTT_NS::optional, + MQTT_NS::publish_options, + MQTT_NS::buffer, + MQTT_NS::buffer, + MQTT_NS::v5::properties) { + MQTT_CHK("h_publish"); + BOOST_TEST(str_user.running_in_this_thread()); + auto pid_unsub = c->acquire_unique_packet_id(); + c->async_unsubscribe( + pid_unsub, + "topic1", + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + } + ) + ); + break; + default: + BOOST_CHECK(false); + break; + } + + c->async_connect( + boost::asio::bind_executor( + str_user, + [&](MQTT_NS::error_code) { + BOOST_TEST(str_user.running_in_this_thread()); + } + ) + ); + + std::thread th_user { + [&] { + try { + ioc.run(); + } + catch (std::exception const& e) { + BOOST_TEST_INFO(e.what()); + BOOST_CHECK(false); + } + } + }; + th_user.join(); + + }; + do_combi_test_async(test); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/system/st_connect1.cpp b/test/system/st_connect1.cpp new file mode 100644 index 000000000..d0fc74bbe --- /dev/null +++ b/test/system/st_connect1.cpp @@ -0,0 +1,1062 @@ +// Copyright Takatoshi Kondo 2015 +// +// 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) + +#include "../common/test_main.hpp" +#include "combi_test.hpp" +#include "checker.hpp" +#include "ordered_caller.hpp" +#include "test_util.hpp" +#include "../common/global_fixture.hpp" + +BOOST_AUTO_TEST_SUITE(st_connect1) + +using namespace MQTT_NS::literals; + +BOOST_AUTO_TEST_CASE( connect ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + BOOST_TEST(c->connected() == false); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(c->connected() == true); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + c->disconnect(); + BOOST_TEST(c->connected() == true); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(c->connected() == true); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + + c->disconnect(); + BOOST_TEST(c->connected() == true); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish, &c] + () { + MQTT_CHK("h_close"); + BOOST_TEST(c->connected() == false); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + BOOST_TEST(c->connected() == false); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); + do_combi_test(test); // for MQTT_NS::client factory test +} + +BOOST_AUTO_TEST_CASE( connect_no_strand ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( keep_alive ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + cont("h_pingresp"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->set_pingresp_handler( + [&chk, &c] + () { + MQTT_CHK("h_pingresp"); + c->disconnect(); + }); + c->set_keep_alive_sec(3); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( keep_alive_and_send_control_packet ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + cont("2sec"), + cont("h_pingresp"), + cont("4sec_cancelled"), + // disconnect + cont("h_close"), + }; + + boost::asio::steady_timer tim(ioc); + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &tim] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + tim.expires_after(std::chrono::seconds(2)); + tim.async_wait( + [&chk, &c, &tim](MQTT_NS::error_code ec) { + MQTT_CHK("2sec"); + BOOST_CHECK(!ec); + c->publish("topic1", "timer_reset", MQTT_NS::qos::at_most_once); + tim.expires_after(std::chrono::seconds(4)); + tim.async_wait( + [&chk](MQTT_NS::error_code ec) { + MQTT_CHK("4sec_cancelled"); + BOOST_TEST(ec == boost::asio::error::operation_aborted); + } + ); + } + ); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &tim] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + tim.expires_after(std::chrono::seconds(2)); + tim.async_wait( + [&chk, &c, &tim](MQTT_NS::error_code ec) { + MQTT_CHK("2sec"); + BOOST_CHECK(!ec); + c->publish("topic1", "timer_reset", MQTT_NS::qos::at_most_once); + tim.expires_after(std::chrono::seconds(4)); + tim.async_wait( + [&chk](MQTT_NS::error_code ec) { + MQTT_CHK("4sec_cancelled"); + BOOST_TEST(ec == boost::asio::error::operation_aborted); + } + ); + } + ); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->set_pingresp_handler( + [&chk, &c, &tim] + () { + MQTT_CHK("h_pingresp"); + tim.cancel(); + c->disconnect(); + }); + c->set_keep_alive_sec(3, std::chrono::seconds(3)); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + + +BOOST_AUTO_TEST_CASE( pingresp_timeout ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + b.set_pingresp(false); + c->set_pingresp_timeout(std::chrono::seconds(2)); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // error + cont("h_error"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [] + () { + BOOST_CHECK(false); + }); + c->set_error_handler( + [&chk, &finish] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + finish(); + }); + c->set_keep_alive_sec(3); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( connect_again ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + bool first = true; + + checker chk = { + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&first, &chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + if (first) { + MQTT_CHK("h_connack1"); + } + else { + MQTT_CHK("h_connack2"); + } + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&first, &chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + if (first) { + MQTT_CHK("h_connack1"); + } + else { + MQTT_CHK("h_connack2"); + } + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&first, &chk, &c, &finish] + () { + if (first) { + MQTT_CHK("h_close1"); + first = false; + c->connect(); + } + else { + MQTT_CHK("h_close2"); + finish(); + } + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( nocid ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties props) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + std::size_t times = 0; + MQTT_NS::v5::visit_props( + props, + [&](MQTT_NS::v5::property::assigned_client_identifier const& p) { + ++times; + BOOST_TEST(p.val() == c->get_client_id()); + }, + [](auto){} + ); + BOOST_TEST(times == 1); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( nocid_noclean ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_error"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::identifier_rejected); + }); + break; + case MQTT_NS::protocol_version::v5: + // On v5, a combination of empty client_id and clean_start:false is accepted. + // Because the client can know the assigned client_id. + // Even if session_expiry_interval != 0 and store the disconnected session, + // the client can access the session using assigned client_id + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties props) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + std::size_t times = 0; + MQTT_NS::v5::visit_props( + props, + [&](MQTT_NS::v5::property::assigned_client_identifier const& p) { + ++times; + BOOST_TEST(p.val() == c->get_client_id()); + }, + [](auto){} + ); + BOOST_TEST(times == 1); + c->force_disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [] + () { + BOOST_CHECK(false); + }); + c->set_error_handler( + [&chk, &finish] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + finish(); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( noclean ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + + checker chk = { + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // disconnect + cont("h_close2"), + // connect + cont("h_connack3"), + // disconnect + cont("h_close3"), + // connect + cont("h_connack4"), + // disconnect + cont("h_close4"), + }; + + int connect = 0; + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &connect, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + switch (connect) { + case 0: + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + break; + case 1: + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == true); + break; + case 2: + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == false); + break; + case 3: + MQTT_CHK("h_connack4"); + BOOST_TEST(sp == false); + break; + } + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &connect, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + switch (connect) { + case 0: + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + break; + case 1: + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + break; + case 2: + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == false); + break; + case 3: + MQTT_CHK("h_connack4"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + break; + } + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &connect, &c, &finish] + () { + switch (connect) { + case 0: + MQTT_CHK("h_close1"); + c->connect(); + ++connect; + break; + case 1: + MQTT_CHK("h_close2"); + c->set_clean_session(true); + c->connect(); + ++connect; + break; + case 2: + MQTT_CHK("h_close3"); + c->set_clean_session(false); + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->connect(); + break; + case MQTT_NS::protocol_version::v5: + c->connect( + MQTT_NS::v5::properties{ + MQTT_NS::v5::property::session_expiry_interval( + MQTT_NS::session_never_expire + ) + } + ); + break; + default: + BOOST_CHECK(false); + break; + } + ++connect; + break; + case 3: + MQTT_CHK("h_close4"); + finish(); + break; + } + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( disconnect_timeout ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + b.set_disconnect_delay(std::chrono::seconds(2)); + c->disconnect(std::chrono::seconds(1)); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + b.set_disconnect_delay(std::chrono::seconds(2)); + c->disconnect(std::chrono::seconds(1)); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( disconnect_not_timeout ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + b.set_disconnect_delay(std::chrono::seconds(1)); + c->disconnect(std::chrono::seconds(2)); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + b.set_disconnect_delay(std::chrono::seconds(1)); + c->disconnect(std::chrono::seconds(2)); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( async_disconnect_timeout ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + b.set_disconnect_delay(std::chrono::seconds(2)); + c->async_disconnect(std::chrono::seconds(1)); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + b.set_disconnect_delay(std::chrono::seconds(2)); + c->async_disconnect(std::chrono::seconds(1)); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->async_connect(42); // 42 is dummy session_life_keeper object to increase coverage + break; + case MQTT_NS::protocol_version::v5: + c->async_connect(MQTT_NS::v5::properties(), 42); // 42 is dummy session_life_keeper object to increase coverage + break; + default: + BOOST_CHECK(false); + break; + } + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_async(test); +} + +BOOST_AUTO_TEST_CASE( async_disconnect_not_timeout ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + b.set_disconnect_delay(std::chrono::seconds(1)); + c->async_disconnect(std::chrono::seconds(2)); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &b] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + b.set_disconnect_delay(std::chrono::seconds(1)); + c->async_disconnect(std::chrono::seconds(2)); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->async_connect( + [] + (MQTT_NS::error_code ec) { + BOOST_TEST( ! ec); + } + ); + break; + case MQTT_NS::protocol_version::v5: + c->async_connect( + MQTT_NS::v5::properties(), + [] + (MQTT_NS::error_code ec) { + BOOST_TEST( ! ec); + } + ); + break; + default: + BOOST_CHECK(false); + break; + } + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_async(test); +} + + +BOOST_AUTO_TEST_CASE( async_keep_alive ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + c->set_client_id("cid1"); + c->set_clean_session(true); + + checker chk = { + // connect + cont("h_connack"), + cont("h_pingresp"), + // disconnect + cont("h_close"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk] + (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_connack"); + BOOST_TEST(sp == false); + BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &finish] + () { + MQTT_CHK("h_close"); + finish(); + }); + c->set_error_handler( + [] + (MQTT_NS::error_code) { + BOOST_CHECK(false); + }); + c->set_pingresp_handler( + [&chk, &c] + () { + MQTT_CHK("h_pingresp"); + c->async_disconnect(); + }); + c->set_keep_alive_sec(3); + c->async_connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_async(test); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/system/st_connect.cpp b/test/system/st_connect2.cpp similarity index 51% rename from test/system/st_connect.cpp rename to test/system/st_connect2.cpp index f79686ea1..e636b5e23 100644 --- a/test/system/st_connect.cpp +++ b/test/system/st_connect2.cpp @@ -11,1054 +11,10 @@ #include "test_util.hpp" #include "../common/global_fixture.hpp" -BOOST_AUTO_TEST_SUITE(st_connect) +BOOST_AUTO_TEST_SUITE(st_connect2) using namespace MQTT_NS::literals; -BOOST_AUTO_TEST_CASE( connect ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - BOOST_TEST(c->connected() == false); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(c->connected() == true); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - c->disconnect(); - BOOST_TEST(c->connected() == true); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(c->connected() == true); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - - c->disconnect(); - BOOST_TEST(c->connected() == true); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish, &c] - () { - MQTT_CHK("h_close"); - BOOST_TEST(c->connected() == false); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - BOOST_TEST(c->connected() == false); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); - do_combi_test(test); // for MQTT_NS::client factory test -} - -BOOST_AUTO_TEST_CASE( connect_no_strand ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( keep_alive ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - cont("h_pingresp"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->set_pingresp_handler( - [&chk, &c] - () { - MQTT_CHK("h_pingresp"); - c->disconnect(); - }); - c->set_keep_alive_sec(3); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( keep_alive_and_send_control_packet ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - cont("2sec"), - cont("h_pingresp"), - cont("4sec_cancelled"), - // disconnect - cont("h_close"), - }; - - boost::asio::steady_timer tim(ioc); - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &tim] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - tim.expires_after(std::chrono::seconds(2)); - tim.async_wait( - [&chk, &c, &tim](MQTT_NS::error_code ec) { - MQTT_CHK("2sec"); - BOOST_CHECK(!ec); - c->publish("topic1", "timer_reset", MQTT_NS::qos::at_most_once); - tim.expires_after(std::chrono::seconds(4)); - tim.async_wait( - [&chk](MQTT_NS::error_code ec) { - MQTT_CHK("4sec_cancelled"); - BOOST_TEST(ec == boost::asio::error::operation_aborted); - } - ); - } - ); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &tim] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - tim.expires_after(std::chrono::seconds(2)); - tim.async_wait( - [&chk, &c, &tim](MQTT_NS::error_code ec) { - MQTT_CHK("2sec"); - BOOST_CHECK(!ec); - c->publish("topic1", "timer_reset", MQTT_NS::qos::at_most_once); - tim.expires_after(std::chrono::seconds(4)); - tim.async_wait( - [&chk](MQTT_NS::error_code ec) { - MQTT_CHK("4sec_cancelled"); - BOOST_TEST(ec == boost::asio::error::operation_aborted); - } - ); - } - ); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->set_pingresp_handler( - [&chk, &c, &tim] - () { - MQTT_CHK("h_pingresp"); - tim.cancel(); - c->disconnect(); - }); - c->set_keep_alive_sec(3, std::chrono::seconds(3)); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - - -BOOST_AUTO_TEST_CASE( pingresp_timeout ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - b.set_pingresp(false); - c->set_pingresp_timeout(std::chrono::seconds(2)); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // error - cont("h_error"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [] - () { - BOOST_CHECK(false); - }); - c->set_error_handler( - [&chk, &finish] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - finish(); - }); - c->set_keep_alive_sec(3); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( connect_again ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - bool first = true; - - checker chk = { - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&first, &chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - if (first) { - MQTT_CHK("h_connack1"); - } - else { - MQTT_CHK("h_connack2"); - } - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&first, &chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - if (first) { - MQTT_CHK("h_connack1"); - } - else { - MQTT_CHK("h_connack2"); - } - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&first, &chk, &c, &finish] - () { - if (first) { - MQTT_CHK("h_close1"); - first = false; - c->connect(); - } - else { - MQTT_CHK("h_close2"); - finish(); - } - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( nocid ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties props) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - std::size_t times = 0; - MQTT_NS::v5::visit_props( - props, - [&](MQTT_NS::v5::property::assigned_client_identifier const& p) { - ++times; - BOOST_TEST(p.val() == c->get_client_id()); - }, - [](auto){} - ); - BOOST_TEST(times == 1); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( nocid_noclean ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_error"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::identifier_rejected); - }); - break; - case MQTT_NS::protocol_version::v5: - // On v5, a combination of empty client_id and clean_start:false is accepted. - // Because the client can know the assigned client_id. - // Even if session_expiry_interval != 0 and store the disconnected session, - // the client can access the session using assigned client_id - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties props) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - std::size_t times = 0; - MQTT_NS::v5::visit_props( - props, - [&](MQTT_NS::v5::property::assigned_client_identifier const& p) { - ++times; - BOOST_TEST(p.val() == c->get_client_id()); - }, - [](auto){} - ); - BOOST_TEST(times == 1); - c->force_disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [] - () { - BOOST_CHECK(false); - }); - c->set_error_handler( - [&chk, &finish] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - finish(); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( noclean ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - - checker chk = { - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // disconnect - cont("h_close2"), - // connect - cont("h_connack3"), - // disconnect - cont("h_close3"), - // connect - cont("h_connack4"), - // disconnect - cont("h_close4"), - }; - - int connect = 0; - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &connect, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - switch (connect) { - case 0: - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - break; - case 1: - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == true); - break; - case 2: - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == false); - break; - case 3: - MQTT_CHK("h_connack4"); - BOOST_TEST(sp == false); - break; - } - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &connect, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - switch (connect) { - case 0: - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - break; - case 1: - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - break; - case 2: - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == false); - break; - case 3: - MQTT_CHK("h_connack4"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - break; - } - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &connect, &c, &finish] - () { - switch (connect) { - case 0: - MQTT_CHK("h_close1"); - c->connect(); - ++connect; - break; - case 1: - MQTT_CHK("h_close2"); - c->set_clean_session(true); - c->connect(); - ++connect; - break; - case 2: - MQTT_CHK("h_close3"); - c->set_clean_session(false); - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->connect(); - break; - case MQTT_NS::protocol_version::v5: - c->connect( - MQTT_NS::v5::properties{ - MQTT_NS::v5::property::session_expiry_interval( - MQTT_NS::session_never_expire - ) - } - ); - break; - default: - BOOST_CHECK(false); - break; - } - ++connect; - break; - case 3: - MQTT_CHK("h_close4"); - finish(); - break; - } - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( disconnect_timeout ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - b.set_disconnect_delay(std::chrono::seconds(2)); - c->disconnect(std::chrono::seconds(1)); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - b.set_disconnect_delay(std::chrono::seconds(2)); - c->disconnect(std::chrono::seconds(1)); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( disconnect_not_timeout ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - b.set_disconnect_delay(std::chrono::seconds(1)); - c->disconnect(std::chrono::seconds(2)); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - b.set_disconnect_delay(std::chrono::seconds(1)); - c->disconnect(std::chrono::seconds(2)); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( async_disconnect_timeout ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - b.set_disconnect_delay(std::chrono::seconds(2)); - c->async_disconnect(std::chrono::seconds(1)); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - b.set_disconnect_delay(std::chrono::seconds(2)); - c->async_disconnect(std::chrono::seconds(1)); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->async_connect(42); // 42 is dummy session_life_keeper object to increase coverage - break; - case MQTT_NS::protocol_version::v5: - c->async_connect(MQTT_NS::v5::properties(), 42); // 42 is dummy session_life_keeper object to increase coverage - break; - default: - BOOST_CHECK(false); - break; - } - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_async(test); -} - -BOOST_AUTO_TEST_CASE( async_disconnect_not_timeout ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - b.set_disconnect_delay(std::chrono::seconds(1)); - c->async_disconnect(std::chrono::seconds(2)); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &b] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - b.set_disconnect_delay(std::chrono::seconds(1)); - c->async_disconnect(std::chrono::seconds(2)); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->async_connect( - [] - (MQTT_NS::error_code ec) { - BOOST_TEST( ! ec); - } - ); - break; - case MQTT_NS::protocol_version::v5: - c->async_connect( - MQTT_NS::v5::properties(), - [] - (MQTT_NS::error_code ec) { - BOOST_TEST( ! ec); - } - ); - break; - default: - BOOST_CHECK(false); - break; - } - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_async(test); -} - - -BOOST_AUTO_TEST_CASE( async_keep_alive ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - c->set_client_id("cid1"); - c->set_clean_session(true); - - checker chk = { - // connect - cont("h_connack"), - cont("h_pingresp"), - // disconnect - cont("h_close"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk] - (bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_connack"); - BOOST_TEST(sp == false); - BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &finish] - () { - MQTT_CHK("h_close"); - finish(); - }); - c->set_error_handler( - [] - (MQTT_NS::error_code) { - BOOST_CHECK(false); - }); - c->set_pingresp_handler( - [&chk, &c] - () { - MQTT_CHK("h_pingresp"); - c->async_disconnect(); - }); - c->set_keep_alive_sec(3); - c->async_connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_async(test); -} - BOOST_AUTO_TEST_CASE( async_keep_alive_and_send_control_packet ) { auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { auto& c = cs[0]; diff --git a/test/system/st_resend.cpp b/test/system/st_resend.cpp deleted file mode 100644 index 057c958a3..000000000 --- a/test/system/st_resend.cpp +++ /dev/null @@ -1,2250 +0,0 @@ -// Copyright Takatoshi Kondo 2015 -// -// 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) - -#include "../common/test_main.hpp" -#include "combi_test.hpp" -#include "checker.hpp" -#include "ordered_caller.hpp" -#include "test_util.hpp" -#include "../common/global_fixture.hpp" - -BOOST_AUTO_TEST_SUITE(st_resend) - -using namespace MQTT_NS::literals; - -BOOST_AUTO_TEST_CASE( publish_qos1 ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS1 - // force_disconnect - cont("h_error"), - // connect - cont("h_connack3"), - cont("h_puback"), - // disconnect - cont("h_close2"), - }; - - MQTT_NS::v5::properties ps { - MQTT_NS::v5::property::payload_format_indicator(MQTT_NS::v5::property::payload_format_indicator::string), - MQTT_NS::v5::property::message_expiry_interval(0x12345678UL), - MQTT_NS::v5::property::topic_alias(0x1234U), - MQTT_NS::v5::property::response_topic("response topic"_mb), - MQTT_NS::v5::property::correlation_data("correlation data"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - - std::size_t user_prop_count = 0; - b.set_publish_props_handler( - [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { - BOOST_TEST(props.size() == size); - - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::payload_format_indicator const& t) { - BOOST_TEST(t.val() == MQTT_NS::v5::property::payload_format_indicator::string); - }, - [&](MQTT_NS::v5::property::message_expiry_interval const& t) { - BOOST_TEST(t.val() == 0x12345678UL); - }, - [&](MQTT_NS::v5::property::topic_alias const& t) { - BOOST_TEST(t.val() == 0x1234U); - }, - [&](MQTT_NS::v5::property::response_topic const& t) { - BOOST_TEST(t.val() == "response topic"); - }, - [&](MQTT_NS::v5::property::correlation_data const& t) { - BOOST_TEST(t.val() == "correlation data"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - case 2: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 3: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - } - ); - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_puback_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_pub, ps = std::move(ps)] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&, ps = std::move(ps)] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no, std::move(ps)); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_puback_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_qos2 ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS2 - // force_disconnect - cont("h_error"), - // connect - cont("h_connack3"), - cont("h_pubrec"), - cont("h_pubcomp"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_pubrec_handler( - [&chk, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - }); - c->set_pubcomp_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_pubrec_handler( - [&chk, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - }); - c->set_v5_pubcomp_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS2 - cont("h_pubrec"), - // force_disconnect - cont("h_error"), - // connect - cont("h_connack3"), - cont("h_pubcomp"), - // disconnect - cont("h_close2"), - }; - - MQTT_NS::v5::properties ps { - MQTT_NS::v5::property::reason_string("test success"_mb), - MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), - MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), - }; - std::size_t user_prop_count = 0; - - b.set_pubrel_props_handler( - [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { - BOOST_TEST(props.size() == size); - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::reason_string const& t) { - BOOST_TEST(t.val() == "test success"); - }, - [&](MQTT_NS::v5::property::user_property const& t) { - switch (user_prop_count++) { - case 0: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 1: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - case 2: - BOOST_TEST(t.key() == "key1"); - BOOST_TEST(t.val() == "val1"); - break; - case 3: - BOOST_TEST(t.key() == "key2"); - BOOST_TEST(t.val() == "val2"); - break; - default: - BOOST_TEST(false); - break; - } - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - } - ); - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_pubrec_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - c->force_disconnect(); - }); - c->set_pubcomp_handler( - [&chk, &c] - (packet_id_t packet_id) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == 1); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_auto_pub_response(false); - c->set_v5_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_pubrec_handler( - [&chk, &c, &pid_pub, ps = std::move(ps)] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); - c->force_disconnect(); - }); - c->set_v5_pubcomp_handler( - [&chk, &c] - (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == 1); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS2 - // force_disconnect - cont("h_error1"), - // connect - cont("h_connack3"), - cont("h_pubrec"), - // force_disconnect - cont("h_error2"), - // connect - cont("h_connack4"), - cont("h_pubcomp"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, & pid_pub] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - }, - [&] { - MQTT_CHK("h_connack4"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_pubrec_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - c->force_disconnect(); - }); - c->set_pubcomp_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, & pid_pub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - }, - [&] { - MQTT_CHK("h_connack4"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_pubrec_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubrec"); - BOOST_TEST(packet_id == pid_pub); - c->force_disconnect(); - }); - c->set_v5_pubcomp_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubcomp"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_error1"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }, - [&] { - MQTT_CHK("h_error2"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - } - ); - BOOST_TEST(ret); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - - -BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - cont("h_suback"), - // publish topic1 QoS1 - cont("h_puback"), - deps("h_publish1", "h_suback"), - // force_disconnect - deps("h_error", "h_puback", "h_publish1"), - // connect - cont("h_connack3"), - cont("h_publish2"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_suback_handler( - [&chk, &c] - (packet_id_t, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - } - ); - c->set_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_publish1"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_puback")) { - c->force_disconnect(); - } - }, - [&] { - MQTT_CHK("h_publish2"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - BOOST_TEST(packet_id.value() == pid_pub); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - c->puback(packet_id.value()); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_puback_handler( - [&chk, &c] - (packet_id_t) { - MQTT_CHK("h_puback"); - if (chk.passed("h_publish1")) { - c->force_disconnect(); - } - } - ); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_suback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); - } - ); - c->set_v5_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_publish1"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_puback")) { - c->force_disconnect(); - } - }, - [&] { - MQTT_CHK("h_publish2"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - BOOST_TEST(packet_id.value() == pid_pub); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - c->puback(packet_id.value()); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_v5_puback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - if (chk.passed("h_publish1")) { - c->force_disconnect(); - } - } - ); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_qos2_from_broker ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - cont("h_suback"), - // publish topic1 QoS2 - cont("h_pubrec"), - cont("h_pubcomp"), - deps("h_publish1", "h_suback"), - // force_disconnect - deps("h_error", "h_pubcomp", "h_publish1"), - // connect - cont("h_connack3"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_suback_handler( - [&chk, &c] - (packet_id_t, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - } - ); - c->set_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish1"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_pubcomp")) { - c->force_disconnect(); - } - } - ); - c->set_pubrec_handler( - [&chk, &c] - (packet_id_t packet_id) { - MQTT_CHK("h_pubrec"); - c->pubrel(packet_id); - } - ); - c->set_pubcomp_handler( - [&chk, &c] - (packet_id_t) { - MQTT_CHK("h_pubcomp"); - if (chk.passed("h_publish1")) { - c->force_disconnect(); - } - } - ); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - c->disconnect(); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_suback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - } - ); - c->set_v5_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish1"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_pubcomp")) { - c->force_disconnect(); - } - } - ); - c->set_v5_pubrec_handler( - [&chk, &c] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubrec"); - c->pubrel(packet_id); - }); - c->set_v5_pubcomp_handler( - [&chk, &c] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubcomp"); - if (chk.passed("h_publish1")) { - c->force_disconnect(); - } - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( pubrel_qos2_from_broker ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - cont("h_suback"), - // publish topic1 QoS2 - cont("h_pubrec"), - cont("h_pubcomp"), - deps("h_publish", "h_suback"), - cont("h_pubrel1"), - // force_disconnect - deps("h_error", "h_pubcomp", "h_publish"), - // connect - cont("h_connack3"), - cont("h_pubrel2"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_suback_handler( - [&chk, &c] - (packet_id_t, std::vector results) { - MQTT_CHK("h_suback"); - BOOST_TEST(results.size() == 1U); - BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - } - ); - c->set_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - c->pubrec(packet_id.value()); - } - ); - c->set_pubrec_handler( - [&chk, &c] - (packet_id_t packet_id) { - MQTT_CHK("h_pubrec"); - c->pubrel(packet_id); - } - ); - c->set_pubrel_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_pubrel1"); - BOOST_TEST(packet_id == pid_pub); - if (chk.passed("h_pubcomp")) { - c->force_disconnect(); - } - }, - [&] { - MQTT_CHK("h_pubrel2"); - BOOST_TEST(packet_id == pid_pub); - c->pubcomp(packet_id); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_pubcomp_handler( - [&chk, &c] - (packet_id_t) { - MQTT_CHK("h_pubcomp"); - if (chk.passed("h_publish")) { - c->force_disconnect(); - } - } - ); - break; - case MQTT_NS::protocol_version::v5: - c->set_auto_pub_response(false); - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - } - ); - c->set_v5_suback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); - } - ); - c->set_v5_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::exactly_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - c->pubrec(packet_id.value()); - } - ); - c->set_v5_pubrec_handler( - [&chk, &c] - (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubrec"); - c->pubrel(packet_id); - } - ); - c->set_v5_pubrel_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::pubrel_reason_code, MQTT_NS::v5::properties /*props*/) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_pubrel1"); - BOOST_TEST(packet_id == pid_pub); - if (chk.passed("h_pubcomp")) { - c->force_disconnect(); - } - }, - [&] { - MQTT_CHK("h_pubrel2"); - BOOST_TEST(packet_id == pid_pub); - c->pubcomp(packet_id); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_v5_pubcomp_handler( - [&chk, &c] - (packet_id_t, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_pubcomp"); - if (chk.passed("h_publish")) { - c->force_disconnect(); - } - } - ); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_message_expired_from_broker ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - cont("h_suback"), - // publish topic1 QoS1 - cont("h_puback"), - deps("h_publish", "h_suback"), - // force_disconnect - deps("h_error", "h_puback", "h_publish"), - // connect - cont("h_connack3"), - // disconnect - cont("h_close2"), - }; - - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - c->disconnect(); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_suback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - c->publish( - "topic1", - "topic1_contents", - MQTT_NS::qos::at_least_once, - MQTT_NS::v5::properties { MQTT_NS::v5::property::message_expiry_interval(1) } - ); - } - ); - c->set_v5_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_publish"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_puback")) { - c->force_disconnect(); - } - } - ); - c->set_v5_puback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - if (chk.passed("h_publish")) { - c->force_disconnect(); - } - } - ); - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - tim.expires_after(std::chrono::seconds(2)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_message_expiry_update_from_broker ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - c->set_auto_pub_response(false); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - cont("h_suback"), - // publish topic1 QoS1 - cont("h_puback"), - deps("h_publish1", "h_suback"), - // force_disconnect - deps("h_error", "h_puback", "h_publish1"), - // connect - cont("h_connack3"), - cont("h_publish2"), - // disconnect - cont("h_close2"), - }; - - c->set_v5_connack_handler( - [&chk, &c] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - c->subscribe("topic1", MQTT_NS::qos::exactly_once); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - } - ); - c->set_v5_suback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_suback"); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons.size() == 1U); - BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); - c->publish( - "topic1", - "topic1_contents", - MQTT_NS::qos::at_least_once, - MQTT_NS::v5::properties { MQTT_NS::v5::property::message_expiry_interval(5) } - ); - } - ); - c->set_v5_publish_handler( - [&chk, &c, &pid_pub] - (MQTT_NS::optional packet_id, - MQTT_NS::publish_options pubopts, - MQTT_NS::buffer topic, - MQTT_NS::buffer contents, - MQTT_NS::v5::properties props) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_publish1"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - pid_pub = packet_id.value(); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - if (chk.passed("h_puback")) { - c->force_disconnect(); - } - }, - [&] { - MQTT_CHK("h_publish2"); - BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); - BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); - BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); - BOOST_CHECK(packet_id); - BOOST_TEST(packet_id.value() == pid_pub); - BOOST_TEST(topic == "topic1"); - BOOST_TEST(contents == "topic1_contents"); - - for (auto const& p : props) { - MQTT_NS::visit( - MQTT_NS::make_lambda_visitor( - [&](MQTT_NS::v5::property::message_expiry_interval const& t) { - BOOST_TEST(t.val() < 5); - }, - [&](auto&& ...) { - BOOST_TEST(false); - } - ), - p - ); - } - c->puback(packet_id.value()); - c->disconnect(); - } - ); - BOOST_TEST(ret); - } - ); - c->set_v5_puback_handler( - [&chk, &c] - (packet_id_t /*packet_id*/, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - if (chk.passed("h_publish1")) { - c->force_disconnect(); - } - } - ); - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - tim.expires_after(std::chrono::seconds(2)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub1; - packet_id_t pid_pub2; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS1 - // publish topic1 QoS1 - // force_disconnect - cont("h_error1"), - // connect - cont("h_connack3"), - cont("h_puback1"), - cont("h_puback2"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v3_1_1: - c->set_connack_handler( - [&chk, &c, &pid_pub1, &pid_pub2] - (bool sp, MQTT_NS::connect_return_code connack_return_code) { - BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - BOOST_TEST(sp == false); - pid_pub1 = c->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_least_once); - pid_pub2 = c->publish("topic1", "topic1_contents2", MQTT_NS::qos::at_least_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_puback_handler( - [&chk, &c, &pid_pub1, &pid_pub2] - (packet_id_t packet_id) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_puback1"); - BOOST_TEST(packet_id == pid_pub1); - }, - [&] { - MQTT_CHK("h_puback2"); - BOOST_TEST(packet_id == pid_pub2); - c->disconnect(); - } - ); - BOOST_TEST(ret); - }); - break; - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_pub1, &pid_pub2] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub1 = c->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_least_once); - pid_pub2 = c->publish("topic1", "topic1_contents2", MQTT_NS::qos::at_least_once); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_puback_handler( - [&chk, &c, &pid_pub1, &pid_pub2] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_puback1"); - BOOST_TEST(packet_id == pid_pub1); - }, - [&] { - MQTT_CHK("h_puback2"); - BOOST_TEST(packet_id == pid_pub2); - c->disconnect(); - } - ); - BOOST_TEST(ret); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - connect_no_clean(c); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error1"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - connect_no_clean(c); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_session_before_expire ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS1 - // force_disconnect - cont("h_error"), - // connect - cont("h_connack3"), - cont("h_puback"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == true); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_puback_handler( - [&chk, &c, &pid_pub] - (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - MQTT_CHK("h_puback"); - BOOST_TEST(packet_id == pid_pub); - c->disconnect(); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - c->set_clean_start(false); - c->connect( - MQTT_NS::v5::properties { - MQTT_NS::v5::property::session_expiry_interval(5) - } - ); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - // TCP level disconnection detecting timing is unpredictable. - // Sometimes broker first, sometimes the client (this test) first. - // This test assume that the broker detects first, so I set timer. - // If client detect the disconnection first, then reconnect with - // existing client id. And it is overwritten at broker. - // Then error handler in the broker called, assertion failed due to - // no corresponding connection exists - tim.expires_after(std::chrono::milliseconds(100)); - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - c->set_clean_start(false); - c->connect( - MQTT_NS::v5::properties { - MQTT_NS::v5::property::session_expiry_interval( - MQTT_NS::session_never_expire - ) - } - ); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - -BOOST_AUTO_TEST_CASE( publish_session_after_expire ) { - auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { - auto& c = cs[0]; - clear_ordered(); - if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) { - finish(); - return; - } - - using packet_id_t = typename std::remove_reference_t::packet_id_t; - c->set_client_id("cid1"); - c->set_clean_session(true); - - packet_id_t pid_pub; - - boost::asio::steady_timer tim(ioc); - - checker chk = { - cont("start"), - // connect - cont("h_connack1"), - // disconnect - cont("h_close1"), - // connect - cont("h_connack2"), - // publish topic1 QoS1 - // force_disconnect - cont("h_error"), - // connect - cont("h_connack3"), - // disconnect - cont("h_close2"), - }; - - switch (c->get_protocol_version()) { - case MQTT_NS::protocol_version::v5: - c->set_v5_connack_handler( - [&chk, &c, &pid_pub] - (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_connack1"); - BOOST_TEST(sp == false); - c->disconnect(); - }, - [&] { - MQTT_CHK("h_connack2"); - // The previous connection is not set Session Expiry Interval. - // That means session state is cleared on close. - BOOST_TEST(sp == false); - pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no); - c->force_disconnect(); - }, - [&] { - MQTT_CHK("h_connack3"); - BOOST_TEST(sp == false); // session has been expired - c->disconnect(); - } - ); - BOOST_TEST(ret); - }); - c->set_v5_puback_handler( - [] - (packet_id_t, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { - BOOST_TEST(false); - }); - break; - default: - BOOST_CHECK(false); - break; - } - - c->set_close_handler( - [&chk, &c, &finish] - () { - auto ret = MQTT_ORDERED( - [&] { - MQTT_CHK("h_close1"); - c->set_clean_start(false); - c->connect( - MQTT_NS::v5::properties { - MQTT_NS::v5::property::session_expiry_interval(2) - } - ); - }, - [&] { - MQTT_CHK("h_close2"); - finish(); - } - ); - BOOST_TEST(ret); - }); - c->set_error_handler( - [&chk, &c, &tim] - (MQTT_NS::error_code) { - MQTT_CHK("h_error"); - tim.expires_after(std::chrono::seconds(4)); // after expired - tim.async_wait( - [&c] (MQTT_NS::error_code ec) { - BOOST_ASSERT( ! ec); - c->set_clean_start(false); - c->connect( - MQTT_NS::v5::properties { - MQTT_NS::v5::property::session_expiry_interval( - MQTT_NS::session_never_expire - ) - } - ); - } - ); - }); - MQTT_CHK("start"); - c->connect(); - ioc.run(); - BOOST_TEST(chk.all()); - }; - do_combi_test_sync(test); -} - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/test/system/st_resend_1.cpp b/test/system/st_resend_1.cpp new file mode 100644 index 000000000..f22567c67 --- /dev/null +++ b/test/system/st_resend_1.cpp @@ -0,0 +1,1030 @@ +// Copyright Takatoshi Kondo 2015 +// +// 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) + +#include "../common/test_main.hpp" +#include "combi_test.hpp" +#include "checker.hpp" +#include "ordered_caller.hpp" +#include "test_util.hpp" +#include "../common/global_fixture.hpp" + +BOOST_AUTO_TEST_SUITE(st_resend1) + +using namespace MQTT_NS::literals; + +BOOST_AUTO_TEST_CASE( publish_qos1 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS1 + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_puback"), + // disconnect + cont("h_close2"), + }; + + MQTT_NS::v5::properties ps { + MQTT_NS::v5::property::payload_format_indicator(MQTT_NS::v5::property::payload_format_indicator::string), + MQTT_NS::v5::property::message_expiry_interval(0x12345678UL), + MQTT_NS::v5::property::topic_alias(0x1234U), + MQTT_NS::v5::property::response_topic("response topic"_mb), + MQTT_NS::v5::property::correlation_data("correlation data"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + + std::size_t user_prop_count = 0; + b.set_publish_props_handler( + [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { + BOOST_TEST(props.size() == size); + + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::payload_format_indicator const& t) { + BOOST_TEST(t.val() == MQTT_NS::v5::property::payload_format_indicator::string); + }, + [&](MQTT_NS::v5::property::message_expiry_interval const& t) { + BOOST_TEST(t.val() == 0x12345678UL); + }, + [&](MQTT_NS::v5::property::topic_alias const& t) { + BOOST_TEST(t.val() == 0x1234U); + }, + [&](MQTT_NS::v5::property::response_topic const& t) { + BOOST_TEST(t.val() == "response topic"); + }, + [&](MQTT_NS::v5::property::correlation_data const& t) { + BOOST_TEST(t.val() == "correlation data"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + case 2: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 3: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + } + ); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_puback_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_pub, ps = std::move(ps)] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&, ps = std::move(ps)] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no, std::move(ps)); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_puback_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_pubrec"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + }); + c->set_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + }); + c->set_v5_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + cont("h_pubrec"), + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + MQTT_NS::v5::properties ps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + std::size_t user_prop_count = 0; + + b.set_pubrel_props_handler( + [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { + BOOST_TEST(props.size() == size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + case 2: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 3: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + } + ); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_pubcomp_handler( + [&chk, &c] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == 1); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_auto_pub_response(false); + c->set_v5_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &c, &pid_pub, ps = std::move(ps)] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); + c->force_disconnect(); + }); + c->set_v5_pubcomp_handler( + [&chk, &c] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == 1); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + // force_disconnect + cont("h_error1"), + // connect + cont("h_connack3"), + cont("h_pubrec"), + // force_disconnect + cont("h_error2"), + // connect + cont("h_connack4"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, & pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + }, + [&] { + MQTT_CHK("h_connack4"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, & pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + }, + [&] { + MQTT_CHK("h_connack4"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_v5_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_error1"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }, + [&] { + MQTT_CHK("h_error2"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + } + ); + BOOST_TEST(ret); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + + +BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + c->set_auto_pub_response(false); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + cont("h_suback"), + // publish topic1 QoS1 + cont("h_puback"), + deps("h_publish1", "h_suback"), + // force_disconnect + deps("h_error", "h_puback", "h_publish1"), + // connect + cont("h_connack3"), + cont("h_publish2"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + c->subscribe("topic1", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_suback_handler( + [&chk, &c] + (packet_id_t, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); + c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + } + ); + c->set_publish_handler( + [&chk, &c, &pid_pub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_publish1"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + pid_pub = packet_id.value(); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + if (chk.passed("h_puback")) { + c->force_disconnect(); + } + }, + [&] { + MQTT_CHK("h_publish2"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + BOOST_TEST(packet_id.value() == pid_pub); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + c->puback(packet_id.value()); + c->disconnect(); + } + ); + BOOST_TEST(ret); + } + ); + c->set_puback_handler( + [&chk, &c] + (packet_id_t) { + MQTT_CHK("h_puback"); + if (chk.passed("h_publish1")) { + c->force_disconnect(); + } + } + ); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + c->subscribe("topic1", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_suback_handler( + [&chk, &c] + (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); + c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + } + ); + c->set_v5_publish_handler( + [&chk, &c, &pid_pub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_publish1"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + pid_pub = packet_id.value(); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + if (chk.passed("h_puback")) { + c->force_disconnect(); + } + }, + [&] { + MQTT_CHK("h_publish2"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + BOOST_TEST(packet_id.value() == pid_pub); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + c->puback(packet_id.value()); + c->disconnect(); + } + ); + BOOST_TEST(ret); + } + ); + c->set_v5_puback_handler( + [&chk, &c] + (packet_id_t /*packet_id*/, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + if (chk.passed("h_publish1")) { + c->force_disconnect(); + } + } + ); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/system/st_resend_2.cpp b/test/system/st_resend_2.cpp new file mode 100644 index 000000000..ba005af1c --- /dev/null +++ b/test/system/st_resend_2.cpp @@ -0,0 +1,1031 @@ +// Copyright Takatoshi Kondo 2015 +// +// 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) + +#include "../common/test_main.hpp" +#include "combi_test.hpp" +#include "checker.hpp" +#include "ordered_caller.hpp" +#include "test_util.hpp" +#include "../common/global_fixture.hpp" + +BOOST_AUTO_TEST_SUITE(st_resend2) + +using namespace MQTT_NS::literals; + +BOOST_AUTO_TEST_CASE( publish_qos1 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS1 + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_puback"), + // disconnect + cont("h_close2"), + }; + + MQTT_NS::v5::properties ps { + MQTT_NS::v5::property::payload_format_indicator(MQTT_NS::v5::property::payload_format_indicator::string), + MQTT_NS::v5::property::message_expiry_interval(0x12345678UL), + MQTT_NS::v5::property::topic_alias(0x1234U), + MQTT_NS::v5::property::response_topic("response topic"_mb), + MQTT_NS::v5::property::correlation_data("correlation data"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + + std::size_t user_prop_count = 0; + b.set_publish_props_handler( + [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { + BOOST_TEST(props.size() == size); + + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::payload_format_indicator const& t) { + BOOST_TEST(t.val() == MQTT_NS::v5::property::payload_format_indicator::string); + }, + [&](MQTT_NS::v5::property::message_expiry_interval const& t) { + BOOST_TEST(t.val() == 0x12345678UL); + }, + [&](MQTT_NS::v5::property::topic_alias const& t) { + BOOST_TEST(t.val() == 0x1234U); + }, + [&](MQTT_NS::v5::property::response_topic const& t) { + BOOST_TEST(t.val() == "response topic"); + }, + [&](MQTT_NS::v5::property::correlation_data const& t) { + BOOST_TEST(t.val() == "correlation data"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + case 2: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 3: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + } + ); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_puback_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_pub, ps = std::move(ps)] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&, ps = std::move(ps)] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once | MQTT_NS::retain::no, std::move(ps)); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_puback_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_pubrec"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + }); + c->set_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + }); + c->set_v5_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( pubrel_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& b) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + cont("h_pubrec"), + // force_disconnect + cont("h_error"), + // connect + cont("h_connack3"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + MQTT_NS::v5::properties ps { + MQTT_NS::v5::property::reason_string("test success"_mb), + MQTT_NS::v5::property::user_property("key1"_mb, "val1"_mb), + MQTT_NS::v5::property::user_property("key2"_mb, "val2"_mb), + }; + std::size_t user_prop_count = 0; + + b.set_pubrel_props_handler( + [&user_prop_count, size = ps.size()] (MQTT_NS::v5::properties const& props) { + BOOST_TEST(props.size() == size); + for (auto const& p : props) { + MQTT_NS::visit( + MQTT_NS::make_lambda_visitor( + [&](MQTT_NS::v5::property::reason_string const& t) { + BOOST_TEST(t.val() == "test success"); + }, + [&](MQTT_NS::v5::property::user_property const& t) { + switch (user_prop_count++) { + case 0: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 1: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + case 2: + BOOST_TEST(t.key() == "key1"); + BOOST_TEST(t.val() == "val1"); + break; + case 3: + BOOST_TEST(t.key() == "key2"); + BOOST_TEST(t.val() == "val2"); + break; + default: + BOOST_TEST(false); + break; + } + }, + [&](auto&& ...) { + BOOST_TEST(false); + } + ), + p + ); + } + } + ); + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_pubcomp_handler( + [&chk, &c] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == 1); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_auto_pub_response(false); + c->set_v5_connack_handler( + [&chk, &c, &pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &c, &pid_pub, ps = std::move(ps)] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->pubrel(packet_id, MQTT_NS::v5::pubrel_reason_code::success, std::move(ps)); + c->force_disconnect(); + }); + c->set_v5_pubcomp_handler( + [&chk, &c] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == 1); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + +BOOST_AUTO_TEST_CASE( publish_pubrel_qos2 ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + // publish topic1 QoS2 + // force_disconnect + cont("h_error1"), + // connect + cont("h_connack3"), + cont("h_pubrec"), + // force_disconnect + cont("h_error2"), + // connect + cont("h_connack4"), + cont("h_pubcomp"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c, & pid_pub] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + }, + [&] { + MQTT_CHK("h_connack4"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c, & pid_pub] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once); + c->force_disconnect(); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + }, + [&] { + MQTT_CHK("h_connack4"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_pubrec_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubrec_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubrec"); + BOOST_TEST(packet_id == pid_pub); + c->force_disconnect(); + }); + c->set_v5_pubcomp_handler( + [&chk, &c, &pid_pub] + (packet_id_t packet_id, MQTT_NS::v5::pubcomp_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_pubcomp"); + BOOST_TEST(packet_id == pid_pub); + c->disconnect(); + }); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_error1"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }, + [&] { + MQTT_CHK("h_error2"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + } + ); + BOOST_TEST(ret); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + + +BOOST_AUTO_TEST_CASE( publish_qos1_from_broker ) { + auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) { + auto& c = cs[0]; + clear_ordered(); + using packet_id_t = typename std::remove_reference_t::packet_id_t; + c->set_client_id("cid1"); + c->set_clean_session(true); + c->set_auto_pub_response(false); + + packet_id_t pid_pub; + + boost::asio::steady_timer tim(ioc); + + checker chk = { + cont("start"), + // connect + cont("h_connack1"), + // disconnect + cont("h_close1"), + // connect + cont("h_connack2"), + cont("h_suback"), + // publish topic1 QoS1 + cont("h_puback"), + deps("h_publish1", "h_suback"), + // force_disconnect + deps("h_error", "h_puback", "h_publish1"), + // connect + cont("h_connack3"), + cont("h_publish2"), + // disconnect + cont("h_close2"), + }; + + switch (c->get_protocol_version()) { + case MQTT_NS::protocol_version::v3_1_1: + c->set_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::connect_return_code connack_return_code) { + BOOST_TEST(connack_return_code == MQTT_NS::connect_return_code::accepted); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + BOOST_TEST(sp == false); + c->subscribe("topic1", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_suback_handler( + [&chk, &c] + (packet_id_t, std::vector results) { + MQTT_CHK("h_suback"); + BOOST_TEST(results.size() == 1U); + BOOST_TEST(results[0] == MQTT_NS::suback_return_code::success_maximum_qos_2); + c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + } + ); + c->set_publish_handler( + [&chk, &c, &pid_pub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_publish1"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + pid_pub = packet_id.value(); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + if (chk.passed("h_puback")) { + c->force_disconnect(); + } + }, + [&] { + MQTT_CHK("h_publish2"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + BOOST_TEST(packet_id.value() == pid_pub); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + c->puback(packet_id.value()); + c->disconnect(); + } + ); + BOOST_TEST(ret); + } + ); + c->set_puback_handler( + [&chk, &c] + (packet_id_t) { + MQTT_CHK("h_puback"); + if (chk.passed("h_publish1")) { + c->force_disconnect(); + } + } + ); + break; + case MQTT_NS::protocol_version::v5: + c->set_v5_connack_handler( + [&chk, &c] + (bool sp, MQTT_NS::v5::connect_reason_code connack_return_code, MQTT_NS::v5::properties /*props*/) { + BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success); + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_connack1"); + BOOST_TEST(sp == false); + c->disconnect(); + }, + [&] { + MQTT_CHK("h_connack2"); + // The previous connection is not set Session Expiry Interval. + // That means session state is cleared on close. + BOOST_TEST(sp == false); + c->subscribe("topic1", MQTT_NS::qos::exactly_once); + }, + [&] { + MQTT_CHK("h_connack3"); + BOOST_TEST(sp == true); + } + ); + BOOST_TEST(ret); + }); + c->set_v5_suback_handler( + [&chk, &c] + (packet_id_t /*packet_id*/, std::vector reasons, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_suback"); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons.size() == 1U); + BOOST_TEST(reasons[0] == MQTT_NS::v5::suback_reason_code::granted_qos_2); + c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once); + } + ); + c->set_v5_publish_handler( + [&chk, &c, &pid_pub] + (MQTT_NS::optional packet_id, + MQTT_NS::publish_options pubopts, + MQTT_NS::buffer topic, + MQTT_NS::buffer contents, + MQTT_NS::v5::properties /*props*/) { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_publish1"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::no); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + pid_pub = packet_id.value(); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + if (chk.passed("h_puback")) { + c->force_disconnect(); + } + }, + [&] { + MQTT_CHK("h_publish2"); + BOOST_TEST(pubopts.get_dup() == MQTT_NS::dup::yes); + BOOST_TEST(pubopts.get_qos() == MQTT_NS::qos::at_least_once); + BOOST_TEST(pubopts.get_retain() == MQTT_NS::retain::no); + BOOST_CHECK(packet_id); + BOOST_TEST(packet_id.value() == pid_pub); + BOOST_TEST(topic == "topic1"); + BOOST_TEST(contents == "topic1_contents"); + c->puback(packet_id.value()); + c->disconnect(); + } + ); + BOOST_TEST(ret); + } + ); + c->set_v5_puback_handler( + [&chk, &c] + (packet_id_t /*packet_id*/, MQTT_NS::v5::puback_reason_code, MQTT_NS::v5::properties /*props*/) { + MQTT_CHK("h_puback"); + if (chk.passed("h_publish1")) { + c->force_disconnect(); + } + } + ); + break; + default: + BOOST_CHECK(false); + break; + } + + c->set_close_handler( + [&chk, &c, &finish] + () { + auto ret = MQTT_ORDERED( + [&] { + MQTT_CHK("h_close1"); + connect_no_clean(c); + }, + [&] { + MQTT_CHK("h_close2"); + finish(); + } + ); + BOOST_TEST(ret); + }); + c->set_error_handler( + [&chk, &c, &tim] + (MQTT_NS::error_code) { + MQTT_CHK("h_error"); + // TCP level disconnection detecting timing is unpredictable. + // Sometimes broker first, sometimes the client (this test) first. + // This test assume that the broker detects first, so I set timer. + // If client detect the disconnection first, then reconnect with + // existing client id. And it is overwritten at broker. + // Then error handler in the broker called, assertion failed due to + // no corresponding connection exists + tim.expires_after(std::chrono::milliseconds(100)); + tim.async_wait( + [&c] (MQTT_NS::error_code ec) { + BOOST_ASSERT( ! ec); + connect_no_clean(c); + } + ); + }); + MQTT_CHK("start"); + c->connect(); + ioc.run(); + BOOST_TEST(chk.all()); + }; + do_combi_test_sync(test); +} + + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 34c4706f2..3b1d34819 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -10,7 +10,7 @@ IF (POLICY CMP0074) CMAKE_POLICY(SET CMP0074 NEW) ENDIF () -IF (MQTT_TEST_1) +IF (MQTT_TEST_8) LIST (APPEND check_PROGRAMS ut_buffer.cpp ut_code.cpp