diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index e3ab0c5ab..8e003eebe 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4796,8 +4796,8 @@ class endpoint : public std::enable_shared_from_thispost( - [ - self = force_move(self), - session_life_keeper = force_move(session_life_keeper), - buf = force_move(buf), - size, - handler = force_move(handler) - ] - () mutable { - handler( - buf.substr(0, size), - buf.substr(size), - force_move(session_life_keeper), - force_move(self) - ); - } + handler( + buf.substr(0, size), + buf.substr(size), + force_move(session_life_keeper), + force_move(self) ); } } @@ -5285,27 +5275,17 @@ class endpoint : public std::enable_shared_from_thispost( - [ - self = force_move(self), - session_life_keeper = force_move(session_life_keeper), - buf = force_move(buf), - handler = force_move(handler) - ] - () mutable { - auto packet_id = - make_packet_id::apply( - buf.data(), - std::next(buf.data(), boost::numeric_cast(Bytes)) - ); - buf.remove_prefix(Bytes); - handler( - packet_id, - force_move(buf), - force_move(session_life_keeper), - force_move(self) - ); - } + auto packet_id = + make_packet_id::apply( + buf.data(), + std::next(buf.data(), boost::numeric_cast(Bytes)) + ); + buf.remove_prefix(Bytes); + handler( + packet_id, + force_move(buf), + force_move(session_life_keeper), + force_move(self) ); } } @@ -5409,26 +5389,13 @@ class endpoint : public std::enable_shared_from_thispost( - [ - session_life_keeper = force_move(session_life_keeper), - handler = force_move(handler), - buf = force_move(buf), - size, - multiplier, - proc = force_move(proc), - self = force_move(self) - ] - () mutable { - proc( - force_move(session_life_keeper), - force_move(buf), - force_move(handler), - size, - multiplier, - force_move(self) - ); - } + proc( + force_move(session_life_keeper), + force_move(buf), + force_move(handler), + size, + multiplier, + force_move(self) ); } } @@ -5585,25 +5552,13 @@ class endpoint : public std::enable_shared_from_thispost( - [ - this, - self = force_move(self), - session_life_keeper = force_move(session_life_keeper), - buf = force_move(buf), - handler = force_move(handler), - property_length - ] - () mutable { - process_property_id( - force_move(session_life_keeper), - force_move(buf), - property_length, - v5::properties(), - force_move(handler), - force_move(self) - ); - } + process_property_id( + force_move(session_life_keeper), + force_move(buf), + property_length, + v5::properties(), + force_move(handler), + force_move(self) ); } }, @@ -5654,29 +5609,16 @@ class endpoint : public std::enable_shared_from_thispost( - [ - this, - self = force_move(self), - session_life_keeper = force_move(session_life_keeper), - buf = force_move(buf), - props = force_move(props), - handler = force_move(handler), - property_length_rest - ] - () mutable { - auto id = static_cast(buf.front()); - buf.remove_prefix(1); - process_property_body( - force_move(session_life_keeper), - force_move(buf), - id, - property_length_rest - 1, - force_move(props), - force_move(handler), - force_move(self) - ); - } + auto id = static_cast(buf.front()); + buf.remove_prefix(1); + process_property_body( + force_move(session_life_keeper), + force_move(buf), + id, + property_length_rest - 1, + force_move(props), + force_move(handler), + force_move(self) ); } } diff --git a/test/system/CMakeLists.txt b/test/system/CMakeLists.txt index 1d5a1ab89..9bbe337af 100644 --- a/test/system/CMakeLists.txt +++ b/test/system/CMakeLists.txt @@ -59,6 +59,7 @@ ENDIF () IF (MQTT_TEST_7) LIST (APPEND check_PROGRAMS st_async_pubsub_2.cpp + st_issue_749.cpp st_broker_offline_message.cpp st_remaining_length.cpp st_utf8string_validate.cpp diff --git a/test/system/st_issue_749.cpp b/test/system/st_issue_749.cpp new file mode 100644 index 000000000..926a4d5d2 --- /dev/null +++ b/test/system/st_issue_749.cpp @@ -0,0 +1,86 @@ +// Copyright Takatoshi Kondo 2020 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include "../common/test_main.hpp" +#include "combi_test.hpp" +#include "checker.hpp" +#include "test_util.hpp" +#include "../common/global_fixture.hpp" + +BOOST_AUTO_TEST_SUITE(st_issue_749) + +using namespace MQTT_NS::literals; + +BOOST_AUTO_TEST_CASE( broker_assertion_fail ) { + + boost::asio::io_context iocb; + MQTT_NS::broker::broker_t b(iocb); + MQTT_NS::optional s; + + std::promise p; + auto f = p.get_future(); + std::thread th( + [&] { + s.emplace(iocb, b); + p.set_value(); + iocb.run(); + } + ); + f.wait(); + + auto finish = + [&] { + as::post( + iocb, + [&] { + s->close(); + } + ); + }; + + std::vector> client_th; + + std::size_t num_clients = 10; + + auto client_thread_func = + [] { + boost::asio::io_context ioc; + + int publish_count = 100; + + auto c1 = MQTT_NS::make_client(ioc, broker_url, broker_notls_port); + c1->set_clean_session(true); + c1->set_client_id("cid1"); + + c1->set_connack_handler( + [&c1, &publish_count] + (bool /*sp*/, MQTT_NS::connect_return_code /*connack_return_code*/) { + std::cout << "Publish: " << publish_count << std::endl; + for (std::size_t i = 0; i != 100; ++i) { + c1->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_most_once); + } + c1->disconnect(); + return true; + } + ); + + c1->connect(); + ioc.run(); + std::cout << "finished" << std::endl; + }; + + for (unsigned int i = 0; i != num_clients; ++i) { + client_th.push_back(std::make_shared(client_thread_func)); + } + + for(auto& th: client_th) { + th->join(); + } + finish(); + th.join(); +} + +BOOST_AUTO_TEST_SUITE_END()