// // Copyright (c) 2023-2024 Ivica Siladic, Bruno Iljazovic, Korina Simicevic // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) // #include #include #ifdef BOOST_ASIO_HAS_CO_AWAIT #include #include #include // std::monostate #include #include #include #include #include #include // async_teardown for asio::ssl::socket #include namespace async_mqtt5 { namespace asio = boost::asio; template struct tls_handshake_type> { static constexpr auto client = asio::ssl::stream_base::client; static constexpr auto server = asio::ssl::stream_base::server; }; template void assign_tls_sni( const authority_path& /* ap */, asio::ssl::context& /* ctx */, asio::ssl::stream& /* stream */ ) {} namespace test { // the following code needs to compile template asio::awaitable test_default_completion_tokens_impl( TlsContextType tls_context = {} ) { asio::io_context ioc; using client_type = asio::use_awaitable_t<>::as_default_on_t< mqtt_client >; client_type c(ioc, std::move(tls_context)); co_await c.async_run(); auto pub_props = publish_props {}; co_await c.template async_publish( "topic", "payload", retain_e::no, pub_props ); auto sub_topic = subscribe_topic {}; auto sub_topics = std::vector { sub_topic }; auto sub_props = subscribe_props {}; co_await c.async_subscribe(sub_topics, sub_props); co_await c.async_subscribe(sub_topic, sub_props); auto unsub_topics = std::vector {}; auto unsub_props = unsubscribe_props {}; co_await c.async_unsubscribe(unsub_topics, unsub_props); co_await c.async_unsubscribe("topic", unsub_props); co_await c.async_receive(); auto dc_props = disconnect_props {}; co_await c.async_disconnect(); co_await c.async_disconnect(disconnect_rc_e::normal_disconnection, dc_props); } asio::awaitable test_default_completion_tokens() { co_await test_default_completion_tokens_impl(); co_await test_default_completion_tokens_impl< asio::ssl::stream, asio::ssl::context >(asio::ssl::context(asio::ssl::context::tls_client)); co_await test_default_completion_tokens_impl< boost::beast::websocket::stream >(); co_await test_default_completion_tokens_impl< boost::beast::websocket::stream>, asio::ssl::context >(asio::ssl::context(asio::ssl::context::tls_client)); } } // end namespace test } // end namespace async_mqtt5 #endif // BOOST_ASIO_HAS_CO_AWAIT