From 062812ea89368c9797a9467d368c2642703818c2 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Mon, 9 May 2022 10:03:50 +0900 Subject: [PATCH 1/4] Fixed #934. Removed assignment operator from uuid construction. Removed boost::optional::has_value(). It doesn't exist in Boost 1.67.0. Removed `std::cout` from test code. --- include/mqtt/broker/uuid.hpp | 2 +- include/mqtt/setup_log.hpp | 1 + test/system/st_receive_maximum.cpp | 6 +++--- test/system/st_underlying_timeout.cpp | 15 ++++++++++----- test/unit/ut_broker_security.cpp | 3 ++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/mqtt/broker/uuid.hpp b/include/mqtt/broker/uuid.hpp index ba59a8db0..bf268e1b2 100644 --- a/include/mqtt/broker/uuid.hpp +++ b/include/mqtt/broker/uuid.hpp @@ -19,7 +19,7 @@ MQTT_BROKER_NS_BEGIN inline std::string create_uuid_string() { // See https://github.com/boostorg/uuid/issues/121 - thread_local auto gen = boost::uuids::random_generator(); + thread_local boost::uuids::random_generator gen; return boost::uuids::to_string(gen()); } diff --git a/include/mqtt/setup_log.hpp b/include/mqtt/setup_log.hpp index 2d3e8a038..fc596ae5e 100644 --- a/include/mqtt/setup_log.hpp +++ b/include/mqtt/setup_log.hpp @@ -138,6 +138,7 @@ void setup_log(severity_level threshold = severity_level::warning) { { "mqtt_cb", threshold }, { "mqtt_impl", threshold }, { "mqtt_broker", threshold }, + { "mqtt_test", threshold }, } ); } diff --git a/test/system/st_receive_maximum.cpp b/test/system/st_receive_maximum.cpp index 64bd8df28..ae853c6e0 100644 --- a/test/system/st_receive_maximum.cpp +++ b/test/system/st_receive_maximum.cpp @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE( sync ) { 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.has_value()); + BOOST_CHECK(packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "message1"); }, @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE( sync ) { 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.has_value()); + BOOST_CHECK(packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "message2"); }, @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE( sync ) { 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.has_value()); + BOOST_CHECK(packet_id); BOOST_TEST(topic == "topic1"); BOOST_TEST(contents == "message3"); c->disconnect(); diff --git a/test/system/st_underlying_timeout.cpp b/test/system/st_underlying_timeout.cpp index 2784c989b..abd7778bf 100644 --- a/test/system/st_underlying_timeout.cpp +++ b/test/system/st_underlying_timeout.cpp @@ -62,7 +62,8 @@ BOOST_AUTO_TEST_CASE( connect_ws_upg ) { [&] (MQTT_NS::error_code ec, auto) { if (ec) { - std::cout << ec.message() << std::endl; + MQTT_LOG("mqtt_test", error) + << "error:" << ec.message(); } BOOST_TEST(!ec); // intentionally don't call async_handshake (WS) @@ -129,7 +130,8 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { [&] (MQTT_NS::error_code ec, auto) { if (ec) { - std::cout << ec.message() << std::endl; + MQTT_LOG("mqtt_test", error) + << "error:" << ec.message(); } BOOST_TEST(!ec); // intentionally don't call async_handshake (TLS) @@ -194,7 +196,8 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { [&] (MQTT_NS::error_code ec, auto) { if (ec) { - std::cout << ec.message() << std::endl; + MQTT_LOG("mqtt_test", error) + << "error:" << ec.message(); } BOOST_TEST(!ec); @@ -203,7 +206,8 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { [&] (MQTT_NS::error_code ec) { if (ec) { - std::cout << ec.message() << std::endl; + MQTT_LOG("mqtt_test", error) + << "error:" << ec.message(); } BOOST_TEST(!ec); // intentionally don't call async_handshake (WS) @@ -272,7 +276,8 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { [&] (MQTT_NS::error_code ec, auto) { if (ec) { - std::cout << ec.message() << std::endl; + MQTT_LOG("mqtt_test", error) + << "error:" << ec.message(); } BOOST_TEST(!ec); // intentionally don't call async_handshake (TLS) diff --git a/test/unit/ut_broker_security.cpp b/test/unit/ut_broker_security.cpp index 0498759a0..f1606b8ce 100644 --- a/test/unit/ut_broker_security.cpp +++ b/test/unit/ut_broker_security.cpp @@ -383,7 +383,8 @@ BOOST_AUTO_TEST_CASE(check_publish_any) { try { load_config(security, value); } catch(std::exception &e) { - std::cout << e.what() << std::endl; + MQTT_LOG("mqtt_test", error) + << "exception:" << e.what(); } BOOST_CHECK(security.auth_pub("topic", "u1") == MQTT_NS::broker::security::authorization::type::deny); From 86c01ff63a60cac53c1887a59f74d2b4af51d780 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Tue, 10 May 2022 08:37:52 +0900 Subject: [PATCH 2/4] Fixed file inclusion. In order to use (internal) boost variant, mqtt/config.hpp must be included on the top of file. --- example/client_cli.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/client_cli.cpp b/example/client_cli.cpp index 970c1d73f..ba80c6491 100644 --- a/example/client_cli.cpp +++ b/example/client_cli.cpp @@ -4,6 +4,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#include + #include #include #include @@ -11,7 +13,9 @@ #include #include -#include +#include +#include +#include inline void print_props(std::string prefix, MQTT_NS::v5::properties const& props) { for (auto const& p : props) { From ed5cef220ee1d9bbb62c25da0a69d3f7c1b18bd0 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Wed, 11 May 2022 18:12:49 +0900 Subject: [PATCH 3/4] bench.cpp requires Boost 1.70.0 or later. So target adding condition is introduced. --- README.md | 1 + example/CMakeLists.txt | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ee7d3894..1aa10f3c7 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Important note https://github.com/redboltz/mqtt_cpp/wiki/News. ## Overview mqtt_cpp is a header only library. It requires C++14 and the Boost Libraries 1.67.0 or later. +example/bench.cpp requires the Boost Libraries 1.70.0 or later. If it is not satisfied, example/bench.cpp is excluded from cmake build target. Add mqtt_cpp/include to your include path. Then, include `mqtt_client_cpp.hpp` and/or `mqtt_server_cpp.hpp` as follows: diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 263760188..6930ade87 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -11,9 +11,14 @@ LIST (APPEND exec_PROGRAMS long_lived_client.cpp redirect.cpp broker.cpp - bench.cpp ) +IF (Boost_VERSION VERSION_GREATER_EQUAL 1.70.0) + LIST (APPEND exec_PROGRAMS + bench.cpp + ) +ENDIF () + IF (UNIX) LIST (APPEND exec_PROGRAMS client_cli.cpp From b7bfdcfed80a742b9eac120fbfbb7c976b6a6865 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Sat, 14 May 2022 22:16:05 +0900 Subject: [PATCH 4/4] Updated minimum required boost version to 1.74.0 from 1.67.0. It is required by websocket, broker, and bench. Updated documents. --- CHANGELOG.md | 7 +++++ CMakeLists.txt | 2 +- README.md | 7 ++--- cmake/Config.cmake.in | 2 +- example/CMakeLists.txt | 9 ++----- include/mqtt/string_view.hpp | 40 ++--------------------------- include/mqtt/tcp_endpoint.hpp | 6 ++--- include/mqtt/type_erased_socket.hpp | 6 ++--- include/mqtt/ws_endpoint.hpp | 16 +++--------- test/system/CMakeLists.txt | 2 +- test/unit/CMakeLists.txt | 4 +-- 11 files changed, 27 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 099c9d751..5cd1bfff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 13.0.0 +* <<<< breaking change >>>> Minimum boost requirement is 1.74.0. (#934) +* Modulized store. (#933) +* Improved compile times and memory consumption. (#931) +* Improved MQTT_STD_XXX behavior. (#929) +* Improved build system. (#927) + ## 12.1.0 * Improved CI (#930) * Improved MQTT_STD_XXX support (#929) diff --git a/CMakeLists.txt b/CMakeLists.txt index d653615f6..03f9e6e50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ ELSE () MESSAGE (STATUS "Logging disabled") SET (MQTT_BOOST_COMPONENTS system date_time program_options) ENDIF () -FIND_PACKAGE (Boost 1.67.0 REQUIRED COMPONENTS ${MQTT_BOOST_COMPONENTS}) +FIND_PACKAGE (Boost 1.74.0 REQUIRED COMPONENTS ${MQTT_BOOST_COMPONENTS}) IF (MQTT_NO_TS_EXECUTORS AND ((Boost_MAJOR_VERSION LESS 1) OR (Boost_MINOR_VERSION LESS 74))) MESSAGE(FATAL_ERROR "Boost version 1.74.0 or later is required for use with standard executors") diff --git a/README.md b/README.md index 1aa10f3c7..0c1050422 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MQTT client/server for C++14 based on Boost.Asio -Version 12.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 13.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. @@ -8,8 +8,7 @@ Important note https://github.com/redboltz/mqtt_cpp/wiki/News. ## Overview -mqtt_cpp is a header only library. It requires C++14 and the Boost Libraries 1.67.0 or later. -example/bench.cpp requires the Boost Libraries 1.70.0 or later. If it is not satisfied, example/bench.cpp is excluded from cmake build target. +mqtt_cpp is a header only library. It requires C++14 and the Boost Libraries 1.74.0 or later. Add mqtt_cpp/include to your include path. Then, include `mqtt_client_cpp.hpp` and/or `mqtt_server_cpp.hpp` as follows: @@ -118,8 +117,6 @@ make make test ``` -In order to build tests, you need to prepare the Boost Libraries 1.59.0. - ## Documents https://github.com/redboltz/mqtt_cpp/wiki diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index f74989210..f5e5f43ed 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1,7 +1,7 @@ SET (Boost_USE_MULTITHREADED ON) include(CMakeFindDependencyMacro) FIND_DEPENDENCY (Threads) -FIND_DEPENDENCY (Boost 1.67.0 COMPONENTS @MQTT_BOOST_COMPONENTS@) +FIND_DEPENDENCY (Boost 1.74.0 COMPONENTS @MQTT_BOOST_COMPONENTS@) @MQTT_DEPENDS_OPENSSL@ @MQTT_DEPENDS_ZLIB@ diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 6930ade87..8d1eae4d3 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -11,21 +11,16 @@ LIST (APPEND exec_PROGRAMS long_lived_client.cpp redirect.cpp broker.cpp + bench.cpp ) -IF (Boost_VERSION VERSION_GREATER_EQUAL 1.70.0) - LIST (APPEND exec_PROGRAMS - bench.cpp - ) -ENDIF () - IF (UNIX) LIST (APPEND exec_PROGRAMS client_cli.cpp ) ENDIF () -FIND_PACKAGE (Boost 1.67.0 REQUIRED COMPONENTS program_options) +FIND_PACKAGE (Boost 1.74.0 REQUIRED COMPONENTS program_options) IF (MQTT_USE_TLS) LIST (APPEND exec_PROGRAMS diff --git a/include/mqtt/string_view.hpp b/include/mqtt/string_view.hpp index e9d0b0515..6dc55641c 100644 --- a/include/mqtt/string_view.hpp +++ b/include/mqtt/string_view.hpp @@ -27,12 +27,6 @@ using std::basic_string_view; #include -#if !defined(MQTT_NO_BOOST_STRING_VIEW) - -#if BOOST_VERSION >= 106100 - -#define MQTT_NO_BOOST_STRING_VIEW 0 - #include #include @@ -45,48 +39,18 @@ using basic_string_view = boost::basic_string_view; } // namespace MQTT_NS -#if BOOST_VERSION < 106900 -namespace boost { -template -std::size_t hash_value(basic_string_view s) { - return hash_range(s.begin(), s.end()); -} -} - -#endif // BOOST_VERSION < 106900 - -#else // BOOST_VERSION >= 106100 - -#define MQTT_NO_BOOST_STRING_VIEW 1 - -#include - -namespace MQTT_NS { - -using string_view = boost::string_ref; - -template > -using basic_string_view = boost::basic_string_ref; - -} // namespace MQTT_NS - -#endif // BOOST_VERSION >= 106100 - - -#endif // !defined(MQTT_NO_BOOST_STRING_VIEW) - #endif // !defined(MQTT_STD_STRING_VIEW) namespace MQTT_NS { namespace detail { - + template T* to_address(T* p) noexcept { return p; } - + template auto to_address(const T& p) noexcept { diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 774181b02..c46a289a8 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -115,15 +115,15 @@ class tcp_endpoint : public socket { tcp_.lowest_layer().close(ec); } -#if BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) MQTT_ALWAYS_INLINE as::executor get_executor() override final { return lowest_layer().get_executor(); } -#else // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) MQTT_ALWAYS_INLINE as::any_io_executor get_executor() override final { return lowest_layer().get_executor(); } -#endif // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) auto& socket() { return tcp_; } auto const& socket() const { return tcp_; } diff --git a/include/mqtt/type_erased_socket.hpp b/include/mqtt/type_erased_socket.hpp index d83335ce7..02788247b 100644 --- a/include/mqtt/type_erased_socket.hpp +++ b/include/mqtt/type_erased_socket.hpp @@ -34,11 +34,11 @@ class socket { virtual void clean_shutdown_and_close(boost::system::error_code&) = 0; virtual void async_clean_shutdown_and_close(std::function) = 0; virtual void force_shutdown_and_close(boost::system::error_code&) = 0; -#if BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) virtual as::executor get_executor() = 0; -#else // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) virtual as::any_io_executor get_executor() = 0; -#endif // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) }; } // namespace MQTT_NS diff --git a/include/mqtt/ws_endpoint.hpp b/include/mqtt/ws_endpoint.hpp index 4869b0551..22b200c26 100644 --- a/include/mqtt/ws_endpoint.hpp +++ b/include/mqtt/ws_endpoint.hpp @@ -155,20 +155,10 @@ class ws_endpoint : public socket { return strand_.running_in_this_thread(); } -#if BOOST_VERSION >= 107000 - MQTT_ALWAYS_INLINE as::ip::tcp::socket::lowest_layer_type& lowest_layer() override final { return boost::beast::get_lowest_layer(ws_); } -#else // BOOST_VERSION >= 107000 - - MQTT_ALWAYS_INLINE as::ip::tcp::socket::lowest_layer_type& lowest_layer() override final { - return ws_.lowest_layer(); - } - -#endif // BOOST_VERSION >= 107000 - MQTT_ALWAYS_INLINE any native_handle() override final { return next_layer().native_handle(); } @@ -240,15 +230,15 @@ class ws_endpoint : public socket { lowest_layer().close(ec); } -#if BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) MQTT_ALWAYS_INLINE as::executor get_executor() override final { return lowest_layer().get_executor(); } -#else // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) MQTT_ALWAYS_INLINE as::any_io_executor get_executor() override final { return lowest_layer().get_executor(); } -#endif // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) typename boost::beast::websocket::stream::next_layer_type& next_layer() { return ws_.next_layer(); diff --git a/test/system/CMakeLists.txt b/test/system/CMakeLists.txt index 4047bc6f4..3196c764c 100644 --- a/test/system/CMakeLists.txt +++ b/test/system/CMakeLists.txt @@ -72,7 +72,7 @@ IF (MQTT_TEST_7) ) ENDIF () -FIND_PACKAGE (Boost 1.67.0 REQUIRED COMPONENTS unit_test_framework) +FIND_PACKAGE (Boost 1.74.0 REQUIRED COMPONENTS unit_test_framework) # Without this setting added, azure pipelines completely fails to find the boost libraries. No idea why. IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index fba23dbb5..34c4706f2 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -25,11 +25,11 @@ IF (MQTT_TEST_1) ut_subscription_map_broker.cpp ut_retained_topic_map_broker.cpp ut_value_allocator.cpp - ut_broker_security.cpp + ut_broker_security.cpp ) ENDIF () -FIND_PACKAGE (Boost 1.67.0 REQUIRED COMPONENTS unit_test_framework) +FIND_PACKAGE (Boost 1.74.0 REQUIRED COMPONENTS unit_test_framework) # Without this setting added, azure pipelines completely fails to find the boost libraries. No idea why. IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")