diff --git a/.github/depends/boost.sh b/.github/depends/boost.sh index c245042c1..35ed368ee 100755 --- a/.github/depends/boost.sh +++ b/.github/depends/boost.sh @@ -33,9 +33,9 @@ while getopts "b:t:" c; do esac done -wget https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2 -tar xf boost_1_72_0.tar.bz2 -cd boost_1_72_0 +wget https://sourceforge.net/projects/boost/files/boost/1.76.0/boost_1_76_0.tar.bz2 +tar xf boost_1_76_0.tar.bz2 +cd boost_1_76_0 ./bootstrap.sh build() diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 89f039292..33a484813 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -56,7 +56,7 @@ jobs: uses: actions/cache@v1 with: path: usr - key: ${{ runner.os }}-boost-20200107 + key: ${{ runner.os }}-boost-20200816 - name: Build boost if: steps.cache-boost.outputs.cache-hit != 'true' run: ./.github/depends/boost.sh -b 64 -t gcc @@ -73,14 +73,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=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=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 -DMQTT_NO_TS_EXECUTORS=OFF" echo "begin" echo ${{env.BOOST_ROOT}} diff --git a/CMakeLists.txt b/CMakeLists.txt index e30f2a790..255da1162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ OPTION(MQTT_STD_STRING_VIEW "Use std::string_view from C++17 instead of boost::s OPTION(MQTT_STD_ANY "Use std::any from C++17 instead of boost::any" OFF) OPTION(MQTT_STD_SHARED_PTR_ARRAY "Use std::shared_ptr from C++17 instead of boost::shared_ptr" OFF) OPTION(MQTT_DISABLE_LIBSTDCXX_TUPLE_ANY_WORKAROUND "std::tuple workaround for libstdc++" OFF) +OPTION(MQTT_NO_TS_EXECUTORS "Use standard executors instead of Networking TS-style executors" OFF) IF (POLICY CMP0074) CMAKE_POLICY(SET CMP0074 NEW) @@ -87,6 +88,12 @@ ELSE () MESSAGE (STATUS "std::tuple workaround for libstdc++ enabled") ENDIF () +IF (MQTT_NO_TS_EXECUTORS) + MESSAGE (STATUS "Using standard executors instead of Networking TS-style executors") +ELSE () + MESSAGE (STATUS "Using Networking TS-style executors instead of standard executors") +ENDIF () + IF ( MQTT_STD_VARIANT OR MQTT_STD_OPTIONAL @@ -129,6 +136,10 @@ ELSE () FIND_PACKAGE (Boost 1.67.0 REQUIRED COMPONENTS system date_time program_options) ENDIF () +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") +ENDIF () + IF (MQTT_USE_TLS) FIND_PACKAGE (OpenSSL REQUIRED) IF (MQTT_USE_STATIC_OPENSSL) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 73f704b6a..2024defef 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -36,6 +36,7 @@ TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:M TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_STD_STRING_VIEW>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_STD_SHARED_PTR_ARRAY>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_DISABLE_LIBSTDCXX_TUPLE_ANY_WORKAROUND>) +TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_NO_TS_EXECUTORS>) # You might wonder why we don't simply add the list of header files to the check_deps # executable directly, and let cmake figure everything out on it's own. diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 5fa308302..417845909 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -25,7 +25,7 @@ class async_client : public client { * Constructor used by factory functions at the end of this file. */ template - async_client(constructor_access, Args && ... args) + explicit async_client(constructor_access, Args && ... args) : async_client(std::forward(args)...) { } @@ -36,7 +36,16 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -46,7 +55,16 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -59,7 +77,16 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -70,7 +97,16 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -82,7 +118,16 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +137,16 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +159,16 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +179,16 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -128,7 +200,17 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -138,7 +220,17 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -151,7 +243,17 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -162,7 +264,17 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -174,7 +286,17 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +306,17 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +329,17 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +350,17 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -271,9 +423,23 @@ class async_client : public client { } }; -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client>; + using async_client_t = async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -286,7 +452,16 @@ make_async_client(as::io_context& ioc, std::string host, std::string port, proto ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_async_client( ioc, @@ -296,9 +471,23 @@ make_async_client(as::io_context& ioc, std::string host, std::uint16_t port, pro ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client>; + using async_client_t = async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -311,7 +500,16 @@ make_async_client_no_strand(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_async_client_no_strand( ioc, @@ -323,9 +521,23 @@ make_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_WS) -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client>; + using async_client_t = async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -336,7 +548,16 @@ make_async_client_ws(as::io_context& ioc, std::string host, std::string port, st ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_async_client_ws( ioc, @@ -347,9 +568,23 @@ make_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client>; + using async_client_t = async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -360,7 +595,16 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_async_client_no_strand_ws( ioc, @@ -375,9 +619,23 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client< + tcp_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -390,7 +648,16 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -400,9 +667,23 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client< + tcp_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -415,7 +696,16 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -427,9 +717,23 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client< + ws_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -440,7 +744,16 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -451,9 +764,23 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client< + ws_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -464,7 +791,16 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -482,9 +818,25 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::u // 32bit Packet Id (experimental) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, 4>; + using async_client_t = async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -497,7 +849,17 @@ make_async_client_32(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_async_client_32( ioc, @@ -507,9 +869,25 @@ make_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, 4>; + using async_client_t = async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -522,7 +900,17 @@ make_async_client_no_strand_32(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_async_client_no_strand_32( ioc, @@ -534,9 +922,25 @@ make_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, 4>; + using async_client_t = async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -547,7 +951,17 @@ make_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_async_client_ws_32( ioc, @@ -558,9 +972,25 @@ make_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, 4>; + using async_client_t = async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -571,7 +1001,17 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_async_client_no_strand_ws_32( ioc, @@ -586,9 +1026,25 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -601,7 +1057,17 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -611,9 +1077,25 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -626,7 +1108,17 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -638,9 +1130,25 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -651,7 +1159,17 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -662,9 +1180,25 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -675,7 +1209,17 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + async_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index cef7de193..4c30d0941 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -21,11 +21,11 @@ #include #include -#include #include #include - #include +#include +#include namespace MQTT_NS { @@ -45,7 +45,7 @@ class client : public endpoint { * Constructor used by factory functions at the end of this file. */ template - client(constructor_access, Args && ... args) + explicit client(constructor_access, Args && ... args) : client(std::forward(args)...) { } @@ -56,7 +56,16 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -66,7 +75,16 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -79,7 +97,16 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -90,7 +117,16 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -102,7 +138,16 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -112,7 +157,16 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -125,7 +179,16 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -136,7 +199,16 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -148,7 +220,17 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -158,7 +240,17 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -171,7 +263,17 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -182,7 +284,17 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -194,7 +306,17 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -204,7 +326,17 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -217,7 +349,17 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -228,7 +370,17 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -1409,9 +1561,23 @@ class client : public endpoint { #endif // defined(MQTT_USE_WS) }; -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client>; + using client_t = client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1424,7 +1590,16 @@ make_client(as::io_context& ioc, std::string host, std::string port, protocol_ve ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_client( ioc, @@ -1434,9 +1609,23 @@ make_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_ ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client>; + using client_t = client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1449,7 +1638,16 @@ make_client_no_strand(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_client_no_strand( ioc, @@ -1461,9 +1659,23 @@ make_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, #if defined(MQTT_USE_WS) -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client>; + using client_t = client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1474,7 +1686,16 @@ make_client_ws(as::io_context& ioc, std::string host, std::string port, std::str ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_client_ws( ioc, @@ -1485,9 +1706,23 @@ make_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::s ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client>; + using client_t = client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1498,7 +1733,16 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_client_no_strand_ws( ioc, @@ -1513,9 +1757,23 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client< + tcp_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1528,7 +1786,16 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1538,9 +1805,23 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client< + tcp_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1553,7 +1834,16 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1565,9 +1855,23 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client< + ws_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1578,7 +1882,16 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1589,9 +1902,23 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client< + ws_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1602,7 +1929,16 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1620,9 +1956,25 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_ // 32bit Packet Id (experimental) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, 4>; + using client_t = client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1635,7 +1987,17 @@ make_client_32(as::io_context& ioc, std::string host, std::string port, protocol ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_client_32( ioc, @@ -1645,9 +2007,25 @@ make_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protoc ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, 4>; + using client_t = client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1660,7 +2038,17 @@ make_client_no_strand_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_client_no_strand_32( ioc, @@ -1672,9 +2060,25 @@ make_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_WS) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, 4>; + using client_t = client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1685,7 +2089,17 @@ make_client_ws_32(as::io_context& ioc, std::string host, std::string port, std:: ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_client_ws_32( ioc, @@ -1696,9 +2110,25 @@ make_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, 4>; + using client_t = client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1709,7 +2139,17 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_client_no_strand_ws_32( ioc, @@ -1724,9 +2164,25 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1739,7 +2195,17 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1749,9 +2215,25 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1764,7 +2246,17 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1776,9 +2268,25 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client< + ws_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1789,7 +2297,17 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1800,9 +2318,25 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1813,7 +2347,17 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/config.hpp b/include/mqtt/config.hpp index f1c005c9e..87f29dc80 100644 --- a/include/mqtt/config.hpp +++ b/include/mqtt/config.hpp @@ -31,4 +31,26 @@ #endif // !defined(MQTT_STD_VARIANT) + +// Check whether to use standard executors only +#if defined(MQTT_NO_TS_EXECUTORS) + +// Determine Boost Asio version +#include + +// Make sure standard executors are supported by Boost Asio +#if BOOST_ASIO_VERSION < 101800 +#error Boost Asio version 1.18.0 required for no TS-style executors +#endif // BOOST_ASIO_VERSION < 101800 + +#else // defined(MQTT_NO_TS_EXECUTORS) + +// Force no TS executors if Boost Asio accepts these only +#if defined(BOOST_ASIO_NO_TS_EXECUTORS) +#define MQTT_NO_TS_EXECUTORS +#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS) + +#endif // defined(MQTT_NO_TS_EXECUTORS) + + #endif // MQTT_CONFIG_HPP diff --git a/include/mqtt/null_strand.hpp b/include/mqtt/null_strand.hpp index 4e72480e9..80cc3cf3d 100644 --- a/include/mqtt/null_strand.hpp +++ b/include/mqtt/null_strand.hpp @@ -17,8 +17,18 @@ namespace MQTT_NS { namespace as = boost::asio; +// Determines which strand to use +#if defined(MQTT_NO_TS_EXECUTORS) + +// Using standard executor style null_strand / simple executor +using null_strand = as::io_context::executor_type; + +#else // defined(MQTT_NO_TS_EXECUTORS) + +namespace detail { + struct null_strand { - null_strand(as::io_context& ioc) noexcept : ioc_(ioc) {} + explicit null_strand(as::io_context& ioc) noexcept : ioc_(ioc) {} template void post(Func&& f, Allocator) const { as::post( @@ -49,6 +59,11 @@ struct null_strand { as::io_context& ioc_; }; +} // namespace detail + +// Use networking TS style null_strand +using null_strand = detail::null_strand; + inline bool operator==(null_strand const& lhs, null_strand const& rhs) { return std::addressof(lhs) == std::addressof(rhs); } @@ -57,8 +72,13 @@ inline bool operator!=(null_strand const& lhs, null_strand const& rhs) { return !(lhs == rhs); } +#endif // defined(MQTT_NO_TS_EXECUTORS) + } // namespace MQTT_NS + +#if !defined(MQTT_NO_TS_EXECUTORS) + namespace boost { namespace asio { @@ -69,4 +89,6 @@ struct is_executor : std::true_type { } // namespace asio } // namespace boost +#endif // !defined(MQTT_NO_TS_EXECUTORS) + #endif // MQTT_NULL_STRAND_HPP diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 4fef99489..f0f7b5d57 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -16,9 +16,10 @@ #include #include -#include #include #include +#include +#include namespace MQTT_NS { @@ -37,7 +38,7 @@ class server_endpoint : public endpoint { }; template < - typename Strand = as::io_context::strand, + typename Strand = strand, typename Mutex = std::mutex, template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2 @@ -195,7 +196,7 @@ class server { #if defined(MQTT_USE_TLS) template < - typename Strand = as::io_context::strand, + typename Strand = strand, typename Mutex = std::mutex, template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2 @@ -419,7 +420,7 @@ class server_tls { #if defined(MQTT_USE_WS) template < - typename Strand = as::io_context::strand, + typename Strand = strand, typename Mutex = std::mutex, template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2 @@ -684,7 +685,7 @@ class server_ws { #if defined(MQTT_USE_TLS) template < - typename Strand = as::io_context::strand, + typename Strand = strand, typename Mutex = std::mutex, template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2 diff --git a/include/mqtt/strand.hpp b/include/mqtt/strand.hpp new file mode 100644 index 000000000..1046a00f8 --- /dev/null +++ b/include/mqtt/strand.hpp @@ -0,0 +1,33 @@ +// 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) + +#if !defined(MQTT_STRAND_HPP) +#define MQTT_STRAND_HPP + +#include +#include + +#include + +namespace MQTT_NS { + +namespace as = boost::asio; + +// Determines which strand to use +#if defined(MQTT_NO_TS_EXECUTORS) + +// Use standard executor style strand +using strand = as::strand; + +#else // defined(MQTT_NO_TS_EXECUTORS) + +// Use networking TS style strand +using strand = as::io_context::strand; + +#endif // defined(MQTT_NO_TS_EXECUTORS) +} + +#endif // MQTT_STRAND_HPP diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 2cc2c4305..bda9e5e2d 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -25,7 +25,7 @@ class sync_client : public client { * Constructor used by factory functions at the end of this file. */ template - sync_client(constructor_access, Args && ... args) + explicit sync_client(constructor_access, Args && ... args) : sync_client(std::forward(args)...) { } @@ -36,7 +36,16 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -46,7 +55,16 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -59,7 +77,16 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -70,7 +97,16 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -82,7 +118,16 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +137,16 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +159,16 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +179,16 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -128,7 +200,17 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -138,7 +220,17 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -151,7 +243,17 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -162,7 +264,17 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) @@ -174,7 +286,17 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +306,17 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +329,17 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +350,17 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -268,9 +420,23 @@ class sync_client : public client { } }; -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client>; + using sync_client_t = sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -283,7 +449,16 @@ make_sync_client(as::io_context& ioc, std::string host, std::string port, protoc ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_sync_client( ioc, @@ -293,9 +468,22 @@ make_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, prot ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client>; + using sync_client_t = sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -308,7 +496,16 @@ make_sync_client_no_strand(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_sync_client_no_strand( ioc, @@ -320,9 +517,23 @@ make_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_WS) -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client>; + using sync_client_t = sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -333,7 +544,16 @@ make_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + > + > + > + > make_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_sync_client_ws( ioc, @@ -344,9 +564,23 @@ make_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, s ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client>; + using sync_client_t = sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -357,7 +591,16 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + > + > + > + > make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_sync_client_no_strand_ws( ioc, @@ -372,9 +615,23 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client< + tcp_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +644,16 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +663,23 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client< + tcp_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +692,16 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +713,23 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client< + ws_endpoint< + tls::stream, + strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +740,16 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + > + > + > + > make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +760,23 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client< + ws_endpoint< + tls::stream, + null_strand + > + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +787,16 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + > + > + > + > make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -479,9 +814,25 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::ui // 32bit Packet Id (experimental) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, 4>; + using sync_client_t = sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -494,7 +845,17 @@ make_sync_client_32(as::io_context& ioc, std::string host, std::string port, pro ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_sync_client_32( ioc, @@ -504,9 +865,25 @@ make_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, p ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, 4>; + using sync_client_t = sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -519,7 +896,17 @@ make_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_sync_client_no_strand_32( ioc, @@ -531,9 +918,25 @@ make_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_WS) -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, 4>; + using sync_client_t = sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -544,7 +947,17 @@ make_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + strand + >, + 4 + > + > + > make_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_sync_client_ws_32( ioc, @@ -555,9 +968,25 @@ make_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, 4>; + using sync_client_t = sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -568,7 +997,17 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::str ); } -inline std::shared_ptr, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + as::ip::tcp::socket, + null_strand + >, + 4 + > + > + > make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_sync_client_no_strand_ws_32( ioc, @@ -583,9 +1022,25 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +1053,17 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +1073,25 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +1104,17 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + tcp_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +1126,25 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +1155,17 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + strand + >, + 4 + > + > + > make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +1176,25 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + >; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +1205,17 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr< + callable_overlay< + sync_client< + ws_endpoint< + tls::stream, + null_strand + >, + 4 + > + > + > make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 6d0aab01a..2b2ae313c 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -23,10 +23,14 @@ template class tcp_endpoint : public socket { public: template - tcp_endpoint(as::io_context& ioc, Args&&... args) + explicit tcp_endpoint(as::io_context& ioc, Args&&... args) :tcp_(ioc, std::forward(args)...), - strand_(ioc) { - } +#if defined(MQTT_NO_TS_EXECUTORS) + strand_(ioc.get_executor()) +#else + strand_(ioc) +#endif + {} MQTT_ALWAYS_INLINE void async_read( as::mutable_buffer buffers, diff --git a/include/mqtt/ws_endpoint.hpp b/include/mqtt/ws_endpoint.hpp index ff51c48ed..ff859f59b 100644 --- a/include/mqtt/ws_endpoint.hpp +++ b/include/mqtt/ws_endpoint.hpp @@ -26,9 +26,14 @@ template class ws_endpoint : public socket { public: template - ws_endpoint(as::io_context& ioc, Args&&... args) + explicit ws_endpoint(as::io_context& ioc, Args&&... args) :ws_(ioc, std::forward(args)...), - strand_(ioc) { +#if defined(MQTT_NO_TS_EXECUTORS) + strand_(ioc.get_executor()) +#else + strand_(ioc) +#endif + { ws_.binary(true); ws_.set_option( boost::beast::websocket::stream_base::decorator(