mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-07-29 20:17:37 +02:00
async_run
Reviewers: ivica Reviewed By: ivica Subscribers: korina Differential Revision: https://repo.mireo.local/D27342
This commit is contained in:
@ -107,7 +107,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
c.credentials("test-client", "username", "password")
|
||||
.brokers("mqtt.broker", 1883)
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
run_with_callbacks(c);
|
||||
|
||||
|
@ -165,7 +165,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
c.credentials("test-client", "username", "password")
|
||||
.brokers("mqtt.broker", 1883)
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
co_spawn(ioc.get_executor(), coroutine(c), asio::detached);
|
||||
// or...
|
||||
|
@ -96,7 +96,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
c.credentials("test-client", "", "")
|
||||
.brokers("mqtt.broker", 1883)
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
for (int i = 0; i < thread_num - 1; ++i)
|
||||
threads.emplace_back([&ioc] { ioc.run(); });
|
||||
@ -108,4 +108,3 @@ int main(int argc, char** argv) {
|
||||
for (auto& t : threads)
|
||||
if (t.joinable()) t.join();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ void publish_qos0_openssl_tls() {
|
||||
c.credentials("test-qos0-openssl-tls", "", "")
|
||||
.brokers("emqtt.mireo.local", 8883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_most_once>(
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
@ -103,7 +103,7 @@ void publish_qos1_openssl_tls() {
|
||||
c.credentials("test-qos1-openssl-tls", "", "")
|
||||
.brokers("emqtt.mireo.local", 8883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_least_once>(
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
@ -138,7 +138,7 @@ void publish_qos2_openssl_tls() {
|
||||
c.credentials("test-qos2-openssl-tls", "", "")
|
||||
.brokers("emqtt.mireo.local", 8883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
@ -173,7 +173,7 @@ void subscribe_and_receive_openssl_tls(int num_receive) {
|
||||
c.credentials("test-subscriber-openssl-tls", "", "")
|
||||
.brokers("emqtt.mireo.local", 8883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
|
||||
std::vector<subscribe_topic> topics;
|
||||
|
@ -19,9 +19,9 @@ asio::awaitable<void> client_publisher(asio::io_context& ioc) {
|
||||
async_mqtt5::mqtt_client<asio::ip::tcp::socket> client(ioc, "");
|
||||
|
||||
// Configure the ``__Client__``.
|
||||
// It is mandatory to call brokers() and run() to configure the Brokers to connect to and start the Client.
|
||||
// It is mandatory to call brokers() and async_run() to configure the Brokers to connect to and start the Client.
|
||||
client.brokers("mqtt.broker", 1883) // Broker that we want to connect to. 1883 is the default TCP port.
|
||||
.run(); // Start the client.
|
||||
.async_run(asio::detached); // Start the client.
|
||||
|
||||
// Publish an Application Message with QoS 1.
|
||||
auto [rc, props] = co_await client.async_publish<async_mqtt5::qos_e::at_least_once>(
|
||||
|
@ -19,9 +19,9 @@ asio::awaitable<void> client_receiver(asio::io_context& ioc) {
|
||||
async_mqtt5::mqtt_client<asio::ip::tcp::socket> client(ioc, "");
|
||||
|
||||
// Configure the``__Client__``.
|
||||
// It is mandatory to call brokers() and run() to configure the Brokers to connect to and start the Client.
|
||||
// It is mandatory to call brokers() and async_run() to configure the Brokers to connect to and start the Client.
|
||||
client.brokers("mqtt.broker", 1883) // Broker that we want to connect to. 1883 is the default TCP port.
|
||||
.run(); // Start the client.
|
||||
.async_run(asio::detached); // Start the client.
|
||||
|
||||
// Configure the request to subscribe to a Topic.
|
||||
async_mqtt5::subscribe_topic sub_topic = async_mqtt5::subscribe_topic {
|
||||
|
@ -24,7 +24,7 @@ void publish_qos0_tcp() {
|
||||
.brokers("emqtt.mireo.local", 1883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.connect_properties(std::move(props))
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_most_once>(
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
@ -52,7 +52,7 @@ void publish_qos1_tcp() {
|
||||
c.credentials("test-qos1-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local", 1883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_least_once>(
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
@ -79,7 +79,7 @@ void publish_qos2_tcp() {
|
||||
c.credentials("test-qos2-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local", 1883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
@ -107,7 +107,7 @@ void subscribe_and_receive_tcp(int num_receive) {
|
||||
c.credentials("test-subscriber-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local", 1883)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_subscribe(
|
||||
{ "test/mqtt-test", { qos_e::exactly_once } }, subscribe_props {},
|
||||
|
@ -25,7 +25,7 @@ void publish_qos0_websocket_tcp() {
|
||||
c.credentials("test-qos0-websocket-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8083)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_most_once>(
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
@ -55,7 +55,7 @@ void publish_qos1_websocket_tcp() {
|
||||
c.credentials("test-qos1-websocket-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8083)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_least_once>(
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
@ -86,7 +86,7 @@ void publish_qos2_websocket_tcp() {
|
||||
c.credentials("test-qos2-websocket-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8083)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
@ -118,7 +118,7 @@ void subscribe_and_receive_websocket_tcp(int num_receive) {
|
||||
c.credentials("test-subscriber-websocket-tcp", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8083)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
std::vector<subscribe_topic> topics;
|
||||
topics.push_back(subscribe_topic{
|
||||
|
@ -85,7 +85,7 @@ void publish_qos0_websocket_tls() {
|
||||
c.credentials("test-qos0-websocket-tls", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8884)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", async_mqtt5::qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_most_once>(
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
@ -120,7 +120,7 @@ void publish_qos1_websocket_tls() {
|
||||
c.credentials("test-qos1-websocket-tls", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8884)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::at_least_once>(
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
@ -156,7 +156,7 @@ void publish_qos2_websocket_tls() {
|
||||
c.credentials("test-qos2-websocket-tls", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8884)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
@ -193,7 +193,7 @@ void subscribe_and_receive_websocket_tls(int num_receive) {
|
||||
c.credentials("test-subscriber-websocket-tls", "", "")
|
||||
.brokers("emqtt.mireo.local/mqtt", 8884)
|
||||
.will({ "test/mqtt-test", "Client disconnected!", qos_e::at_least_once })
|
||||
.run();
|
||||
.async_run(asio::detached);
|
||||
|
||||
std::vector<subscribe_topic> topics;
|
||||
topics.push_back(subscribe_topic{
|
||||
|
Reference in New Issue
Block a user