diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4078eb0..1430fc63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 4.0.0 +### breaking changes +- Fixed multiple close problem. In order to do that endpoint become shared_ptr based design. #98, #100, #101, #102 +### other updates +- Refined documents. #97 +- Added TLS async_shutdown timeout. #99 + ## 3.0.0 ### breaking changes - Fixed inconsistent function names. #84, #89 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a553b46f..740bdb37b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # http://www.boost.org/LICENSE_1_0.txt) cmake_minimum_required (VERSION 3.13.0) -project(async_mqtt_iface VERSION 3.0.0) +project(async_mqtt_iface VERSION 4.0.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -107,7 +107,7 @@ if(DOXYGEN_FOUND) COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = async_mqtt" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile - COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NUMBER = 3.0.0" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NUMBER = 4.0.0" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMAND ${CMAKE_COMMAND} -E echo "RECURSIVE = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMAND ${CMAKE_COMMAND} -E echo "PREDEFINED = _DOXYGEN_ ASYNC_MQTT_USE_TLS ASYNC_MQTT_USE_WS" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include/async_mqtt" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile diff --git a/README.md b/README.md index 573295cf0..e2f5894d6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Asynchronous MQTT communication library. -Version 3.0.0 [![Actions Status](https://github.com/redboltz/async_mqtt/workflows/CI/badge.svg)](https://github.com/redboltz/async_mqtt/actions)[![codecov](https://codecov.io/gh/redboltz/async_mqtt/branch/main/graph/badge.svg)](https://codecov.io/gh/redboltz/async_mqtt) +Version 4.0.0 [![Actions Status](https://github.com/redboltz/async_mqtt/workflows/CI/badge.svg)](https://github.com/redboltz/async_mqtt/actions)[![codecov](https://codecov.io/gh/redboltz/async_mqtt/branch/main/graph/badge.svg)](https://codecov.io/gh/redboltz/async_mqtt) This is Boost.Asio oriented asynchronous MQTT communication library. You can use async_mqtt to develop not only your MQTT client application but also your server (e.g. broker). Based on https://github.com/redboltz/mqtt_cpp experience, there are many improvements. See overview. diff --git a/example/ep_cb_mqtt_client.cpp b/example/ep_cb_mqtt_client.cpp index 0acc86331..1fd850c56 100644 --- a/example/ep_cb_mqtt_client.cpp +++ b/example/ep_cb_mqtt_client.cpp @@ -23,10 +23,10 @@ int main(int argc, char* argv[]) { as::io_context ioc; as::ip::tcp::socket resolve_sock{ioc}; as::ip::tcp::resolver res{resolve_sock.get_executor()}; - am::endpoint amep { + auto amep = am::endpoint::create( am::protocol_version::v3_1_1, ioc.get_executor() - }; + ); std::cout << "start" << std::endl; std::size_t count = 0; @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) { // Underlying TCP connect as::async_connect( - amep.next_layer(), + amep->next_layer(), eps, [&] (boost::system::error_code ec, as::ip::tcp::endpoint /*unused*/) { @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) { << std::endl; if (ec) return; // Send MQTT CONNECT - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -70,7 +70,7 @@ int main(int argc, char* argv[]) { return; } // Recv MQTT CONNACK - amep.recv( + amep->recv( [&] (am::packet_variant pv) { if (pv) { @@ -82,9 +82,9 @@ int main(int argc, char* argv[]) { << " sp:" << p.session_present() << std::endl; // Send MQTT SUBSCRIBE - amep.send( + amep->send( am::v3_1_1::subscribe_packet{ - *amep.acquire_unique_packet_id(), + *amep->acquire_unique_packet_id(), { {am::allocate_buffer("topic1"), am::qos::at_most_once} } }, [&] @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) { return; } // Recv MQTT SUBACK - amep.recv( + amep->recv( [&] (am::packet_variant pv) { if (pv) { @@ -110,9 +110,9 @@ int main(int argc, char* argv[]) { } std::cout << std::endl; // Send MQTT PUBLISH - amep.send( + amep->send( am::v3_1_1::publish_packet{ - *amep.acquire_unique_packet_id(), + *amep->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -152,11 +152,11 @@ int main(int argc, char* argv[]) { } ); if (++count < 2) { - amep.recv(*recv_handler); + amep->recv(*recv_handler); } else { std::cout << "close" << std::endl; - amep.close([]{}); + amep->close([]{}); } } else { @@ -167,7 +167,7 @@ int main(int argc, char* argv[]) { return; } }; - amep.recv(*recv_handler); + amep->recv(*recv_handler); } ); }, diff --git a/example/ep_cpp20coro_mqtt_client.cpp b/example/ep_cpp20coro_mqtt_client.cpp index 8a297e24e..753f19b98 100644 --- a/example/ep_cpp20coro_mqtt_client.cpp +++ b/example/ep_cpp20coro_mqtt_client.cpp @@ -19,10 +19,10 @@ as::awaitable proc(Executor exe, std::string_view host, std::string_view port) { as::ip::tcp::socket resolve_sock{exe}; as::ip::tcp::resolver res{exe}; - am::endpoint amep { + auto amep = am::endpoint::create( am::protocol_version::v3_1_1, exe - }; + ); std::cout << "start" << std::endl; try { @@ -35,14 +35,14 @@ proc(Executor exe, std::string_view host, std::string_view port) { // Underlying TCP connect co_await as::async_connect( - amep.next_layer(), + amep->next_layer(), eps, as::use_awaitable ); std::cout << "TCP connected" << std::endl; // Send MQTT CONNECT - if (auto se = co_await amep.send( + if (auto se = co_await amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -59,7 +59,7 @@ proc(Executor exe, std::string_view host, std::string_view port) { } // Recv MQTT CONNACK - if (am::packet_variant pv = co_await amep.recv(as::use_awaitable)) { + if (am::packet_variant pv = co_await amep->recv(as::use_awaitable)) { pv.visit( am::overload { [&](am::v3_1_1::connack_packet const& p) { @@ -84,9 +84,9 @@ proc(Executor exe, std::string_view host, std::string_view port) { std::vector sub_entry{ {am::allocate_buffer("topic1"), am::qos::at_most_once} }; - if (auto se = co_await amep.send( + if (auto se = co_await amep->send( am::v3_1_1::subscribe_packet{ - *amep.acquire_unique_packet_id(), + *amep->acquire_unique_packet_id(), am::force_move(sub_entry) // sub_entry variable is required to avoid g++ bug }, as::use_awaitable @@ -96,7 +96,7 @@ proc(Executor exe, std::string_view host, std::string_view port) { co_return; } // Recv MQTT SUBACK - if (am::packet_variant pv = co_await amep.recv(as::use_awaitable)) { + if (am::packet_variant pv = co_await amep->recv(as::use_awaitable)) { pv.visit( am::overload { [&](am::v3_1_1::suback_packet const& p) { @@ -121,9 +121,9 @@ proc(Executor exe, std::string_view host, std::string_view port) { co_return; } // Send MQTT PUBLISH - if (auto se = co_await amep.send( + if (auto se = co_await amep->send( am::v3_1_1::publish_packet{ - *amep.acquire_unique_packet_id(), + *amep->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -136,7 +136,7 @@ proc(Executor exe, std::string_view host, std::string_view port) { } // Recv MQTT PUBLISH and PUBACK (order depends on broker) for (std::size_t count = 0; count != 2; ++count) { - if (am::packet_variant pv = co_await amep.recv(as::use_awaitable)) { + if (am::packet_variant pv = co_await amep->recv(as::use_awaitable)) { pv.visit( am::overload { [&](am::v3_1_1::publish_packet const& p) { @@ -169,7 +169,7 @@ proc(Executor exe, std::string_view host, std::string_view port) { } } std::cout << "close" << std::endl; - co_await amep.close(as::use_awaitable); + co_await amep->close(as::use_awaitable); } catch (boost::system::system_error const& se) { std::cout << se.what() << std::endl; diff --git a/example/ep_future_mqtt_client.cpp b/example/ep_future_mqtt_client.cpp index 6353b4c45..710a3b0d9 100644 --- a/example/ep_future_mqtt_client.cpp +++ b/example/ep_future_mqtt_client.cpp @@ -24,10 +24,10 @@ int main(int argc, char* argv[]) { as::io_context ioc; as::ip::tcp::socket resolve_sock{ioc}; as::ip::tcp::resolver res{resolve_sock.get_executor()}; - am::endpoint amep { + auto amep = am::endpoint::create( am::protocol_version::v3_1_1, ioc.get_executor() - }; + ); // async_mqtt thread auto guard = as::make_work_guard(ioc.get_executor()); @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) { auto eps = f_res.get(); auto f_con = as::async_connect( - amep.next_layer(), + amep->next_layer(), eps, as::use_future ); @@ -65,7 +65,7 @@ int main(int argc, char* argv[]) { // Send MQTT CONNECT { - auto fut = amep.send( + auto fut = amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) { // Recv MQTT CONNACK { - auto fut = amep.recv(as::use_future); + auto fut = amep->recv(as::use_future); auto pv = fut.get(); // get am::packet_variant if (pv) { pv.visit( @@ -112,9 +112,9 @@ int main(int argc, char* argv[]) { // Send MQTT SUBSCRIBE { - auto fut_id = amep.acquire_unique_packet_id(as::use_future); + auto fut_id = amep->acquire_unique_packet_id(as::use_future); auto pid = fut_id.get(); - auto fut = amep.send( + auto fut = amep->send( am::v3_1_1::subscribe_packet{ *pid, { {am::allocate_buffer("topic1"), am::qos::at_most_once} } @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) { // Recv MQTT SUBACK { - auto fut = amep.recv(as::use_future); + auto fut = amep->recv(as::use_future); auto pv = fut.get(); if (pv) { pv.visit( @@ -160,9 +160,9 @@ int main(int argc, char* argv[]) { // Send MQTT PUBLISH { - auto fut_id = amep.acquire_unique_packet_id(as::use_future); + auto fut_id = amep->acquire_unique_packet_id(as::use_future); auto pid = fut_id.get(); - auto fut = amep.send( + auto fut = amep->send( am::v3_1_1::publish_packet{ *pid, am::allocate_buffer("topic1"), @@ -181,7 +181,7 @@ int main(int argc, char* argv[]) { // Recv MQTT PUBLISH and PUBACK (order depends on broker) { for (std::size_t count = 0; count != 2; ++count) { - auto fut = amep.recv(as::use_future); + auto fut = amep->recv(as::use_future); auto pv = fut.get(); if (pv) { pv.visit( @@ -218,7 +218,7 @@ int main(int argc, char* argv[]) { } { std::cout << "close" << std::endl; - auto fut = amep.close(as::use_future); + auto fut = amep->close(as::use_future); fut.get(); } } diff --git a/example/ep_slcoro_mqtt_client.cpp b/example/ep_slcoro_mqtt_client.cpp index fad1f184d..da42031de 100644 --- a/example/ep_slcoro_mqtt_client.cpp +++ b/example/ep_slcoro_mqtt_client.cpp @@ -24,7 +24,7 @@ struct app { ):res_{exe}, host_{std::move(host)}, port_{std::move(port)}, - amep_{am::protocol_version::v3_1_1, exe} + amep_{am::endpoint::create(am::protocol_version::v3_1_1, exe)} { impl_(); } @@ -73,7 +73,7 @@ struct app { // Underlying TCP connect yield as::async_connect( - app_.amep_.next_layer(), + app_.amep_->next_layer(), *eps, *this ); @@ -85,7 +85,7 @@ struct app { if (ec) return; // Send MQTT CONNECT - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -102,7 +102,7 @@ struct app { } // Recv MQTT CONNACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -125,9 +125,9 @@ struct app { } // Send MQTT SUBSCRIBE - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::subscribe_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), { {am::allocate_buffer("topic1"), am::qos::at_most_once} } }, *this @@ -137,7 +137,7 @@ struct app { return; } // Recv MQTT SUBACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -163,9 +163,9 @@ struct app { return; } // Send MQTT PUBLISH - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::publish_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -178,7 +178,7 @@ struct app { } // Recv MQTT PUBLISH and PUBACK (order depends on broker) for (app_.count_ = 0; app_.count_ != 2; ++app_.count_) { - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -212,7 +212,7 @@ struct app { } } std::cout << "close" << std::endl; - yield app_.amep_.close(*this); + yield app_.amep_->close(*this); } } @@ -224,7 +224,7 @@ struct app { as::ip::tcp::resolver res_; std::string_view host_; std::string_view port_; - am::endpoint amep_; + std::shared_ptr> amep_; std::size_t count_ = 0; impl impl_{*this}; }; diff --git a/example/ep_slcoro_mqtts_client.cpp b/example/ep_slcoro_mqtts_client.cpp index 3f8cf8fcb..a27a64ad7 100644 --- a/example/ep_slcoro_mqtts_client.cpp +++ b/example/ep_slcoro_mqtts_client.cpp @@ -24,7 +24,11 @@ struct app { ):res_{exe}, host_{std::move(host)}, port_{std::move(port)}, - amep_{am::protocol_version::v3_1_1, exe, ctx_} + amep_{ + am::endpoint::create( + am::protocol_version::v3_1_1, exe, ctx_ + ) + } { ctx_.set_verify_mode(am::tls::verify_none); impl_(); @@ -74,7 +78,7 @@ struct app { // Underlying TCP connect yield as::async_connect( - app_.amep_.lowest_layer(), + app_.amep_->lowest_layer(), *eps, *this ); @@ -86,7 +90,7 @@ struct app { if (ec) return; // Underlying TLS handshake - yield app_.amep_.next_layer().async_handshake( + yield app_.amep_->next_layer().async_handshake( am::tls::stream_base::client, *this ); @@ -96,7 +100,7 @@ struct app { << std::endl; // Send MQTT CONNECT - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -113,7 +117,7 @@ struct app { } // Recv MQTT CONNACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -136,9 +140,9 @@ struct app { } // Send MQTT SUBSCRIBE - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::subscribe_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), { {am::allocate_buffer("topic1"), am::qos::at_most_once} } }, *this @@ -148,7 +152,7 @@ struct app { return; } // Recv MQTT SUBACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -174,9 +178,9 @@ struct app { return; } // Send MQTT PUBLISH - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::publish_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -189,7 +193,7 @@ struct app { } // Recv MQTT PUBLISH and PUBACK (order depends on broker) for (app_.count_ = 0; app_.count_ != 2; ++app_.count_) { - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -223,7 +227,7 @@ struct app { } } std::cout << "close" << std::endl; - yield app_.amep_.close(*this); + yield app_.amep_->close(*this); } } @@ -236,7 +240,7 @@ struct app { std::string_view host_; std::string_view port_; am::tls::context ctx_{am::tls::context::tlsv12}; - am::endpoint amep_; + std::shared_ptr> amep_; std::size_t count_ = 0; impl impl_{*this}; }; diff --git a/example/ep_slcoro_ws_client.cpp b/example/ep_slcoro_ws_client.cpp index 720d69bb6..240cb7273 100644 --- a/example/ep_slcoro_ws_client.cpp +++ b/example/ep_slcoro_ws_client.cpp @@ -24,7 +24,7 @@ struct app { ):res_{exe}, host_{std::move(host)}, port_{std::move(port)}, - amep_{am::protocol_version::v3_1_1, exe} + amep_{am::endpoint::create(am::protocol_version::v3_1_1, exe)} { impl_(); } @@ -73,7 +73,7 @@ struct app { // Underlying TCP connect yield as::async_connect( - app_.amep_.lowest_layer(), + app_.amep_->lowest_layer(), *eps, *this ); @@ -85,7 +85,7 @@ struct app { if (ec) return; // Underlying WS handshake - yield app_.amep_.next_layer().async_handshake( + yield app_.amep_->next_layer().async_handshake( app_.host_, "/", *this @@ -96,7 +96,7 @@ struct app { << std::endl; // Send MQTT CONNECT - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -113,7 +113,7 @@ struct app { } // Recv MQTT CONNACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -136,9 +136,9 @@ struct app { } // Send MQTT SUBSCRIBE - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::subscribe_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), { {am::allocate_buffer("topic1"), am::qos::at_most_once} } }, *this @@ -148,7 +148,7 @@ struct app { return; } // Recv MQTT SUBACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -174,9 +174,9 @@ struct app { return; } // Send MQTT PUBLISH - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::publish_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -189,7 +189,7 @@ struct app { } // Recv MQTT PUBLISH and PUBACK (order depends on broker) for (app_.count_ = 0; app_.count_ != 2; ++app_.count_) { - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -223,7 +223,7 @@ struct app { } } std::cout << "close" << std::endl; - yield app_.amep_.close(*this); + yield app_.amep_->close(*this); } } @@ -235,7 +235,7 @@ struct app { as::ip::tcp::resolver res_; std::string_view host_; std::string_view port_; - am::endpoint amep_; + std::shared_ptr> amep_; std::size_t count_ = 0; impl impl_{*this}; }; diff --git a/example/ep_slcoro_wss_client.cpp b/example/ep_slcoro_wss_client.cpp index a83a20bf2..85a34c218 100644 --- a/example/ep_slcoro_wss_client.cpp +++ b/example/ep_slcoro_wss_client.cpp @@ -24,7 +24,7 @@ struct app { ):res_{exe}, host_{std::move(host)}, port_{std::move(port)}, - amep_{am::protocol_version::v3_1_1, exe, ctx_} + amep_{am::endpoint::create(am::protocol_version::v3_1_1, exe, ctx_)} { ctx_.set_verify_mode(am::tls::verify_none); impl_(); @@ -74,7 +74,7 @@ struct app { // Underlying TCP connect yield as::async_connect( - app_.amep_.lowest_layer(), + app_.amep_->lowest_layer(), *eps, *this ); @@ -86,7 +86,7 @@ struct app { if (ec) return; // Underlying TLS handshake - yield app_.amep_.next_layer().next_layer().async_handshake( + yield app_.amep_->next_layer().next_layer().async_handshake( am::tls::stream_base::client, *this ); @@ -96,7 +96,7 @@ struct app { << std::endl; // Underlying WS handshake - yield app_.amep_.next_layer().async_handshake( + yield app_.amep_->next_layer().async_handshake( app_.host_, "/", *this @@ -107,7 +107,7 @@ struct app { << std::endl; // Send MQTT CONNECT - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -124,7 +124,7 @@ struct app { } // Recv MQTT CONNACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -147,9 +147,9 @@ struct app { } // Send MQTT SUBSCRIBE - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::subscribe_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), { {am::allocate_buffer("topic1"), am::qos::at_most_once} } }, *this @@ -159,7 +159,7 @@ struct app { return; } // Recv MQTT SUBACK - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -185,9 +185,9 @@ struct app { return; } // Send MQTT PUBLISH - yield app_.amep_.send( + yield app_.amep_->send( am::v3_1_1::publish_packet{ - *app_.amep_.acquire_unique_packet_id(), + *app_.amep_->acquire_unique_packet_id(), am::allocate_buffer("topic1"), am::allocate_buffer("payload1"), am::qos::at_least_once @@ -200,7 +200,7 @@ struct app { } // Recv MQTT PUBLISH and PUBACK (order depends on broker) for (app_.count_ = 0; app_.count_ != 2; ++app_.count_) { - yield app_.amep_.recv(*this); + yield app_.amep_->recv(*this); if (pv) { pv.visit( am::overload { @@ -234,7 +234,7 @@ struct app { } } std::cout << "close" << std::endl; - yield app_.amep_.close(*this); + yield app_.amep_->close(*this); } } @@ -247,7 +247,7 @@ struct app { std::string_view host_; std::string_view port_; am::tls::context ctx_{am::tls::context::tlsv12}; - am::endpoint amep_; + std::shared_ptr> amep_; std::size_t count_ = 0; impl impl_{*this}; }; diff --git a/include/async_mqtt/endpoint.hpp b/include/async_mqtt/endpoint.hpp index dba6bc4ec..88bf0ded2 100644 --- a/include/async_mqtt/endpoint.hpp +++ b/include/async_mqtt/endpoint.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,7 @@ enum class filter { * @tparam NextLayer Just next layer for basic_endpoint. mqtt, mqtts, ws, and wss are predefined. */ template -class basic_endpoint { +class basic_endpoint : public std::enable_shared_from_this>{ enum class connection_status { connecting, @@ -88,11 +89,15 @@ class basic_endpoint { } using this_type = basic_endpoint; + using this_type_sp = std::shared_ptr; using stream_type = stream< NextLayer >; + template + friend class make_shared_helper; + public: /// @brief The type given as NextLayer using next_layer_type = NextLayer; @@ -107,27 +112,21 @@ class basic_endpoint { /// @brief Type of MQTT Packet Identifier. using packet_id_t = typename packet_id_type::type; - /** - * @brief constructor - * @tparam Args Types for the next layer - * @param ver MQTT protocol version client can set v5 or v3_1_1, in addition - * server can set undetermined - * @param args args for the next layer. There are predefined next layer types: - * \n @link protocol::mqtt @endlink, @link protocol::mqtts @endlink, - * @link protocol::ws @endlink, and @link protocol::wss @endlink. - */ + template + friend std::shared_ptr std::make_shared(Args&&...); + template - basic_endpoint( + static std::shared_ptr create( protocol_version ver, Args&&... args - ): protocol_version_{ver}, - stream_{std::make_shared(std::forward(args)...)} - { - BOOST_ASSERT( - (Role == role::client && ver != protocol_version::undetermined) || - Role != role::client - ); + ) { + return make_shared_helper::make_shared(ver, std::forward(args)...); + } + ~basic_endpoint() { + ASYNC_MQTT_LOG("mqtt_impl", trace) + << ASYNC_MQTT_ADD_VALUE(address, this) + << "destroy"; } basic_endpoint(this_type const&) = delete; @@ -764,6 +763,29 @@ class basic_endpoint { private: // compose operation impl + /** + * @brief constructor + * @tparam Args Types for the next layer + * @param ver MQTT protocol version client can set v5 or v3_1_1, in addition + * server can set undetermined + * @param args args for the next layer. There are predefined next layer types: + * \n @link protocol::mqtt @endlink, @link protocol::mqtts @endlink, + * @link protocol::ws @endlink, and @link protocol::wss @endlink. + */ + template + basic_endpoint( + protocol_version ver, + Args&&... args + ): protocol_version_{ver}, + stream_{stream_type::create(std::forward(args)...)} + { + BOOST_ASSERT( + (Role == role::client && ver != protocol_version::undetermined) || + Role != role::client + ); + + } + struct acquire_unique_packet_id_impl { this_type& ep; enum { dispatch, complete } state = dispatch; @@ -2186,7 +2208,8 @@ class basic_endpoint { struct close_impl { this_type& ep; - enum { initiate, complete } state = initiate; + enum { dispatch, close, complete } state = dispatch; + this_type_sp life_keeper = ep.shared_from_this(); template void operator()( @@ -2194,7 +2217,15 @@ class basic_endpoint { error_code const& = error_code{} ) { switch (state) { - case initiate: + case dispatch: { + state = close; + auto& a_ep{ep}; + as::dispatch( + a_ep.strand(), + force_move(self) + ); + } break; + case close: switch (ep.status_) { case connection_status::connecting: case connection_status::connected: @@ -2221,26 +2252,23 @@ class basic_endpoint { << "already closed"; state = complete; self.complete(); - break; - } - break; - case complete: + } break; + case complete: { BOOST_ASSERT(ep.strand().running_in_this_thread()); ASYNC_MQTT_LOG("mqtt_impl", trace) << ASYNC_MQTT_ADD_VALUE(address, &ep) << "close complete status:" << static_cast(ep.status_); - ep.tim_pingreq_send_->cancel(); - ep.tim_pingreq_recv_->cancel(); - ep.tim_pingresp_recv_->cancel(); - ep.status_ = connection_status::closed; - while (!ep.close_queue_.stopped()) { - ASYNC_MQTT_LOG("mqtt_impl", trace) - << ASYNC_MQTT_ADD_VALUE(address, &ep) - << "process enqueued close"; - ep.close_queue_.poll_one(); - } + auto& a_ep{ep}; + a_ep.tim_pingreq_send_->cancel(); + a_ep.tim_pingreq_recv_->cancel(); + a_ep.tim_pingresp_recv_->cancel(); + a_ep.status_ = connection_status::closed; + ASYNC_MQTT_LOG("mqtt_impl", trace) + << ASYNC_MQTT_ADD_VALUE(address, &ep) + << "process enqueued close"; + a_ep.close_queue_.poll(); self.complete(); - break; + } break; } } }; diff --git a/include/async_mqtt/stream.hpp b/include/async_mqtt/stream.hpp index 8ca934055..bbb39d050 100644 --- a/include/async_mqtt/stream.hpp +++ b/include/async_mqtt/stream.hpp @@ -25,6 +25,7 @@ #endif // defined(ASYNC_MQTT_USE_WS) #include +#include #include #include #include @@ -66,25 +67,16 @@ class stream : public std::enable_shared_from_this> { using executor_type = async_mqtt::executor_type; using strand_type = as::strand; + template + friend class make_shared_helper; + template < typename T, typename... Args, std::enable_if_t, this_type>>* = nullptr > - explicit - stream(T&& t, Args&&... args) - :nl_{std::forward(t), std::forward(args)...} - { - if constexpr(is_ws::value) { - nl_.binary(true); - nl_.set_option( - bs::websocket::stream_base::decorator( - [](bs::websocket::request_type& req) { - req.set("Sec-WebSocket-Protocol", "mqtt"); - } - ) - ); - } + static std::shared_ptr create(T&& t, Args&&... args) { + return make_shared_helper::make_shared(std::forward(t), std::forward(args)...); } ~stream() { @@ -179,6 +171,28 @@ class stream : public std::enable_shared_from_this> { private: + // constructor + template < + typename T, + typename... Args, + std::enable_if_t, this_type>>* = nullptr + > + explicit + stream(T&& t, Args&&... args) + :nl_{std::forward(t), std::forward(args)...} + { + if constexpr(is_ws::value) { + nl_.binary(true); + nl_.set_option( + bs::websocket::stream_base::decorator( + [](bs::websocket::request_type& req) { + req.set("Sec-WebSocket-Protocol", "mqtt"); + } + ) + ); + } + } + struct read_packet_impl { read_packet_impl(this_type& strm):strm{strm} {} diff --git a/include/async_mqtt/util/ioc_queue.hpp b/include/async_mqtt/util/ioc_queue.hpp index 415f9d634..7a2bdf7f5 100644 --- a/include/async_mqtt/util/ioc_queue.hpp +++ b/include/async_mqtt/util/ioc_queue.hpp @@ -46,10 +46,16 @@ class ioc_queue { return queue_.stopped(); } - void poll_one() { + std::size_t poll_one() { working_ = false; if (queue_.stopped()) queue_.restart(); - queue_.poll_one(); + return queue_.poll_one(); + } + + std::size_t poll() { + working_ = false; + if (queue_.stopped()) queue_.restart(); + return queue_.poll(); } private: diff --git a/include/async_mqtt/util/make_shared_helper.hpp b/include/async_mqtt/util/make_shared_helper.hpp new file mode 100644 index 000000000..66f362061 --- /dev/null +++ b/include/async_mqtt/util/make_shared_helper.hpp @@ -0,0 +1,37 @@ +// Copyright Takatoshi Kondo 2022 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP) +#define ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP + +#include + +namespace async_mqtt { + +template +class make_shared_helper { + friend T; + struct target : public T { + template + target(Args&&... args) + :T{std::forward(args)...} + {} + }; + + template + static std::shared_ptr make_shared(Args&&... args) { + return std::make_shared(std::forward(args)...); + } + + template + static std::shared_ptr allocate_shared(Alloc const& alloc, Args&&... args) { + return std::allocate_shared(alloc, std::forward(args)...); + } +}; + +} // namespace async_mqtt + +#endif // ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP diff --git a/test/system/st_auth.cpp b/test/system/st_auth.cpp index d7db759f0..bd566a8c7 100644 --- a/test/system/st_auth.cpp +++ b/test/system/st_auth.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(fail_plain) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(fail_plain) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(success_digest) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(success_digest) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(fail_digest) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(fail_digest) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE(send_auth) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(send_auth) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_conflict_cid.cpp b/test/system/st_conflict_cid.cpp index bc35ffd37..3127a245d 100644 --- a/test/system/st_conflict_cid.cpp +++ b/test/system/st_conflict_cid.cpp @@ -21,11 +21,11 @@ BOOST_AUTO_TEST_CASE(v311_cs1to1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep1 = ep_t( + auto amep1 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep2 = ep_t( + auto amep2 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(v311_cs1to1) { } }; - tc t{{amep1, amep2}, "127.0.0.1", 1883}; + tc t{{*amep1, *amep2}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -118,11 +118,11 @@ BOOST_AUTO_TEST_CASE(v311_cs0to1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep1 = ep_t( + auto amep1 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep2 = ep_t( + auto amep2 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0to1) { } }; - tc t{{amep1, amep2}, "127.0.0.1", 1883}; + tc t{{*amep1, *amep2}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -215,11 +215,11 @@ BOOST_AUTO_TEST_CASE(v311_cs0to0) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep1 = ep_t( + auto amep1 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep2 = ep_t( + auto amep2 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0to0) { } }; - tc t{{amep1, amep2}, "127.0.0.1", 1883}; + tc t{{*amep1, *amep2}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -312,11 +312,11 @@ BOOST_AUTO_TEST_CASE(v311_cs0offto1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep1 = ep_t( + auto amep1 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep2 = ep_t( + auto amep2 = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -400,7 +400,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0offto1) { } }; - tc t{{amep1, amep2}, "127.0.0.1", 1883}; + tc t{{*amep1, *amep2}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_gencid.cpp b/test/system/st_gencid.cpp index 981363f80..8d074a543 100644 --- a/test/system/st_gencid.cpp +++ b/test/system/st_gencid.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(v311_cs1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(v311_cs1) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(v5_cs1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(v5_cs1) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(v5_cs0) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(v5_cs0) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_inflight.cpp b/test/system/st_inflight.cpp index e60dfacfc..d5a244f8a 100644 --- a/test/system/st_inflight.cpp +++ b/test/system/st_inflight.cpp @@ -18,7 +18,7 @@ BOOST_AUTO_TEST_CASE(v311_to_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(v311_to_broker) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(v5_to_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(v5_to_broker) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -339,11 +339,11 @@ BOOST_AUTO_TEST_CASE(v311_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -518,7 +518,7 @@ BOOST_AUTO_TEST_CASE(v311_from_broker) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -528,11 +528,11 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -708,7 +708,7 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -718,11 +718,11 @@ BOOST_AUTO_TEST_CASE(v5_from_broker_mei) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -887,7 +887,7 @@ BOOST_AUTO_TEST_CASE(v5_from_broker_mei) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_invalid.cpp b/test/system/st_invalid.cpp index 2bb422cf7..8791fccf7 100644 --- a/test/system/st_invalid.cpp +++ b/test/system/st_invalid.cpp @@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(remaining_length) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(remaining_length) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_keep_alive.cpp b/test/system/st_keep_alive.cpp index 6778eb0c2..11bb3db7f 100644 --- a/test/system/st_keep_alive.cpp +++ b/test/system/st_keep_alive.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(v311_timeout) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(v311_timeout) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(v5_timeout) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(v5_timeout) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_mqtt_connect.cpp b/test/system/st_mqtt_connect.cpp index 24123930b..723c1f78a 100644 --- a/test/system/st_mqtt_connect.cpp +++ b/test/system/st_mqtt_connect.cpp @@ -23,16 +23,16 @@ BOOST_AUTO_TEST_CASE(cb) { as::ip::address address = boost::asio::ip::make_address("127.0.0.1"); as::ip::tcp::endpoint endpoint{address, 1883}; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - amep.next_layer().async_connect( + amep->next_layer().async_connect( endpoint, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(cb) { }, [&](am::system_error const& se) { BOOST_TEST(!se); - amep.recv( + amep->recv( [&](am::packet_variant pv) { pv.visit( am::overload { @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(cb) { } } ); - amep.close([]{}); + amep->close([]{}); } ); } @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(fut) { as::ip::address address = boost::asio::ip::make_address("127.0.0.1"); as::ip::tcp::endpoint endpoint{address, 1883}; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); { - auto fut = amep.next_layer().async_connect( + auto fut = amep->next_layer().async_connect( endpoint, as::use_future ); @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.recv(as::use_future); + amep->recv(as::use_future); auto pv = fut.get(); pv.visit( am::overload { @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); } { - auto fut = amep.close(as::use_future); + auto fut = amep->close(as::use_future); fut.get(); } } @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(coro) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(coro) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_mqtts_connect.cpp b/test/system/st_mqtts_connect.cpp index 8da75f359..f2da43cde 100644 --- a/test/system/st_mqtts_connect.cpp +++ b/test/system/st_mqtts_connect.cpp @@ -28,21 +28,21 @@ BOOST_AUTO_TEST_CASE(cb) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx ); - amep.lowest_layer().async_connect( + amep->lowest_layer().async_connect( endpoint, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.next_layer().async_handshake( + amep->next_layer().async_handshake( am::tls::stream_base::client, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(cb) { }, [&](am::system_error const& se) { BOOST_TEST(!se); - amep.recv( + amep->recv( [&](am::packet_variant pv) { pv.visit( am::overload { @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(cb) { } } ); - amep.close([]{}); + amep->close([]{}); } ); } @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(fut) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); { - auto fut = amep.lowest_layer().async_connect( + auto fut = amep->lowest_layer().async_connect( endpoint, as::use_future ); @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(fut) { } } { - auto fut = amep.next_layer().async_handshake( + auto fut = amep->next_layer().async_handshake( am::tls::stream_base::client, as::use_future ); @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.recv(as::use_future); + amep->recv(as::use_future); auto pv = fut.get(); pv.visit( am::overload { @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); } { - auto fut = amep.close(as::use_future); + auto fut = amep->close(as::use_future); fut.get(); } } @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(coro) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx @@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(coro) { } }; - tc t{amep, "127.0.0.1", 8883}; + tc t{*amep, "127.0.0.1", 8883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -248,7 +248,7 @@ BOOST_AUTO_TEST_CASE(coro_client_cert) { ctx.use_private_key_file("client.key.pem", boost::asio::ssl::context::pem); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx @@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(coro_client_cert) { } }; - tc t{amep, "127.0.0.1", 8883}; + tc t{*amep, "127.0.0.1", 8883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_offline.cpp b/test/system/st_offline.cpp index b6676585d..1c54ca27f 100644 --- a/test/system/st_offline.cpp +++ b/test/system/st_offline.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(v311_cs1_sp0) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(v311_cs1_sp0) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp0) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp0) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp1) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp1) { } }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -393,11 +393,11 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp1_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -591,7 +591,7 @@ BOOST_AUTO_TEST_CASE(v311_cs0_sp1_from_broker) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -601,11 +601,11 @@ BOOST_AUTO_TEST_CASE(v5_cs0_sp1_from_broker_mei) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -795,7 +795,7 @@ BOOST_AUTO_TEST_CASE(v5_cs0_sp1_from_broker_mei) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_pub.cpp b/test/system/st_pub.cpp index 7dee5fdfd..d58503ef8 100644 --- a/test/system/st_pub.cpp +++ b/test/system/st_pub.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(v311_pub_to_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(v311_pub_to_broker) { ep_t::packet_id_t pid; }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(v5_pub_to_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(v5_pub_to_broker) { ep_t::packet_id_t pid; }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -220,11 +220,11 @@ BOOST_AUTO_TEST_CASE(v311_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(v311_from_broker) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -405,11 +405,11 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -580,7 +580,7 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_reqres.cpp b/test/system/st_reqres.cpp index 586fb08e9..cc4c98e78 100644 --- a/test/system/st_reqres.cpp +++ b/test/system/st_reqres.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(generate_reuse_renew) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(generate_reuse_renew) { am::buffer response_topic; }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_retain.cpp b/test/system/st_retain.cpp index 915f758a6..c2c9fd77c 100644 --- a/test/system/st_retain.cpp +++ b/test/system/st_retain.cpp @@ -21,11 +21,11 @@ BOOST_AUTO_TEST_CASE(v5_mei_none) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(v5_mei_none) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -173,11 +173,11 @@ BOOST_AUTO_TEST_CASE(v5_mei_no_exp) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE(v5_mei_no_exp) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -327,11 +327,11 @@ BOOST_AUTO_TEST_CASE(v5_mei_exp) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -484,7 +484,7 @@ BOOST_AUTO_TEST_CASE(v5_mei_exp) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -494,11 +494,11 @@ BOOST_AUTO_TEST_CASE(v5_clear) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -635,7 +635,7 @@ BOOST_AUTO_TEST_CASE(v5_clear) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_shared_sub.cpp b/test/system/st_shared_sub.cpp index 5b081e90b..b00aac71a 100644 --- a/test/system/st_shared_sub.cpp +++ b/test/system/st_shared_sub.cpp @@ -21,19 +21,19 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub1 = ep_t( + auto amep_sub1 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub2 = ep_t( + auto amep_sub2 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub3 = ep_t( + auto amep_sub3 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(v5_from_broker) { } }; - tc t{{amep_pub, amep_sub1, amep_sub2, amep_sub3}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub1, *amep_sub2, *amep_sub3}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -330,19 +330,19 @@ BOOST_AUTO_TEST_CASE(v5_unsub_from_broker) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub1 = ep_t( + auto amep_sub1 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub2 = ep_t( + auto amep_sub2 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub3 = ep_t( + auto amep_sub3 = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -654,7 +654,7 @@ BOOST_AUTO_TEST_CASE(v5_unsub_from_broker) { } }; - tc t{{amep_pub, amep_sub1, amep_sub2, amep_sub3}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub1, *amep_sub2, *amep_sub3}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_sub.cpp b/test/system/st_sub.cpp index 52b6606fb..cd2bd1f59 100644 --- a/test/system/st_sub.cpp +++ b/test/system/st_sub.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(v311_sub) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(v311_sub) { ep_t::packet_id_t pid; }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(v5_sub) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(v5_sub) { ep_t::packet_id_t pid; }; - tc t{amep, "127.0.0.1", 1883}; + tc t{*amep, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_will.cpp b/test/system/st_will.cpp index eae5c66c7..d52acd686 100644 --- a/test/system/st_will.cpp +++ b/test/system/st_will.cpp @@ -21,11 +21,11 @@ BOOST_AUTO_TEST_CASE(v311_will) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor() ); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(v311_will) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -140,11 +140,11 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -263,11 +263,11 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send_sei) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send_sei) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -386,11 +386,11 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send_sei_disconnect) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -506,7 +506,7 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_send_sei_disconnect) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -516,11 +516,11 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_not_send_sei_disconnect) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -648,7 +648,7 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_not_send_sei_disconnect) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); @@ -658,11 +658,11 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_not_send_mei) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep_pub = ep_t( + auto amep_pub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); - auto amep_sub = ep_t( + auto amep_sub = ep_t::create( am::protocol_version::v5, ioc.get_executor() ); @@ -789,7 +789,7 @@ BOOST_AUTO_TEST_CASE(v5_will_wd_not_send_mei) { } }; - tc t{{amep_pub, amep_sub}, "127.0.0.1", 1883}; + tc t{{*amep_pub, *amep_sub}, "127.0.0.1", 1883}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_ws_connect.cpp b/test/system/st_ws_connect.cpp index b3bd8ed4a..93589d222 100644 --- a/test/system/st_ws_connect.cpp +++ b/test/system/st_ws_connect.cpp @@ -23,21 +23,21 @@ BOOST_AUTO_TEST_CASE(cb) { as::ip::address address = boost::asio::ip::make_address("127.0.0.1"); as::ip::tcp::endpoint endpoint{address, 10080}; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, am::protocol::ws{ioc.get_executor()} ); - amep.lowest_layer().async_connect( + amep->lowest_layer().async_connect( endpoint, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.next_layer().async_handshake( + amep->next_layer().async_handshake( "127.0.0.1", "/", [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(cb) { }, [&](am::system_error const& se) { BOOST_TEST(!se); - amep.recv( + amep->recv( [&](am::packet_variant pv) { pv.visit( am::overload { @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(cb) { } } ); - amep.close([]{}); + amep->close([]{}); } ); } @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(fut) { as::ip::address address = boost::asio::ip::make_address("127.0.0.1"); as::ip::tcp::endpoint endpoint{address, 10080}; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, am::protocol::ws{ioc.get_executor()} ); @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); { - auto fut = amep.lowest_layer().async_connect( + auto fut = amep->lowest_layer().async_connect( endpoint, as::use_future ); @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(fut) { } } { - auto fut = amep.next_layer().async_handshake( + auto fut = amep->next_layer().async_handshake( "127.0.0.1", "/", as::use_future @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.recv(as::use_future); + amep->recv(as::use_future); auto pv = fut.get(); pv.visit( am::overload { @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); } { - auto fut = amep.close(as::use_future); + auto fut = amep->close(as::use_future); fut.get(); } } @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(coro) { broker_runner br; as::io_context ioc; using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, am::protocol::ws{ioc.get_executor()} ); @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(coro) { } }; - tc t{amep, "127.0.0.1", 10080}; + tc t{*amep, "127.0.0.1", 10080}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/system/st_wss_connect.cpp b/test/system/st_wss_connect.cpp index bea67cd95..431bb5cad 100644 --- a/test/system/st_wss_connect.cpp +++ b/test/system/st_wss_connect.cpp @@ -28,26 +28,26 @@ BOOST_AUTO_TEST_CASE(cb) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx ); - amep.lowest_layer().async_connect( + amep->lowest_layer().async_connect( endpoint, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.next_layer().next_layer().async_handshake( + amep->next_layer().next_layer().async_handshake( am::tls::stream_base::client, [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.next_layer().async_handshake( + amep->next_layer().async_handshake( "127.0.0.1", "/", [&](am::error_code const& ec) { BOOST_TEST(ec == am::error_code{}); - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(cb) { }, [&](am::system_error const& se) { BOOST_TEST(!se); - amep.recv( + amep->recv( [&](am::packet_variant pv) { pv.visit( am::overload { @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(cb) { } } ); - amep.close([]{}); + amep->close([]{}); } ); } @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(fut) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); { - auto fut = amep.lowest_layer().async_connect( + auto fut = amep->lowest_layer().async_connect( endpoint, as::use_future ); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(fut) { } } { - auto fut = amep.next_layer().next_layer().async_handshake( + auto fut = amep->next_layer().next_layer().async_handshake( am::tls::stream_base::client, as::use_future ); @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(fut) { } } { - auto fut = amep.next_layer().async_handshake( + auto fut = amep->next_layer().async_handshake( "127.0.0.1", "/", as::use_future @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.send( + amep->send( am::v3_1_1::connect_packet{ true, // clean_session 0x1234, // keep_alive @@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(fut) { } { auto fut = - amep.recv(as::use_future); + amep->recv(as::use_future); auto pv = fut.get(); pv.visit( am::overload { @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(fut) { ); } { - auto fut = amep.close(as::use_future); + auto fut = amep->close(as::use_future); fut.get(); } } @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(coro) { ctx.load_verify_file("cacert.pem"); using ep_t = am::endpoint; - auto amep = ep_t( + auto amep = ep_t::create( am::protocol_version::v3_1_1, ioc.get_executor(), ctx @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(coro) { } }; - tc t{amep, "127.0.0.1", 10443}; + tc t{*amep, "127.0.0.1", 10443}; t(); ioc.run(); BOOST_TEST(t.finish()); diff --git a/test/unit/ut_ep_con_discon.cpp b/test/unit/ut_ep_con_discon.cpp index 2295af1a5..75509de23 100644 --- a/test/unit/ut_ep_con_discon.cpp +++ b/test/unit/ut_ep_con_discon.cpp @@ -22,7 +22,7 @@ namespace am = async_mqtt; namespace as = boost::asio; // packet_id is hard coded in this test case for just testing. -// but users need to get packet_id via ep.acquire_unique_packet_id(...) +// but users need to get packet_id via ep->acquire_unique_packet_id(...) // see other test cases. // v3_1_1 @@ -37,12 +37,12 @@ BOOST_AUTO_TEST_CASE(valid_client_v3_1_1) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v3_1_1::connect_packet{ true, // clean_session @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(valid_client_v3_1_1) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -114,154 +114,154 @@ BOOST_AUTO_TEST_CASE(valid_client_v3_1_1) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // send valid packets - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback, wp)); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec, wp)); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel, wp)); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp, wp)); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(subscribe, wp)); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(unsubscribe, wp)); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pingreq, wp)); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(!ec); } // send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto ec = ep.send(disconnect, as::use_future).get(); + auto ec = ep->send(disconnect, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto ec = ep.send(disconnect, as::use_future).get(); + auto ec = ep->send(disconnect, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } @@ -279,12 +279,12 @@ BOOST_AUTO_TEST_CASE(invalid_client_v3_1_1) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v3_1_1::connect_packet{ true, // clean_session @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(invalid_client_v3_1_1) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack @@ -370,356 +370,356 @@ BOOST_AUTO_TEST_CASE(invalid_client_v3_1_1) { // compile error as expected #if defined(ASYNC_MQTT_TEST_COMPILE_ERROR) - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } #endif // defined(ASYNC_MQTT_TEST_COMPILE_ERROR) // runtime error due to unable send packet - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(connack), as::use_future).get(); + auto ec = ep->send(am::packet_variant(connack), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(suback), as::use_future).get(); + auto ec = ep->send(am::packet_variant(suback), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(unsuback), as::use_future).get(); + auto ec = ep->send(am::packet_variant(unsuback), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(pingresp), as::use_future).get(); + auto ec = ep->send(am::packet_variant(pingresp), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before sending connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack with not_authorized - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -734,18 +734,18 @@ BOOST_AUTO_TEST_CASE(valid_server_v3_1_1) { } }; - am::endpoint ep1{ + auto ep1 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep2{ + ); + auto ep2 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v3_1_1::connect_packet{ true, // clean_session @@ -800,7 +800,7 @@ BOOST_AUTO_TEST_CASE(valid_server_v3_1_1) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets connect, @@ -810,113 +810,113 @@ BOOST_AUTO_TEST_CASE(valid_server_v3_1_1) { // recv connect { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep1.send(connack, as::use_future).get(); + auto ec = ep1->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep1.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep1->register_packet_id(0x1, as::use_future).get()); // send valid packets - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep1.send(publish, as::use_future).get(); + auto ec = ep1->send(publish, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback, wp)); } ); { - auto ec = ep1.send(puback, as::use_future).get(); + auto ec = ep1->send(puback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec, wp)); } ); { - auto ec = ep1.send(pubrec, as::use_future).get(); + auto ec = ep1->send(pubrec, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel, wp)); } ); { - auto ec = ep1.send(pubrel, as::use_future).get(); + auto ec = ep1->send(pubrel, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp, wp)); } ); { - auto ec = ep1.send(pubcomp, as::use_future).get(); + auto ec = ep1->send(pubcomp, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(suback, wp)); } ); { - auto ec = ep1.send(suback, as::use_future).get(); + auto ec = ep1->send(suback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(unsuback, wp)); } ); { - auto ec = ep1.send(unsuback, as::use_future).get(); + auto ec = ep1->send(unsuback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pingresp, wp)); } ); { - auto ec = ep1.send(pingresp, as::use_future).get(); + auto ec = ep1->send(pingresp, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets connect, @@ -926,38 +926,38 @@ BOOST_AUTO_TEST_CASE(valid_server_v3_1_1) { // recv connect { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep2.send(connack, as::use_future).get(); + auto ec = ep2->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep2.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep2->register_packet_id(0x1, as::use_future).get()); // send publish behalf of valid packets - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep2.send(publish, as::use_future).get(); + auto ec = ep2->send(publish, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } @@ -975,12 +975,12 @@ BOOST_AUTO_TEST_CASE(invalid_server_v3_1_1) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v3_1_1::connect_packet{ true, // clean_session @@ -1054,7 +1054,7 @@ BOOST_AUTO_TEST_CASE(invalid_server_v3_1_1) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect, @@ -1066,354 +1066,354 @@ BOOST_AUTO_TEST_CASE(invalid_server_v3_1_1) { // compile error as expected #if defined(ASYNC_MQTT_TEST_COMPILE_ERROR) - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } #endif // defined(ASYNC_MQTT_TEST_COMPILE_ERROR) // runtime error due to unable send packet - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(connect), as::use_future).get(); + auto ec = ep->send(am::packet_variant(connect), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(subscribe), as::use_future).get(); + auto ec = ep->send(am::packet_variant(subscribe), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(unsubscribe), as::use_future).get(); + auto ec = ep->send(am::packet_variant(unsubscribe), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(pingreq), as::use_future).get(); + auto ec = ep->send(am::packet_variant(pingreq), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before sending connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack with not_authorized - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -1430,12 +1430,12 @@ BOOST_AUTO_TEST_CASE(valid_client_v5) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -1517,7 +1517,7 @@ BOOST_AUTO_TEST_CASE(valid_client_v5) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -1528,175 +1528,175 @@ BOOST_AUTO_TEST_CASE(valid_client_v5) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // send auth packet that can be sent before connack receiving - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(auth, wp)); } ); { - auto ec = ep.send(auth, as::use_future).get(); + auto ec = ep->send(auth, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // send valid packets - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(auth, wp)); } ); { - auto ec = ep.send(auth, as::use_future).get(); + auto ec = ep->send(auth, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); - ep.next_layer().set_write_packet_checker( + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback, wp)); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec, wp)); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel, wp)); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp, wp)); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(subscribe, wp)); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(unsubscribe, wp)); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(!ec); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pingreq, wp)); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(!ec); } // send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto ec = ep.send(disconnect, as::use_future).get(); + auto ec = ep->send(disconnect, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto ec = ep.send(disconnect, as::use_future).get(); + auto ec = ep->send(disconnect, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } @@ -1714,12 +1714,12 @@ BOOST_AUTO_TEST_CASE(invalid_client_v5) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -1821,7 +1821,7 @@ BOOST_AUTO_TEST_CASE(invalid_client_v5) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack @@ -1833,366 +1833,366 @@ BOOST_AUTO_TEST_CASE(invalid_client_v5) { // compile error as expected #if defined(ASYNC_MQTT_TEST_COMPILE_ERROR) - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } #endif // defined(ASYNC_MQTT_TEST_COMPILE_ERROR) // runtime error due to unable send packet - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(connack), as::use_future).get(); + auto ec = ep->send(am::packet_variant(connack), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(suback), as::use_future).get(); + auto ec = ep->send(am::packet_variant(suback), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(unsuback), as::use_future).get(); + auto ec = ep->send(am::packet_variant(unsuback), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(pingresp), as::use_future).get(); + auto ec = ep->send(am::packet_variant(pingresp), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before sending connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(auth, as::use_future).get(); + auto ec = ep->send(auth, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack with not_authorized - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -2207,19 +2207,19 @@ BOOST_AUTO_TEST_CASE(valid_server_v5) { } }; - am::endpoint ep1{ + auto ep1 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); - am::endpoint ep2{ + auto ep2 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -2301,7 +2301,7 @@ BOOST_AUTO_TEST_CASE(valid_server_v5) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets connect, @@ -2311,134 +2311,134 @@ BOOST_AUTO_TEST_CASE(valid_server_v5) { // recv connect { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send auth - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(auth, wp)); } ); { - auto ec = ep1.send(auth, as::use_future).get(); + auto ec = ep1->send(auth, as::use_future).get(); BOOST_TEST(!ec); } // send connack - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep1.send(connack, as::use_future).get(); + auto ec = ep1->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep1.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep1->register_packet_id(0x1, as::use_future).get()); // send valid packets - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(auth, wp)); } ); { - auto ec = ep1.send(auth, as::use_future).get(); + auto ec = ep1->send(auth, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep1.send(publish, as::use_future).get(); + auto ec = ep1->send(publish, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback, wp)); } ); { - auto ec = ep1.send(puback, as::use_future).get(); + auto ec = ep1->send(puback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec, wp)); } ); { - auto ec = ep1.send(pubrec, as::use_future).get(); + auto ec = ep1->send(pubrec, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel, wp)); } ); { - auto ec = ep1.send(pubrel, as::use_future).get(); + auto ec = ep1->send(pubrel, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp, wp)); } ); { - auto ec = ep1.send(pubcomp, as::use_future).get(); + auto ec = ep1->send(pubcomp, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(suback, wp)); } ); { - auto ec = ep1.send(suback, as::use_future).get(); + auto ec = ep1->send(suback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(unsuback, wp)); } ); { - auto ec = ep1.send(unsuback, as::use_future).get(); + auto ec = ep1->send(unsuback, as::use_future).get(); BOOST_TEST(!ec); } - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pingresp, wp)); } ); { - auto ec = ep1.send(pingresp, as::use_future).get(); + auto ec = ep1->send(pingresp, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets connect, @@ -2448,38 +2448,38 @@ BOOST_AUTO_TEST_CASE(valid_server_v5) { // recv connect { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep2.send(connack, as::use_future).get(); + auto ec = ep2->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // register packet_id for testing - BOOST_TEST(ep2.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep2->register_packet_id(0x1, as::use_future).get()); // send publish behalf of valid packets - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish, wp)); } ); { - auto ec = ep2.send(publish, as::use_future).get(); + auto ec = ep2->send(publish, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } @@ -2497,12 +2497,12 @@ BOOST_AUTO_TEST_CASE(invalid_server_v5) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -2604,7 +2604,7 @@ BOOST_AUTO_TEST_CASE(invalid_server_v5) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect @@ -2616,364 +2616,364 @@ BOOST_AUTO_TEST_CASE(invalid_server_v5) { // compile error as expected #if defined(ASYNC_MQTT_TEST_COMPILE_ERROR) - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(subscribe, as::use_future).get(); + auto ec = ep->send(subscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsubscribe, as::use_future).get(); + auto ec = ep->send(unsubscribe, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingreq, as::use_future).get(); + auto ec = ep->send(pingreq, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } #endif // defined(ASYNC_MQTT_TEST_COMPILE_ERROR) // runtime error due to unable send packet - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(connect), as::use_future).get(); + auto ec = ep->send(am::packet_variant(connect), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(subscribe), as::use_future).get(); + auto ec = ep->send(am::packet_variant(subscribe), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(unsubscribe), as::use_future).get(); + auto ec = ep->send(am::packet_variant(unsubscribe), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(am::packet_variant(pingreq), as::use_future).get(); + auto ec = ep->send(am::packet_variant(pingreq), as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // register packet_id for testing - BOOST_TEST(ep.register_packet_id(0x1, as::use_future).get()); + BOOST_TEST(ep->register_packet_id(0x1, as::use_future).get()); // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(auth, as::use_future).get(); + auto ec = ep->send(auth, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before sending connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // offline publish success - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish, as::use_future).get(); + auto ec = ep->send(publish, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::success); } // runtime error due to send before receiving connack with not_authorized - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(puback, as::use_future).get(); + auto ec = ep->send(puback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrec, as::use_future).get(); + auto ec = ep->send(pubrec, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubrel, as::use_future).get(); + auto ec = ep->send(pubrel, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pubcomp, as::use_future).get(); + auto ec = ep->send(pubcomp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(suback, as::use_future).get(); + auto ec = ep->send(suback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(unsuback, as::use_future).get(); + auto ec = ep->send(unsuback, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(pingresp, as::use_future).get(); + auto ec = ep->send(pingresp, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::protocol_error); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } diff --git a/test/unit/ut_ep_recv_filter.cpp b/test/unit/ut_ep_recv_filter.cpp index 982e21e22..6c1186a3c 100644 --- a/test/unit/ut_ep_recv_filter.cpp +++ b/test/unit/ut_ep_recv_filter.cpp @@ -32,12 +32,12 @@ BOOST_AUTO_TEST_CASE(recv_filter) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(recv_filter) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -65,23 +65,23 @@ BOOST_AUTO_TEST_CASE(recv_filter) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(am::filter::match, {am::control_packet_type::connack}, as::use_future).get(); + auto pv = ep->recv(am::filter::match, {am::control_packet_type::connack}, as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } diff --git a/test/unit/ut_ep_recv_max.cpp b/test/unit/ut_ep_recv_max.cpp index 4c04d1941..df6ecc18d 100644 --- a/test/unit/ut_ep_recv_max.cpp +++ b/test/unit/ut_ep_recv_max.cpp @@ -31,12 +31,12 @@ BOOST_AUTO_TEST_CASE(client_send) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(client_send) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -64,23 +64,23 @@ BOOST_AUTO_TEST_CASE(client_send) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_1_q1 = am::v5::publish_packet( *pid_opt1, @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(client_send) { am::properties{} ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_2_q1 = am::v5::publish_packet( *pid_opt2, @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(client_send) { am::properties{} ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_3_q2 = am::v5::publish_packet( *pid_opt3, @@ -135,24 +135,24 @@ BOOST_AUTO_TEST_CASE(client_send) { ); // send publish_1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_1_q1, wp)); } ); { - auto ec = ep.send(publish_1_q1, as::use_future).get(); + auto ec = ep->send(publish_1_q1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_2_q1, wp)); } ); { - auto ec = ep.send(publish_2_q1, as::use_future).get(); + auto ec = ep->send(publish_2_q1, as::use_future).get(); BOOST_TEST(!ec); } @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(client_send) { std::promise p; auto f = p.get_future(); // send publish_3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_3_q2, wp)); pub3_send = true; @@ -168,27 +168,27 @@ BOOST_AUTO_TEST_CASE(client_send) { } ); { - auto ec = ep.send(publish_3_q2, as::use_future).get(); + auto ec = ep->send(publish_3_q2, as::use_future).get(); BOOST_TEST(!ec); BOOST_TEST(!pub3_send); } // send publish_4 bool pub4_send = false; - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_4_q0, wp)); pub4_send = true; } ); { - auto ec = ep.send(publish_4_q0, as::use_future).get(); + auto ec = ep->send(publish_4_q0, as::use_future).get(); BOOST_TEST(!ec); BOOST_TEST(pub4_send); } // set send publish_3 checker again - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_3_q2, wp)); pub3_send = true; @@ -196,7 +196,7 @@ BOOST_AUTO_TEST_CASE(client_send) { } ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets puback2, @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(client_send) { // recv puback2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(puback2, pv)); } @@ -215,27 +215,27 @@ BOOST_AUTO_TEST_CASE(client_send) { // recv pubrec3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec3, pv)); } // send pubrel3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep.send(pubrel3, as::use_future).get(); + auto ec = ep->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv pubcomp3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubcomp3, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -250,12 +250,12 @@ BOOST_AUTO_TEST_CASE(server_send) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(server_send) { am::properties{} }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect, @@ -284,22 +284,22 @@ BOOST_AUTO_TEST_CASE(server_send) { // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_1_q1 = am::v5::publish_packet( *pid_opt1, @@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(server_send) { am::properties{} ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_2_q1 = am::v5::publish_packet( *pid_opt2, @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(server_send) { am::properties{} ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_3_q2 = am::v5::publish_packet( *pid_opt3, @@ -353,7 +353,7 @@ BOOST_AUTO_TEST_CASE(server_send) { *pid_opt3 ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets puback2, @@ -363,24 +363,24 @@ BOOST_AUTO_TEST_CASE(server_send) { ); // send publish_1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_1_q1, wp)); } ); { - auto ec = ep.send(publish_1_q1, as::use_future).get(); + auto ec = ep->send(publish_1_q1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_2_q1, wp)); } ); { - auto ec = ep.send(publish_2_q1, as::use_future).get(); + auto ec = ep->send(publish_2_q1, as::use_future).get(); BOOST_TEST(!ec); } @@ -388,7 +388,7 @@ BOOST_AUTO_TEST_CASE(server_send) { std::promise p; auto f = p.get_future(); // send publish_3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_3_q2, wp)); pub3_send = true; @@ -396,27 +396,27 @@ BOOST_AUTO_TEST_CASE(server_send) { } ); { - auto ec = ep.send(publish_3_q2, as::use_future).get(); + auto ec = ep->send(publish_3_q2, as::use_future).get(); BOOST_TEST(!ec); BOOST_TEST(!pub3_send); } // send publish_4 bool pub4_send = false; - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_4_q0, wp)); pub4_send = true; } ); { - auto ec = ep.send(publish_4_q0, as::use_future).get(); + auto ec = ep->send(publish_4_q0, as::use_future).get(); BOOST_TEST(!ec); BOOST_TEST(pub4_send); } // set send publish_3 checker again - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_3_q2, wp)); pub3_send = true; @@ -426,7 +426,7 @@ BOOST_AUTO_TEST_CASE(server_send) { // recv puback2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(puback2, pv)); } @@ -434,27 +434,27 @@ BOOST_AUTO_TEST_CASE(server_send) { // recv pubrec3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec3, pv)); } // send pubrel3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep.send(pubrel3, as::use_future).get(); + auto ec = ep->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv pubcomp3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubcomp3, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -469,12 +469,12 @@ BOOST_AUTO_TEST_CASE(client_recv) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -501,7 +501,7 @@ BOOST_AUTO_TEST_CASE(client_recv) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -509,19 +509,19 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } @@ -589,7 +589,7 @@ BOOST_AUTO_TEST_CASE(client_recv) { 0x3 // packet_id ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -602,26 +602,26 @@ BOOST_AUTO_TEST_CASE(client_recv) { // recv publish1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_2_q1, pv)); } // recv publish3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_3_q0, pv)); } bool close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -629,19 +629,19 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // recv publish4 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -649,23 +649,23 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -681,71 +681,71 @@ BOOST_AUTO_TEST_CASE(client_recv) { // recv publish1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish4 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_4_q2, pv)); } // send puback2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback2, wp)); } ); { - auto ec = ep.send(puback2, as::use_future).get(); + auto ec = ep->send(puback2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrec3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec3, wp)); } ); { - auto ec = ep.send(pubrec3, as::use_future).get(); + auto ec = ep->send(pubrec3, as::use_future).get(); BOOST_TEST(!ec); } // recv pubrel3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrel3, pv)); } // send pubcomp3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp3, wp)); } ); { - auto ec = ep.send(pubcomp3, as::use_future).get(); + auto ec = ep->send(pubcomp3, as::use_future).get(); BOOST_TEST(!ec); } // recv publish2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_2_q1, pv)); } // recv publish3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_3_q0, pv)); } // recv publish5 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_5_q1, pv)); } close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -753,12 +753,12 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // recv publish6 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -773,18 +773,18 @@ BOOST_AUTO_TEST_CASE(server_recv) { } }; - am::endpoint ep1{ + auto ep1 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep2{ + ); + auto ep2 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -811,7 +811,7 @@ BOOST_AUTO_TEST_CASE(server_recv) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets connect, @@ -820,18 +820,18 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv connect { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep1.send(connack, as::use_future).get(); + auto ec = ep1->send(connack, as::use_future).get(); BOOST_TEST(!ec); } @@ -899,7 +899,7 @@ BOOST_AUTO_TEST_CASE(server_recv) { 0x3 // packet_id ); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -912,26 +912,26 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv publish1 { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish2 { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_2_q1, pv)); } // recv publish3 { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_3_q0, pv)); } bool close_called = false; - ep1.next_layer().set_close_checker( + ep1->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -939,19 +939,19 @@ BOOST_AUTO_TEST_CASE(server_recv) { ); // recv publish4 { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); // recv close { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets connect, @@ -960,22 +960,22 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv connect { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep2.send(connack, as::use_future).get(); + auto ec = ep2->send(connack, as::use_future).get(); BOOST_TEST(!ec); } - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -991,71 +991,71 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv publish1 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish4 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_4_q2, pv)); } // send puback2 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(puback2, wp)); } ); { - auto ec = ep2.send(puback2, as::use_future).get(); + auto ec = ep2->send(puback2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrec3 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrec3, wp)); } ); { - auto ec = ep2.send(pubrec3, as::use_future).get(); + auto ec = ep2->send(pubrec3, as::use_future).get(); BOOST_TEST(!ec); } // recv pubrel3 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrel3, pv)); } // send pubcomp3 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubcomp3, wp)); } ); { - auto ec = ep2.send(pubcomp3, as::use_future).get(); + auto ec = ep2->send(pubcomp3, as::use_future).get(); BOOST_TEST(!ec); } // recv publish2 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_2_q1, pv)); } // recv publish3 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_3_q0, pv)); } // recv publish5 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_5_q1, pv)); } close_called = false; - ep2.next_layer().set_close_checker( + ep2->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -1063,13 +1063,13 @@ BOOST_AUTO_TEST_CASE(server_recv) { ); // recv publish6 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); - ep1.close(as::use_future).get(); - ep2.close(as::use_future).get(); + ep1->close(as::use_future).get(); + ep2->close(as::use_future).get(); guard.reset(); th.join(); } diff --git a/test/unit/ut_ep_send_rt_chk.cpp b/test/unit/ut_ep_send_rt_chk.cpp index ed6851643..2864166aa 100644 --- a/test/unit/ut_ep_send_rt_chk.cpp +++ b/test/unit/ut_ep_send_rt_chk.cpp @@ -38,12 +38,12 @@ BOOST_AUTO_TEST_CASE(v311_client) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v5::connect_packet{ @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { am::allocate_buffer("pass1"), am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "protocol version mismatch")); } { @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { am::allocate_buffer("user1"), am::allocate_buffer("pass1") }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { true, // session_present am::connect_return_code::not_authorized }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -84,35 +84,35 @@ BOOST_AUTO_TEST_CASE(v311_client) { am::allocate_buffer("payload1"), am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::puback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrec_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrel_packet( 0x1234 // packet_id ); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubcomp_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -149,29 +149,29 @@ BOOST_AUTO_TEST_CASE(v311_client) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::unsuback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::disconnect_packet(); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -188,12 +188,12 @@ BOOST_AUTO_TEST_CASE(v311_server) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v3_1_1::connect_packet{ @@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { am::allocate_buffer("user1"), am::allocate_buffer("pass1") }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { true, // session_present am::connect_return_code::not_authorized }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -221,35 +221,35 @@ BOOST_AUTO_TEST_CASE(v311_server) { am::allocate_buffer("payload1"), am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::puback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrec_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrel_packet( 0x1234 // packet_id ); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubcomp_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -286,29 +286,29 @@ BOOST_AUTO_TEST_CASE(v311_server) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::unsuback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::disconnect_packet(); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -326,12 +326,12 @@ BOOST_AUTO_TEST_CASE(v311_any) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v3_1_1::connect_packet{ @@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(v311_any) { am::allocate_buffer("user1"), am::allocate_buffer("pass1") }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(v311_any) { true, // session_present am::connect_return_code::not_authorized }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -359,35 +359,35 @@ BOOST_AUTO_TEST_CASE(v311_any) { am::allocate_buffer("payload1"), am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::puback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrec_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubrel_packet( 0x1234 // packet_id ); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pubcomp_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(v311_any) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(v311_any) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -424,29 +424,29 @@ BOOST_AUTO_TEST_CASE(v311_any) { 0x1234, // packet_id args }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::unsuback_packet{ 0x1234 // packet_id }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v3_1_1::disconnect_packet(); - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -463,12 +463,12 @@ BOOST_AUTO_TEST_CASE(v5_client) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v3_1_1::connect_packet{ @@ -479,7 +479,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::allocate_buffer("user1"), am::allocate_buffer("pass1") }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "protocol version mismatch")); } { @@ -492,7 +492,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::allocate_buffer("pass1"), am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -501,7 +501,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::connect_reason_code::not_authorized, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); // packet type checking is prior to version checking BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -512,7 +512,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -521,7 +521,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::puback_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::pubrec_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -539,7 +539,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::pubrel_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -548,7 +548,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::pubcomp_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -574,7 +574,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -600,17 +600,17 @@ BOOST_AUTO_TEST_CASE(v5_client) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -618,7 +618,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::auth_reason_code::continue_authentication, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -626,7 +626,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::disconnect_reason_code::protocol_error, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -643,12 +643,12 @@ BOOST_AUTO_TEST_CASE(v5_server) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v5::connect_packet{ @@ -660,7 +660,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::allocate_buffer("pass1"), am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -669,7 +669,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::connect_reason_code::not_authorized, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); // packet type checking is prior to version checking BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -680,7 +680,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -689,7 +689,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::puback_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -698,7 +698,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::pubrec_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -707,7 +707,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::pubrel_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -716,7 +716,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::pubcomp_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -729,7 +729,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -742,7 +742,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -755,7 +755,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -768,17 +768,17 @@ BOOST_AUTO_TEST_CASE(v5_server) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -786,7 +786,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::auth_reason_code::continue_authentication, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -794,7 +794,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::disconnect_reason_code::protocol_error, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -811,12 +811,12 @@ BOOST_AUTO_TEST_CASE(v5_any) { ioc.run(); } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); { auto p = am::v5::connect_packet{ @@ -828,7 +828,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::allocate_buffer("pass1"), am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -837,7 +837,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::connect_reason_code::not_authorized, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); // packet type checking is prior to version checking BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } @@ -848,7 +848,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::qos::at_most_once | am::pub::retain::yes | am::pub::dup::yes, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -857,7 +857,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::puback_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -866,7 +866,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::pubrec_reason_code::packet_identifier_in_use, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -875,7 +875,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::pubrel_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -884,7 +884,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::pubcomp_reason_code::packet_identifier_not_found, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -897,7 +897,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -910,7 +910,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -923,7 +923,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -936,17 +936,17 @@ BOOST_AUTO_TEST_CASE(v5_any) { args, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingreq_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { auto p = am::v5::pingresp_packet{}; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -954,7 +954,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::auth_reason_code::continue_authentication, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } { @@ -962,7 +962,7 @@ BOOST_AUTO_TEST_CASE(v5_any) { am::disconnect_reason_code::protocol_error, am::properties{} }; - auto ec = ep.send(am::packet_variant{p}, as::use_future).get(); + auto ec = ep->send(am::packet_variant{p}, as::use_future).get(); BOOST_TEST(!ec_what_start_with(ec, "packet cannot be send by MQTT protocol")); } diff --git a/test/unit/ut_ep_size_max.cpp b/test/unit/ut_ep_size_max.cpp index 0a578e32e..458af4e7e 100644 --- a/test/unit/ut_ep_size_max.cpp +++ b/test/unit/ut_ep_size_max.cpp @@ -31,14 +31,14 @@ BOOST_AUTO_TEST_CASE(client_send) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { BOOST_TEST(false); } ); @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(client_send) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -70,24 +70,24 @@ BOOST_AUTO_TEST_CASE(client_send) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // size: 21bytes - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_1_q1 = am::v5::publish_packet( *pid_opt1, @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(client_send) { ); // size: 22bytes - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_2_q1 = am::v5::publish_packet( *pid_opt2, @@ -109,32 +109,32 @@ BOOST_AUTO_TEST_CASE(client_send) { ); // send publish_1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_1_q1, wp)); } ); { - auto ec = ep.send(publish_1_q1, as::use_future).get(); + auto ec = ep->send(publish_1_q1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_2_q1, as::use_future).get(); + auto ec = ep->send(publish_2_q1, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); BOOST_TEST(*pid_opt3 == 2); // 2 can be resused - ep.next_layer().set_close_checker({}); - ep.close(as::use_future).get(); + ep->next_layer().set_close_checker({}); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -149,14 +149,14 @@ BOOST_AUTO_TEST_CASE(client_recv) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { BOOST_TEST(false); } ); @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(client_recv) { am::properties{} }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -193,24 +193,24 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } // size: 21bytes - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_1_q1 = am::v5::publish_packet( *pid_opt1, @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(client_recv) { ); // size: 22bytes - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_2_q1 = am::v5::publish_packet( *pid_opt2, @@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(client_recv) { am::properties{} ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -241,23 +241,23 @@ BOOST_AUTO_TEST_CASE(client_recv) { // recv publish1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish2 bool close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } @@ -277,14 +277,14 @@ BOOST_AUTO_TEST_CASE(server_recv) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { BOOST_TEST(false); } ); @@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(server_recv) { am::properties{} }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect, @@ -322,23 +322,23 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } // size: 21bytes - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_1_q1 = am::v5::publish_packet( *pid_opt1, @@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(server_recv) { ); // size: 22bytes - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_2_q1 = am::v5::publish_packet( *pid_opt2, @@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(server_recv) { am::properties{} ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_1_q1, @@ -369,23 +369,23 @@ BOOST_AUTO_TEST_CASE(server_recv) { // recv publish1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_1_q1, pv)); } // recv publish2 bool close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } diff --git a/test/unit/ut_ep_store.cpp b/test/unit/ut_ep_store.cpp index 15637eeb2..1da1f8538 100644 --- a/test/unit/ut_ep_store.cpp +++ b/test/unit/ut_ep_store.cpp @@ -33,12 +33,12 @@ BOOST_AUTO_TEST_CASE(v311_client) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, - ioc, - }; + ioc + ); auto connect = am::v3_1_1::connect_packet{ false, // clean_session @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { am::connect_return_code::accepted }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack_sp_false, @@ -67,19 +67,19 @@ BOOST_AUTO_TEST_CASE(v311_client) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { am::qos::at_most_once ); - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish1 = am::v3_1_1::publish_packet( *pid_opt1, @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { auto publish1dup{publish1}; publish1dup.set_dup(true); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish2 = am::v3_1_1::publish_packet( *pid_opt2, @@ -124,13 +124,13 @@ BOOST_AUTO_TEST_CASE(v311_client) { *pid_opt2 ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto pubrel3 = am::v3_1_1::pubrel_packet( *pid_opt3 ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets close, @@ -144,52 +144,52 @@ BOOST_AUTO_TEST_CASE(v311_client) { ); // send publish0 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish0, wp)); } ); { - auto ec = ep.send(publish0, as::use_future).get(); + auto ec = ep->send(publish0, as::use_future).get(); BOOST_TEST(!ec); } // send publish1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish1, wp)); } ); { - auto ec = ep.send(publish1, as::use_future).get(); + auto ec = ep->send(publish1, as::use_future).get(); BOOST_TEST(!ec); } // send publish2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish2, wp)); } ); { - auto ec = ep.send(publish2, as::use_future).get(); + auto ec = ep->send(publish2, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { std::size_t index = 0; std::promise p; auto f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -222,46 +222,46 @@ BOOST_AUTO_TEST_CASE(v311_client) { // recv pubrec2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec2, pv)); } // send pubrel2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel2, wp)); } ); { - auto ec = ep.send(pubrel2, as::use_future).get(); + auto ec = ep->send(pubrel2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrel3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep.send(pubrel3, as::use_future).get(); + auto ec = ep->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { index = 0; p = std::promise(); f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE(v311_client) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -297,33 +297,33 @@ BOOST_AUTO_TEST_CASE(v311_client) { // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false index = 0; - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -338,30 +338,30 @@ BOOST_AUTO_TEST_CASE(v311_server) { } }; - am::endpoint ep1{ + auto ep1 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep2{ + ); + auto ep2 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep3{ + ); + auto ep3 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep4{ + ); + auto ep4 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect_no_clean = am::v3_1_1::connect_packet{ false, // clean_session @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets connect_no_clean, @@ -402,18 +402,18 @@ BOOST_AUTO_TEST_CASE(v311_server) { // recv connect_no_clean { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // send connack_sp_false - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack_sp_false, wp)); } ); { - auto ec = ep1.send(connack_sp_false, as::use_future).get(); + auto ec = ep1->send(connack_sp_false, as::use_future).get(); BOOST_TEST(!ec); } @@ -424,7 +424,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { am::qos::at_most_once ); - auto pid_opt1 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish1 = am::v3_1_1::publish_packet( *pid_opt1, @@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { auto publish1dup{publish1}; publish1dup.set_dup(true); - auto pid_opt2 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish2 = am::v3_1_1::publish_packet( *pid_opt2, @@ -456,19 +456,19 @@ BOOST_AUTO_TEST_CASE(v311_server) { *pid_opt2 ); - auto pid_opt3 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto pubrel3 = am::v3_1_1::pubrel_packet( *pid_opt3 ); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets close, } ); - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets connect_no_clean, @@ -476,14 +476,14 @@ BOOST_AUTO_TEST_CASE(v311_server) { close, } ); - ep3.next_layer().set_recv_packets( + ep3->next_layer().set_recv_packets( { // receive packets connect_no_clean, close, } ); - ep4.next_layer().set_recv_packets( + ep4->next_layer().set_recv_packets( { // receive packets connect_clean, @@ -491,61 +491,61 @@ BOOST_AUTO_TEST_CASE(v311_server) { ); // send publish0 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish0, wp)); } ); { - auto ec = ep1.send(publish0, as::use_future).get(); + auto ec = ep1->send(publish0, as::use_future).get(); BOOST_TEST(!ec); } // send publish1 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish1, wp)); } ); { - auto ec = ep1.send(publish1, as::use_future).get(); + auto ec = ep1->send(publish1, as::use_future).get(); BOOST_TEST(!ec); } // send publish2 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish2, wp)); } ); { - auto ec = ep1.send(publish2, as::use_future).get(); + auto ec = ep1->send(publish2, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_no_clean { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // get_stored and restore next endpoint { - auto pvs = ep1.get_stored_packets(as::use_future).get(); - ep2.restore_packets(am::force_move(pvs), as::use_future); + auto pvs = ep1->get_stored_packets(as::use_future).get(); + ep2->restore_packets(am::force_move(pvs), as::use_future); } // send connack_sp_true std::size_t index = 0; std::promise p; auto f = p.get_future(); - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -565,68 +565,68 @@ BOOST_AUTO_TEST_CASE(v311_server) { } ); { - auto ec = ep2.send(connack_sp_true, as::use_future).get(); + auto ec = ep2->send(connack_sp_true, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 3); { - auto pid_opt = ep2.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt = ep2->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt.has_value()); BOOST_TEST(*pid_opt == 3); // 1 and 2 are used by publish(dup) } // recv pubrec2 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec2, pv)); } // send pubrel2 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel2, wp)); } ); { - auto ec = ep2.send(pubrel2, as::use_future).get(); + auto ec = ep2->send(pubrel2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrel3 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep2.send(pubrel3, as::use_future).get(); + auto ec = ep2->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_no_clean { - auto pv = ep3.recv(as::use_future).get(); + auto pv = ep3->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // get_stored and restore next endpoint { - auto pvs = ep2.get_stored_packets(as::use_future).get(); - ep3.restore_packets(am::force_move(pvs), as::use_future); + auto pvs = ep2->get_stored_packets(as::use_future).get(); + ep3->restore_packets(am::force_move(pvs), as::use_future); } // send connack_sp_true index = 0; p = std::promise(); f = p.get_future(); - ep3.next_layer().set_write_packet_checker( + ep3->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -649,26 +649,26 @@ BOOST_AUTO_TEST_CASE(v311_server) { } ); { - auto ec = ep3.send(connack_sp_true, as::use_future).get(); + auto ec = ep3->send(connack_sp_true, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 4); { - auto pid_opt = ep3.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt = ep3->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt.has_value()); BOOST_TEST(*pid_opt == 4); // 1, 2 and 3 are used by publish(dup) and pubrel } // recv close { - auto pv = ep3.recv(as::use_future).get(); + auto pv = ep3->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_clean { - auto pv = ep4.recv(as::use_future).get(); + auto pv = ep4->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_clean, pv)); } @@ -678,7 +678,7 @@ BOOST_AUTO_TEST_CASE(v311_server) { index = 0; p = std::promise(); f = p.get_future(); - ep4.next_layer().set_write_packet_checker( + ep4->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -692,15 +692,15 @@ BOOST_AUTO_TEST_CASE(v311_server) { } ); { - auto ec = ep4.send(connack_sp_false, as::use_future).get(); + auto ec = ep4->send(connack_sp_false, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 1); - ep1.close(as::use_future).get(); - ep2.close(as::use_future).get(); - ep3.close(as::use_future).get(); - ep4.close(as::use_future).get(); + ep1->close(as::use_future).get(); + ep2->close(as::use_future).get(); + ep3->close(as::use_future).get(); + ep4->close(as::use_future).get(); guard.reset(); th.join(); } @@ -717,12 +717,12 @@ BOOST_AUTO_TEST_CASE(v5_client) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ false, // clean_session @@ -750,7 +750,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack_sp_false, @@ -758,19 +758,19 @@ BOOST_AUTO_TEST_CASE(v5_client) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } @@ -782,7 +782,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { am::properties{} ); - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish1 = am::v5::publish_packet( *pid_opt1, @@ -795,7 +795,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { auto publish1dup{publish1}; publish1dup.set_dup(true); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish2 = am::v5::publish_packet( *pid_opt2, @@ -816,13 +816,13 @@ BOOST_AUTO_TEST_CASE(v5_client) { *pid_opt2 ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto pubrel3 = am::v5::pubrel_packet( *pid_opt3 ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets close, @@ -836,52 +836,52 @@ BOOST_AUTO_TEST_CASE(v5_client) { ); // send publish0 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish0, wp)); } ); { - auto ec = ep.send(publish0, as::use_future).get(); + auto ec = ep->send(publish0, as::use_future).get(); BOOST_TEST(!ec); } // send publish1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish1, wp)); } ); { - auto ec = ep.send(publish1, as::use_future).get(); + auto ec = ep->send(publish1, as::use_future).get(); BOOST_TEST(!ec); } // send publish2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish2, wp)); } ); { - auto ec = ep.send(publish2, as::use_future).get(); + auto ec = ep->send(publish2, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -889,7 +889,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { std::size_t index = 0; std::promise p; auto f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -906,7 +906,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -914,46 +914,46 @@ BOOST_AUTO_TEST_CASE(v5_client) { // recv pubrec2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec2, pv)); } // send pubrel2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel2, wp)); } ); { - auto ec = ep.send(pubrel2, as::use_future).get(); + auto ec = ep->send(pubrel2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrel3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep.send(pubrel3, as::use_future).get(); + auto ec = ep->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -961,7 +961,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { index = 0; p = std::promise(); f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -981,7 +981,7 @@ BOOST_AUTO_TEST_CASE(v5_client) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -989,33 +989,33 @@ BOOST_AUTO_TEST_CASE(v5_client) { // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false index = 0; - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -1030,30 +1030,30 @@ BOOST_AUTO_TEST_CASE(v5_server) { } }; - am::endpoint ep1{ + auto ep1 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep2{ + ); + auto ep2 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep3{ + ); + auto ep3 = am::endpoint::create( version, // for stub_socket args version, ioc - }; - am::endpoint ep4{ + ); + auto ep4 = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect_no_clean = am::v5::connect_packet{ false, // clean_session @@ -1091,7 +1091,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets connect_no_clean, @@ -1100,18 +1100,18 @@ BOOST_AUTO_TEST_CASE(v5_server) { // recv connect_no_clean { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // send connack_sp_false - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack_sp_false, wp)); } ); { - auto ec = ep1.send(connack_sp_false, as::use_future).get(); + auto ec = ep1->send(connack_sp_false, as::use_future).get(); BOOST_TEST(!ec); } @@ -1123,7 +1123,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { am::properties{} ); - auto pid_opt1 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish1 = am::v5::publish_packet( *pid_opt1, @@ -1136,7 +1136,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { auto publish1dup{publish1}; publish1dup.set_dup(true); - auto pid_opt2 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish2 = am::v5::publish_packet( *pid_opt2, @@ -1157,19 +1157,19 @@ BOOST_AUTO_TEST_CASE(v5_server) { *pid_opt2 ); - auto pid_opt3 = ep1.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep1->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto pubrel3 = am::v5::pubrel_packet( *pid_opt3 ); - ep1.next_layer().set_recv_packets( + ep1->next_layer().set_recv_packets( { // receive packets close, } ); - ep2.next_layer().set_recv_packets( + ep2->next_layer().set_recv_packets( { // receive packets connect_no_clean, @@ -1177,14 +1177,14 @@ BOOST_AUTO_TEST_CASE(v5_server) { close, } ); - ep3.next_layer().set_recv_packets( + ep3->next_layer().set_recv_packets( { // receive packets connect_no_clean, close, } ); - ep4.next_layer().set_recv_packets( + ep4->next_layer().set_recv_packets( { // receive packets connect_clean, @@ -1192,61 +1192,61 @@ BOOST_AUTO_TEST_CASE(v5_server) { ); // send publish0 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish0, wp)); } ); { - auto ec = ep1.send(publish0, as::use_future).get(); + auto ec = ep1->send(publish0, as::use_future).get(); BOOST_TEST(!ec); } // send publish1 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish1, wp)); } ); { - auto ec = ep1.send(publish1, as::use_future).get(); + auto ec = ep1->send(publish1, as::use_future).get(); BOOST_TEST(!ec); } // send publish2 - ep1.next_layer().set_write_packet_checker( + ep1->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish2, wp)); } ); { - auto ec = ep1.send(publish2, as::use_future).get(); + auto ec = ep1->send(publish2, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep1.recv(as::use_future).get(); + auto pv = ep1->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_no_clean { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // get_stored and restore next endpoint { - auto pvs = ep1.get_stored_packets(as::use_future).get(); - ep2.restore_packets(am::force_move(pvs), as::use_future); + auto pvs = ep1->get_stored_packets(as::use_future).get(); + ep2->restore_packets(am::force_move(pvs), as::use_future); } // send connack_sp_true std::size_t index = 0; std::promise p; auto f = p.get_future(); - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -1266,69 +1266,69 @@ BOOST_AUTO_TEST_CASE(v5_server) { } ); { - auto ec = ep2.send(connack_sp_true, as::use_future).get(); + auto ec = ep2->send(connack_sp_true, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 3); { - auto pid_opt = ep2.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt = ep2->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt.has_value()); BOOST_TEST(*pid_opt == 3); // 1 and 2 are used by publish(dup) } // recv pubrec2 { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec2, pv)); } // send pubrel2 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel2, wp)); } ); { - auto ec = ep2.send(pubrel2, as::use_future).get(); + auto ec = ep2->send(pubrel2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrel3 - ep2.next_layer().set_write_packet_checker( + ep2->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep2.send(pubrel3, as::use_future).get(); + auto ec = ep2->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep2.recv(as::use_future).get(); + auto pv = ep2->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_no_clean { - auto pv = ep3.recv(as::use_future).get(); + auto pv = ep3->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_no_clean, pv)); } // get_stored and restore next endpoint { - auto pvs = ep2.get_stored_packets(as::use_future).get(); - ep3.restore_packets(am::force_move(pvs), as::use_future); + auto pvs = ep2->get_stored_packets(as::use_future).get(); + ep3->restore_packets(am::force_move(pvs), as::use_future); } // send connack_sp_true index = 0; p = std::promise(); f = p.get_future(); - ep3.next_layer().set_write_packet_checker( + ep3->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -1351,26 +1351,26 @@ BOOST_AUTO_TEST_CASE(v5_server) { } ); { - auto ec = ep3.send(connack_sp_true, as::use_future).get(); + auto ec = ep3->send(connack_sp_true, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 4); { - auto pid_opt = ep3.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt = ep3->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt.has_value()); BOOST_TEST(*pid_opt == 4); // 1, 2 and 3 are used by publish(dup) and pubrel } // recv close { - auto pv = ep3.recv(as::use_future).get(); + auto pv = ep3->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // recv connect_clean { - auto pv = ep4.recv(as::use_future).get(); + auto pv = ep4->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect_clean, pv)); } @@ -1380,7 +1380,7 @@ BOOST_AUTO_TEST_CASE(v5_server) { index = 0; p = std::promise(); f = p.get_future(); - ep4.next_layer().set_write_packet_checker( + ep4->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -1394,15 +1394,15 @@ BOOST_AUTO_TEST_CASE(v5_server) { } ); { - auto ec = ep4.send(connack_sp_false, as::use_future).get(); + auto ec = ep4->send(connack_sp_false, as::use_future).get(); BOOST_TEST(!ec); } f.get(); BOOST_TEST(index == 1); - ep1.close(as::use_future).get(); - ep2.close(as::use_future).get(); - ep3.close(as::use_future).get(); - ep4.close(as::use_future).get(); + ep1->close(as::use_future).get(); + ep2->close(as::use_future).get(); + ep3->close(as::use_future).get(); + ep4->close(as::use_future).get(); guard.reset(); th.join(); } @@ -1417,12 +1417,12 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { } }; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ false, // clean_session @@ -1454,7 +1454,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack_sp_false, @@ -1462,19 +1462,19 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } @@ -1486,7 +1486,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { am::properties{} ); - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish1 = am::v5::publish_packet( *pid_opt1, @@ -1509,7 +1509,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { auto publish1no_ta_dup{publish1no_ta}; publish1no_ta_dup.set_dup(true); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish2 = am::v5::publish_packet( *pid_opt2, @@ -1540,13 +1540,13 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { *pid_opt2 ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto pubrel3 = am::v5::pubrel_packet( *pid_opt3 ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets close, @@ -1560,52 +1560,52 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { ); // send publish0 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish0, wp)); } ); { - auto ec = ep.send(publish0, as::use_future).get(); + auto ec = ep->send(publish0, as::use_future).get(); BOOST_TEST(!ec); } // send publish1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish1, wp)); } ); { - auto ec = ep.send(publish1, as::use_future).get(); + auto ec = ep->send(publish1, as::use_future).get(); BOOST_TEST(!ec); } // send publish2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish2, wp)); } ); { - auto ec = ep.send(publish2, as::use_future).get(); + auto ec = ep->send(publish2, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -1613,7 +1613,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { std::size_t index = 0; std::promise p; auto f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -1630,7 +1630,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -1638,46 +1638,46 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { // recv pubrec2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(pubrec2, pv)); } // send pubrel2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel2, wp)); } ); { - auto ec = ep.send(pubrel2, as::use_future).get(); + auto ec = ep->send(pubrel2, as::use_future).get(); BOOST_TEST(!ec); } // send pubrel3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(pubrel3, wp)); } ); { - auto ec = ep.send(pubrel3, as::use_future).get(); + auto ec = ep->send(pubrel3, as::use_future).get(); BOOST_TEST(!ec); } // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } @@ -1685,7 +1685,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { index = 0; p = std::promise(); f = p.get_future(); - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { switch (index++) { case 0: @@ -1705,7 +1705,7 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_true, pv)); } f.get(); @@ -1713,33 +1713,33 @@ BOOST_AUTO_TEST_CASE(v5_topic_alias) { // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack_sp_false index = 0; - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack_sp_false, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } diff --git a/test/unit/ut_ep_topic_alias.cpp b/test/unit/ut_ep_topic_alias.cpp index f464ec150..539181337 100644 --- a/test/unit/ut_ep_topic_alias.cpp +++ b/test/unit/ut_ep_topic_alias.cpp @@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE(send_client) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -84,23 +84,23 @@ BOOST_AUTO_TEST_CASE(send_client) { ); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_reg_t1 = am::v5::publish_packet( *pid_opt1, @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_use_ta1 = am::v5::publish_packet( *pid_opt2, @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_reg_t2 = am::v5::publish_packet( *pid_opt3, @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt4 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt4 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt4.has_value()); auto publish_use_ta2 = am::v5::publish_packet( *pid_opt4, @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt5 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt5 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt5.has_value()); auto publish_reg_t3 = am::v5::publish_packet( *pid_opt5, @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt6 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt6 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt6.has_value()); auto publish_use_ta3 = am::v5::publish_packet( *pid_opt6, @@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(send_client) { } ); - auto pid_opt7 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt7 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt7.has_value()); auto publish_upd_t3 = am::v5::publish_packet( *pid_opt7, @@ -185,100 +185,100 @@ BOOST_AUTO_TEST_CASE(send_client) { ); // send publish_reg_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_reg_t1, wp)); } ); { - auto ec = ep.send(publish_reg_t1, as::use_future).get(); + auto ec = ep->send(publish_reg_t1, as::use_future).get(); BOOST_TEST(!ec); } { // check regulate auto p = publish_reg_t1; - auto rp = ep.regulate_for_store(p, as::use_future).get(); + auto rp = ep->regulate_for_store(p, as::use_future).get(); BOOST_TEST(rp.topic() == "topic1"_mb); BOOST_TEST(!get_topic_alias(rp.props())); // idempotence auto p2 = p; - auto rp2 = ep.regulate_for_store(p2, as::use_future).get(); + auto rp2 = ep->regulate_for_store(p2, as::use_future).get(); BOOST_TEST(rp2.topic() == "topic1"_mb); BOOST_TEST(!get_topic_alias(rp2.props())); } // send publish_use_ta1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta1, wp)); } ); { - auto ec = ep.send(publish_use_ta1, as::use_future).get(); + auto ec = ep->send(publish_use_ta1, as::use_future).get(); BOOST_TEST(!ec); } { // check regulate auto p = publish_use_ta1; - auto rp = ep.regulate_for_store(p, as::use_future).get(); + auto rp = ep->regulate_for_store(p, as::use_future).get(); BOOST_TEST(rp.topic() == "topic1"_mb); BOOST_TEST(!get_topic_alias(rp.props())); } // send publish_reg_t2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_reg_t2, wp)); } ); { - auto ec = ep.send(publish_reg_t2, as::use_future).get(); + auto ec = ep->send(publish_reg_t2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_use_ta2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta2, wp)); } ); { - auto ec = ep.send(publish_use_ta2, as::use_future).get(); + auto ec = ep->send(publish_use_ta2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_reg_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_reg_t3, as::use_future).get(); + auto ec = ep->send(publish_reg_t3, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } // send publish_use_ta3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_use_ta3, as::use_future).get(); + auto ec = ep->send(publish_use_ta3, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } // send publish_upd_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_upd_t3, wp)); } ); { - auto ec = ep.send(publish_upd_t3, as::use_future).get(); + auto ec = ep->send(publish_upd_t3, as::use_future).get(); BOOST_TEST(!ec); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -294,12 +294,12 @@ BOOST_AUTO_TEST_CASE(send_server) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE(send_server) { am::properties{} }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect, @@ -328,22 +328,22 @@ BOOST_AUTO_TEST_CASE(send_server) { // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_reg_t1 = am::v5::publish_packet( *pid_opt1, @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_use_ta1 = am::v5::publish_packet( *pid_opt2, @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_reg_t2 = am::v5::publish_packet( *pid_opt3, @@ -379,7 +379,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt4 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt4 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt4.has_value()); auto publish_use_ta2 = am::v5::publish_packet( *pid_opt4, @@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt5 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt5 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt5.has_value()); auto publish_reg_t3 = am::v5::publish_packet( *pid_opt5, @@ -403,7 +403,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt6 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt6 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt6.has_value()); auto publish_use_ta3 = am::v5::publish_packet( *pid_opt6, @@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE(send_server) { } ); - auto pid_opt7 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt7 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt7.has_value()); auto publish_upd_t3 = am::v5::publish_packet( *pid_opt7, @@ -428,82 +428,82 @@ BOOST_AUTO_TEST_CASE(send_server) { ); // send publish_reg_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_reg_t1, wp)); } ); { - auto ec = ep.send(publish_reg_t1, as::use_future).get(); + auto ec = ep->send(publish_reg_t1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_use_ta1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta1, wp)); } ); { - auto ec = ep.send(publish_use_ta1, as::use_future).get(); + auto ec = ep->send(publish_use_ta1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_reg_t2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_reg_t2, wp)); } ); { - auto ec = ep.send(publish_reg_t2, as::use_future).get(); + auto ec = ep->send(publish_reg_t2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_use_ta2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta2, wp)); } ); { - auto ec = ep.send(publish_use_ta2, as::use_future).get(); + auto ec = ep->send(publish_use_ta2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_reg_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_reg_t3, as::use_future).get(); + auto ec = ep->send(publish_reg_t3, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } // send publish_use_ta3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_use_ta3, as::use_future).get(); + auto ec = ep->send(publish_use_ta3, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } // send publish_upd_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_upd_t3, wp)); } ); { - auto ec = ep.send(publish_upd_t3, as::use_future).get(); + auto ec = ep->send(publish_upd_t3, as::use_future).get(); BOOST_TEST(!ec); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -519,12 +519,12 @@ BOOST_AUTO_TEST_CASE(send_auto_map) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -544,33 +544,33 @@ BOOST_AUTO_TEST_CASE(send_auto_map) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, } ); - ep.set_auto_map_topic_alias_send(true); + ep->set_auto_map_topic_alias_send(true); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_t1 = am::v5::publish_packet( *pid_opt1, @@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE(send_auto_map) { } ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_t2 = am::v5::publish_packet( *pid_opt2, @@ -630,7 +630,7 @@ BOOST_AUTO_TEST_CASE(send_auto_map) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_t3 = am::v5::publish_packet( *pid_opt3, @@ -661,71 +661,71 @@ BOOST_AUTO_TEST_CASE(send_auto_map) { ); // send publish_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_mapped_ta1, wp)); } ); { - auto ec = ep.send(publish_t1, as::use_future).get(); + auto ec = ep->send(publish_t1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta1, wp)); } ); { - auto ec = ep.send(publish_t1, as::use_future).get(); + auto ec = ep->send(publish_t1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_mapped_ta2, wp)); } ); { - auto ec = ep.send(publish_t2, as::use_future).get(); + auto ec = ep->send(publish_t2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t2 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta2, wp)); } ); { - auto ec = ep.send(publish_t2, as::use_future).get(); + auto ec = ep->send(publish_t2, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_mapped_ta1_2, wp)); } ); { - auto ec = ep.send(publish_t3, as::use_future).get(); + auto ec = ep->send(publish_t3, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t3 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_use_ta1_2, wp)); } ); { - auto ec = ep.send(publish_t3, as::use_future).get(); + auto ec = ep->send(publish_t3, as::use_future).get(); BOOST_TEST(!ec); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -741,12 +741,12 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -766,33 +766,33 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { } }; - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, } ); - ep.set_auto_replace_topic_alias_send(true); + ep->set_auto_replace_topic_alias_send(true); // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_t1 = am::v5::publish_packet( *pid_opt1, @@ -802,7 +802,7 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { am::properties{} ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_map_ta1 = am::v5::publish_packet( *pid_opt2, @@ -814,7 +814,7 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_use_ta1 = am::v5::publish_packet( *pid_opt3, @@ -826,7 +826,7 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { } ); - auto pid_opt4 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt4 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt4.has_value()); auto publish_t1_2 = am::v5::publish_packet( *pid_opt4, @@ -847,50 +847,50 @@ BOOST_AUTO_TEST_CASE(send_auto_replace) { ); // send publish_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_t1, wp)); } ); { - auto ec = ep.send(publish_t1, as::use_future).get(); + auto ec = ep->send(publish_t1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_use_ta1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant) { BOOST_TEST(false); } ); { - auto ec = ep.send(publish_use_ta1, as::use_future).get(); + auto ec = ep->send(publish_use_ta1, as::use_future).get(); BOOST_TEST(ec.code() == am::errc::bad_message); } // send publish_map_ta1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(publish_map_ta1, wp)); } ); { - auto ec = ep.send(publish_map_ta1, as::use_future).get(); + auto ec = ep->send(publish_map_ta1, as::use_future).get(); BOOST_TEST(!ec); } // send publish_t1 - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { // auto use BOOST_TEST(am::packet_compare(publish_exp_ta1, wp)); } ); { - auto ec = ep.send(publish_t1_2, as::use_future).get(); + auto ec = ep->send(publish_t1_2, as::use_future).get(); BOOST_TEST(!ec); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -906,12 +906,12 @@ BOOST_AUTO_TEST_CASE(recv_client) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -938,7 +938,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connack, @@ -948,26 +948,26 @@ BOOST_AUTO_TEST_CASE(recv_client) { auto init = [&] { // send connect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connect, wp)); } ); { - auto ec = ep.send(connect, as::use_future).get(); + auto ec = ep->send(connect, as::use_future).get(); BOOST_TEST(!ec); } // recv connack { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connack, pv)); } }; init(); - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_reg_t1 = am::v5::publish_packet( *pid_opt1, @@ -979,7 +979,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_use_ta1 = am::v5::publish_packet( *pid_opt2, @@ -1001,7 +1001,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_reg_t2 = am::v5::publish_packet( *pid_opt3, @@ -1013,7 +1013,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt4 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt4 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt4.has_value()); auto publish_use_ta2 = am::v5::publish_packet( *pid_opt4, @@ -1035,7 +1035,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt5 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt5 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt5.has_value()); auto publish_reg_t3 = am::v5::publish_packet( *pid_opt5, @@ -1047,7 +1047,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt6 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt6 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt6.has_value()); auto publish_use_ta3 = am::v5::publish_packet( *pid_opt6, @@ -1059,7 +1059,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt7 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt7 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt7.has_value()); auto publish_upd_t3 = am::v5::publish_packet( *pid_opt7, @@ -1071,7 +1071,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - auto pid_opt8 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt8 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt8.has_value()); auto publish_use_ta1_t3 = am::v5::publish_packet( *pid_opt8, @@ -1093,7 +1093,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { } ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_reg_t1, @@ -1113,35 +1113,35 @@ BOOST_AUTO_TEST_CASE(recv_client) { // recv publish_reg_t1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_reg_t1, pv)); } // recv publish_use_ta1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t1, pv)); } // recv publish_reg_t2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_reg_t2, pv)); } // recv publish_use_ta2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t2, pv)); } bool close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -1149,7 +1149,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { ); // recv publish_reg_t3 (invalid) { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } @@ -1157,18 +1157,18 @@ BOOST_AUTO_TEST_CASE(recv_client) { // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } init(); close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -1176,7 +1176,7 @@ BOOST_AUTO_TEST_CASE(recv_client) { ); // recv publish_use_ta3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } @@ -1184,23 +1184,23 @@ BOOST_AUTO_TEST_CASE(recv_client) { // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } init(); // recv publish_upd_t3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_upd_t3, pv)); } // recv publish_use_ta1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t3, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } @@ -1216,12 +1216,12 @@ BOOST_AUTO_TEST_CASE(recv_server) { }; using ep_t = am::endpoint; - ep_t ep{ + auto ep = ep_t::create( version, // for stub_socket args version, ioc - }; + ); auto connect = am::v5::connect_packet{ true, // clean_start @@ -1248,7 +1248,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { auto close = am::make_error(am::errc::network_reset, "pseudo close"); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets connect, @@ -1259,18 +1259,18 @@ BOOST_AUTO_TEST_CASE(recv_server) { [&] { // recv connect { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(connect, pv)); } // send connack - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(am::packet_compare(connack, wp)); } ); { - auto ec = ep.send(connack, as::use_future).get(); + auto ec = ep->send(connack, as::use_future).get(); BOOST_TEST(!ec); } @@ -1278,7 +1278,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { init(); - auto pid_opt1 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt1 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt1.has_value()); auto publish_reg_t1 = am::v5::publish_packet( *pid_opt1, @@ -1290,7 +1290,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt2 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt2 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt2.has_value()); auto publish_use_ta1 = am::v5::publish_packet( *pid_opt2, @@ -1312,7 +1312,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt3 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt3 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt3.has_value()); auto publish_reg_t2 = am::v5::publish_packet( *pid_opt3, @@ -1324,7 +1324,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt4 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt4 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt4.has_value()); auto publish_use_ta2 = am::v5::publish_packet( *pid_opt4, @@ -1346,7 +1346,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt5 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt5 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt5.has_value()); auto publish_reg_t3 = am::v5::publish_packet( *pid_opt5, @@ -1358,7 +1358,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt6 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt6 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt6.has_value()); auto publish_use_ta3 = am::v5::publish_packet( *pid_opt6, @@ -1370,7 +1370,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt7 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt7 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt7.has_value()); auto publish_upd_t3 = am::v5::publish_packet( *pid_opt7, @@ -1382,7 +1382,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - auto pid_opt8 = ep.acquire_unique_packet_id(as::use_future).get(); + auto pid_opt8 = ep->acquire_unique_packet_id(as::use_future).get(); BOOST_TEST(pid_opt8.has_value()); auto publish_use_ta1_t3 = am::v5::publish_packet( *pid_opt8, @@ -1404,7 +1404,7 @@ BOOST_AUTO_TEST_CASE(recv_server) { } ); - ep.next_layer().set_recv_packets( + ep->next_layer().set_recv_packets( { // receive packets publish_reg_t1, @@ -1424,34 +1424,34 @@ BOOST_AUTO_TEST_CASE(recv_server) { // recv publish_reg_t1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_reg_t1, pv)); } // recv publish_use_ta1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t1, pv)); } // recv publish_reg_t2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_reg_t2, pv)); } // recv publish_use_ta2 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t2, pv)); } bool close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -1459,24 +1459,24 @@ BOOST_AUTO_TEST_CASE(recv_server) { ); // recv publish_reg_t3 (invalid) { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } init(); close_called = false; - ep.next_layer().set_close_checker( + ep->next_layer().set_close_checker( [&] { close_called = true; } ); // internal auto send disconnect - ep.next_layer().set_write_packet_checker( + ep->next_layer().set_write_packet_checker( [&](am::packet_variant wp) { BOOST_TEST(!close_called); BOOST_TEST(am::packet_compare(disconnect, wp)); @@ -1484,31 +1484,31 @@ BOOST_AUTO_TEST_CASE(recv_server) { ); // recv publish_use_ta3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); BOOST_TEST(pv.get_if()->code() == am::errc::bad_message); } BOOST_TEST(close_called); // recv close { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(pv.get_if() != nullptr); } init(); // recv publish_upd_t3 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_upd_t3, pv)); } // recv publish_use_ta1 { - auto pv = ep.recv(as::use_future).get(); + auto pv = ep->recv(as::use_future).get(); BOOST_TEST(am::packet_compare(publish_exp_t3, pv)); } - ep.close(as::use_future).get(); + ep->close(as::use_future).get(); guard.reset(); th.join(); } diff --git a/test/unit/ut_static_assert_fail_client.cpp b/test/unit/ut_static_assert_fail_client.cpp index 697aaa177..734334acb 100644 --- a/test/unit/ut_static_assert_fail_client.cpp +++ b/test/unit/ut_static_assert_fail_client.cpp @@ -18,17 +18,17 @@ namespace as = boost::asio; BOOST_AUTO_TEST_CASE(tc) { auto version = am::protocol_version::v3_1_1; as::io_context ioc; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto p = am::v3_1_1::connack_packet{ true, // session_present am::connect_return_code::not_authorized }; // static_assert fail as expected - auto ec = ep.send(p, as::use_future).get(); + auto ec = ep->send(p, as::use_future).get(); BOOST_TEST(!ec); } diff --git a/test/unit/ut_static_assert_fail_server.cpp b/test/unit/ut_static_assert_fail_server.cpp index fceb7af34..9706865a0 100644 --- a/test/unit/ut_static_assert_fail_server.cpp +++ b/test/unit/ut_static_assert_fail_server.cpp @@ -18,12 +18,12 @@ namespace as = boost::asio; BOOST_AUTO_TEST_CASE(tc) { auto version = am::protocol_version::v3_1_1; as::io_context ioc; - am::endpoint ep{ + auto ep = am::endpoint::create( version, // for stub_socket args version, ioc - }; + ); auto p = am::v3_1_1::connect_packet{ true, // clean_session 0x0, // keep_alive @@ -33,6 +33,6 @@ BOOST_AUTO_TEST_CASE(tc) { am::allocate_buffer("pass1") }; // static_assert fail as expected - auto ec = ep.send(p, as::use_future).get(); + auto ec = ep->send(p, as::use_future).get(); BOOST_TEST(!ec); } diff --git a/test/unit/ut_strm.cpp b/test/unit/ut_strm.cpp index 607cd546e..adda30cc7 100644 --- a/test/unit/ut_strm.cpp +++ b/test/unit/ut_strm.cpp @@ -23,7 +23,7 @@ namespace am = async_mqtt; namespace as = boost::asio; // packet_id is hard coded in this test case for just testing. -// but users need to get packet_id via ep.acquire_unique_packet_id(...) +// but users need to get packet_id via ep->acquire_unique_packet_id(...) // see other test cases. // v3_1_1 @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(write_cont) { as::io_context ioc; using strm_t = am::stream; - auto s = std::make_shared( + auto s = strm_t::create( // for stub_socket args version, ioc diff --git a/tool/bench.cpp b/tool/bench.cpp index efd2c7bf7..b9bd9146d 100644 --- a/tool/bench.cpp +++ b/tool/bench.cpp @@ -1958,7 +1958,7 @@ int main(int argc, char *argv[]) { std::size_t hps_index = target_index; for (std::size_t i = 0; i != clients; ++i) { cis.emplace_back( - std::make_shared( + client_t::create( version, iocs.at(i % num_of_iocs).get_executor() ), @@ -2023,7 +2023,7 @@ int main(int argc, char *argv[]) { ctx.set_verify_mode(am::tls::verify_none); } cis.emplace_back( - std::make_shared( + client_t::create( version, iocs.at(i % num_of_iocs).get_executor(), ctx @@ -2086,7 +2086,7 @@ int main(int argc, char *argv[]) { std::size_t hps_index = target_index; for (std::size_t i = 0; i != clients; ++i) { cis.emplace_back( - std::make_shared( + client_t::create( version, iocs.at(i % num_of_iocs).get_executor() ), @@ -2156,7 +2156,7 @@ int main(int argc, char *argv[]) { ctx.set_verify_mode(am::tls::verify_none); } cis.emplace_back( - std::make_shared( + client_t::create( version, iocs.at(i % num_of_iocs).get_executor(), ctx diff --git a/tool/broker.cpp b/tool/broker.cpp index 73f34c412..5ffa1a4ef 100644 --- a/tool/broker.cpp +++ b/tool/broker.cpp @@ -222,7 +222,7 @@ void run_broker(boost::program_options::variables_map const& vm) { mqtt_async_accept = [&] { auto epsp = - std::make_shared>( + am::endpoint::create( am::protocol_version::undetermined, con_ioc_getter().get_executor() ); @@ -258,7 +258,7 @@ void run_broker(boost::program_options::variables_map const& vm) { ws_async_accept = [&] { auto epsp = - std::make_shared>( + am::endpoint::create( am::protocol_version::undetermined, con_ioc_getter().get_executor() ); @@ -345,7 +345,7 @@ void run_broker(boost::program_options::variables_map const& vm) { } ); auto epsp = - std::make_shared>( + am::endpoint::create( am::protocol_version::undetermined, con_ioc_getter().get_executor(), *mqtts_ctx @@ -433,7 +433,7 @@ void run_broker(boost::program_options::variables_map const& vm) { } ); auto epsp = - std::make_shared>( + am::endpoint::create( am::protocol_version::undetermined, con_ioc_getter().get_executor(), *wss_ctx diff --git a/tool/client_cli.cpp b/tool/client_cli.cpp index dacd890c4..83931386b 100644 --- a/tool/client_cli.cpp +++ b/tool/client_cli.cpp @@ -1086,12 +1086,12 @@ int main(int argc, char* argv[]) { if (protocol == "mqtt") { as::ip::tcp::socket resolve_sock{ioc}; as::ip::tcp::resolver res{resolve_sock.get_executor()}; - am::endpoint amep { + auto amep = am::endpoint::create( version, ioc.get_executor() - }; - auto cc = client_cli{ioc, amep, version}; - auto nm = network_manager{amep, res, vm, version}; + ); + auto cc = client_cli{ioc, *amep, version}; + auto nm = network_manager{*amep, res, vm, version}; nm(); ioc.run(); return 0; @@ -1120,13 +1120,13 @@ int main(int argc, char* argv[]) { ctx.use_certificate_chain_file(vm["certificate"].as()); ctx.use_private_key_file(vm["private_key"].as(), boost::asio::ssl::context::pem); } - am::endpoint amep { + auto amep = am::endpoint::create( version, ioc.get_executor(), ctx - }; - auto cc = client_cli{ioc, amep, version}; - auto nm = network_manager{amep, res, vm, version}; + ); + auto cc = client_cli{ioc, *amep, version}; + auto nm = network_manager{*amep, res, vm, version}; nm(); ioc.run(); return 0; @@ -1136,12 +1136,12 @@ int main(int argc, char* argv[]) { else if (protocol == "ws") { as::ip::tcp::socket resolve_sock{ioc}; as::ip::tcp::resolver res{resolve_sock.get_executor()}; - am::endpoint amep { + auto amep = am::endpoint::create( version, ioc.get_executor() - }; - auto cc = client_cli{ioc, amep, version}; - auto nm = network_manager{amep, res, vm, version}; + ); + auto cc = client_cli{ioc, *amep, version}; + auto nm = network_manager{*amep, res, vm, version}; nm(); ioc.run(); return 0; @@ -1171,13 +1171,13 @@ int main(int argc, char* argv[]) { ctx.use_certificate_chain_file(vm["certificate"].as()); ctx.use_private_key_file(vm["private_key"].as(), boost::asio::ssl::context::pem); } - am::endpoint amep { + auto amep = am::endpoint::create( version, ioc.get_executor(), ctx - }; - auto cc = client_cli{ioc, amep, version}; - auto nm = network_manager{amep, res, vm, version}; + ); + auto cc = client_cli{ioc, *amep, version}; + auto nm = network_manager{*amep, res, vm, version}; nm(); ioc.run(); return 0;