Skip to content

Commit

Permalink
Merge pull request #935 from redboltz/fix_934
Browse files Browse the repository at this point in the history
Fixed #934.
  • Loading branch information
redboltz authored May 14, 2022
2 parents a885735 + b7bfdcf commit 5bff3c8
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 78 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 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.

[MQTT v5 is supported](https://github.com/redboltz/mqtt_cpp/wiki/MQTT-v5) since version 4.0.0.

## Overview

mqtt_cpp is a header only library. It requires C++14 and the Boost Libraries 1.67.0 or later.
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:

Expand Down Expand Up @@ -117,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

Expand Down
2 changes: 1 addition & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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@

Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ IF (UNIX)
)
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
Expand Down
6 changes: 5 additions & 1 deletion example/client_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <mqtt/config.hpp>

#include <iostream>
#include <iomanip>
#include <fstream>

#include <boost/program_options.hpp>
#include <boost/format.hpp>

#include <mqtt_client_cpp.hpp>
#include <mqtt/setup_log.hpp>
#include <mqtt/sync_client.hpp>
#include <mqtt/unique_scope_guard.hpp>

inline void print_props(std::string prefix, MQTT_NS::v5::properties const& props) {
for (auto const& p : props) {
Expand Down
2 changes: 1 addition & 1 deletion include/mqtt/broker/uuid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions include/mqtt/setup_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
);
}
Expand Down
40 changes: 2 additions & 38 deletions include/mqtt/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ using std::basic_string_view;

#include <boost/version.hpp>

#if !defined(MQTT_NO_BOOST_STRING_VIEW)

#if BOOST_VERSION >= 106100

#define MQTT_NO_BOOST_STRING_VIEW 0

#include <boost/utility/string_view.hpp>
#include <boost/container_hash/hash_fwd.hpp>

Expand All @@ -45,48 +39,18 @@ using basic_string_view = boost::basic_string_view<CharT, Traits>;

} // namespace MQTT_NS

#if BOOST_VERSION < 106900
namespace boost {
template <class charT, class traits>
std::size_t hash_value(basic_string_view<charT, traits> s) {
return hash_range(s.begin(), s.end());
}
}

#endif // BOOST_VERSION < 106900

#else // BOOST_VERSION >= 106100

#define MQTT_NO_BOOST_STRING_VIEW 1

#include <boost/utility/string_ref.hpp>

namespace MQTT_NS {

using string_view = boost::string_ref;

template<class CharT, class Traits = std::char_traits<CharT> >
using basic_string_view = boost::basic_string_ref<CharT, Traits>;

} // 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<class T>
T* to_address(T* p) noexcept
{
return p;
}

template<class T>
auto to_address(const T& p) noexcept
{
Expand Down
6 changes: 3 additions & 3 deletions include/mqtt/tcp_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down
6 changes: 3 additions & 3 deletions include/mqtt/type_erased_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(error_code)>) = 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
Expand Down
16 changes: 3 additions & 13 deletions include/mqtt/ws_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<Socket>::next_layer_type& next_layer() {
return ws_.next_layer();
Expand Down
2 changes: 1 addition & 1 deletion test/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions test/system/st_receive_maximum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
Expand All @@ -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");
},
Expand All @@ -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();
Expand Down
15 changes: 10 additions & 5 deletions test/system/st_underlying_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion test/unit/ut_broker_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5bff3c8

Please sign in to comment.