mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-07-30 04:27:34 +02:00
[mqtt-client] add readme & license, doc fixes
Summary: resolves T13126 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Maniphest Tasks: T13126 Differential Revision: https://repo.mireo.local/D26629
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/asio/co_spawn.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
@ -55,6 +55,7 @@ constexpr char spacetime_ca[] =
|
||||
;
|
||||
|
||||
void publish_qos0_openssl_tls() {
|
||||
std::cout << "[Test-publish-qos0-openssl-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -77,7 +78,7 @@ void publish_qos0_openssl_tls() {
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec) {
|
||||
fmt::print("[Test-publish-qos0-openssl-tls] error_code: {}\n", ec.message());
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -87,6 +88,7 @@ void publish_qos0_openssl_tls() {
|
||||
}
|
||||
|
||||
void publish_qos1_openssl_tls() {
|
||||
std::cout << "[Test-publish-qos1-openssl-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -109,10 +111,8 @@ void publish_qos1_openssl_tls() {
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, puback_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos1-openssl-tls] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -123,6 +123,7 @@ void publish_qos1_openssl_tls() {
|
||||
|
||||
|
||||
void publish_qos2_openssl_tls() {
|
||||
std::cout << "[Test-publish-qos2-openssl-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -145,10 +146,8 @@ void publish_qos2_openssl_tls() {
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, pubcomp_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos2-openssl-tls] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -159,6 +158,7 @@ void publish_qos2_openssl_tls() {
|
||||
|
||||
|
||||
void subscribe_and_receive_openssl_tls(int num_receive) {
|
||||
std::cout << "[Test-subscribe-and-receive-openssl-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -193,10 +193,8 @@ void subscribe_and_receive_openssl_tls(int num_receive) {
|
||||
[](error_code ec, std::vector<reason_code> codes, suback_props) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-openssl-tls] subscribe error_code: {},"
|
||||
" reason_code: {}\n", ec.message(), codes[0].message()
|
||||
);
|
||||
std::cout << "subscribe error_code: " << ec.message() << std::endl;
|
||||
std::cout << "subscribe reason_code: " << codes[0].message() << std::endl;
|
||||
}
|
||||
);
|
||||
|
||||
@ -209,11 +207,10 @@ void subscribe_and_receive_openssl_tls(int num_receive) {
|
||||
) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-openssl-tls] message {}/{}:"
|
||||
"ec: {}, topic: {}, payload: {}\n",
|
||||
i + 1, num_receive, ec.message(), topic, payload
|
||||
);
|
||||
std::cout << "message " << i + 1 << "/" << num_receive << std::endl;
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "topic: " << topic << std::endl;
|
||||
std::cout << "payload: " << payload << std::endl;
|
||||
|
||||
if (i == num_receive - 1)
|
||||
c.cancel();
|
||||
@ -226,6 +223,7 @@ void subscribe_and_receive_openssl_tls(int num_receive) {
|
||||
}
|
||||
|
||||
void test_coro() {
|
||||
std::cout << "[Test-coro-openssl-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -258,10 +256,11 @@ void test_coro() {
|
||||
auto [codes, props] = co_await c.async_subscribe(
|
||||
topics, subscribe_props {}, asio::use_awaitable
|
||||
);
|
||||
fmt::print("Subscribe result: ({}),", codes[0].message());
|
||||
std::cout << "subscribe reason_code: " << codes[0].message() << std::endl;
|
||||
|
||||
auto [topic, payload, rec_props] = co_await c.async_receive(asio::use_awaitable);
|
||||
fmt::print("Receive from topic {}: {}\n", topic, payload);
|
||||
std::cout << "topic: " << topic << std::endl;
|
||||
std::cout << "payload: " << payload << std::endl;
|
||||
|
||||
asio::steady_timer timer(ioc);
|
||||
timer.expires_from_now(std::chrono::seconds(1));
|
||||
|
@ -7,9 +7,9 @@ void run_websocket_tls_examples();
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
run_tcp_examples();
|
||||
//run_openssl_tls_examples();
|
||||
//run_websocket_tcp_examples();
|
||||
//run_websocket_tls_examples();
|
||||
run_openssl_tls_examples();
|
||||
run_websocket_tcp_examples();
|
||||
run_websocket_tls_examples();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
namespace asio = boost::asio;
|
||||
|
||||
void publish_qos0_tcp() {
|
||||
fmt::print("[Test-publish-qos0-tcp]\n");
|
||||
std::cout << "[Test-publish-qos0-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -26,7 +26,7 @@ void publish_qos0_tcp() {
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec) {
|
||||
fmt::print("\terror_code: {}\n", ec.message());
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -36,7 +36,7 @@ void publish_qos0_tcp() {
|
||||
|
||||
|
||||
void publish_qos1_tcp() {
|
||||
fmt::print("[Test-publish-qos1-tcp]\n");
|
||||
std::cout << "[Test-publish-qos1-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -53,10 +53,8 @@ void publish_qos1_tcp() {
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
retain_e::no, publish_props {},
|
||||
[&c](error_code ec, reason_code rc, puback_props) {
|
||||
fmt::print(
|
||||
"\terror_code: {}, reason_code: {}\n",
|
||||
ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -65,7 +63,7 @@ void publish_qos1_tcp() {
|
||||
}
|
||||
|
||||
void publish_qos2_tcp() {
|
||||
fmt::print("[Test-publish-qos2-tcp]\n");
|
||||
std::cout << "[Test-publish-qos2-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -80,12 +78,10 @@ void publish_qos2_tcp() {
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
retain_e::no, publish_props{},
|
||||
retain_e::no, publish_props {},
|
||||
[&c](error_code ec, reason_code rc, pubcomp_props) {
|
||||
fmt::print(
|
||||
"\terror_code: {}, reason_code: {}\n",
|
||||
ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -95,7 +91,7 @@ void publish_qos2_tcp() {
|
||||
|
||||
|
||||
void subscribe_and_receive_tcp(int num_receive) {
|
||||
fmt::print("[Test-subscribe-and-receive-tcp]\n");
|
||||
std::cout << "[Test-subscribe-and-receive-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -113,10 +109,8 @@ void subscribe_and_receive_tcp(int num_receive) {
|
||||
[](error_code ec, std::vector<reason_code> codes, suback_props) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"\tsubscribe error_code: {}, reason_code: {}\n",
|
||||
ec.message(), codes[0].message()
|
||||
);
|
||||
std::cout << "subscribe error_code: " << ec.message() << std::endl;
|
||||
std::cout << "subscribe reason_code: " << codes[0].message() << std::endl;
|
||||
}
|
||||
);
|
||||
|
||||
@ -129,10 +123,10 @@ void subscribe_and_receive_tcp(int num_receive) {
|
||||
) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"\tmessage {}/{}: ec: {}, topic: {}, payload: {}\n",
|
||||
i + 1, num_receive, ec.message(), topic, payload
|
||||
);
|
||||
std::cout << "message " << i + 1 << "/" << num_receive << std::endl;
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "topic: " << topic << std::endl;
|
||||
std::cout << "payload: " << payload << std::endl;
|
||||
|
||||
if (i == num_receive - 1)
|
||||
c.cancel();
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
namespace asio = boost::asio;
|
||||
|
||||
void publish_qos0_websocket_tcp() {
|
||||
std::cout << "[Test-publish-qos0-websocket-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -30,7 +31,7 @@ void publish_qos0_websocket_tcp() {
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec) {
|
||||
fmt::print("[Test-publish-qos0-websocket-tcp] error_code: {}\n", ec.message());
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -40,6 +41,7 @@ void publish_qos0_websocket_tcp() {
|
||||
}
|
||||
|
||||
void publish_qos1_websocket_tcp() {
|
||||
std::cout << "[Test-publish-qos1-websocket-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -59,10 +61,8 @@ void publish_qos1_websocket_tcp() {
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
async_mqtt5::retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, puback_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos1-websocket-tcp] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -72,6 +72,7 @@ void publish_qos1_websocket_tcp() {
|
||||
}
|
||||
|
||||
void publish_qos2_websocket_tcp() {
|
||||
std::cout << "[Test-publish-qos2-websocket-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -91,10 +92,8 @@ void publish_qos2_websocket_tcp() {
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, pubcomp_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos2-websocket-tcp] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -105,6 +104,7 @@ void publish_qos2_websocket_tcp() {
|
||||
|
||||
|
||||
void subscribe_and_receive_websocket_tcp(int num_receive) {
|
||||
std::cout << "[Test-subscribe-and-receive-websocket-tcp]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -135,10 +135,8 @@ void subscribe_and_receive_websocket_tcp(int num_receive) {
|
||||
[](error_code ec, std::vector<reason_code> codes, suback_props) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-websocket-tcp] "
|
||||
" error_code: {}, reason_code: {}\n", ec.message(), codes[0].message()
|
||||
);
|
||||
std::cout << "subscribe error_code: " << ec.message() << std::endl;
|
||||
std::cout << "subscribe reason_code: " << codes[0].message() << std::endl;
|
||||
}
|
||||
);
|
||||
|
||||
@ -150,11 +148,10 @@ void subscribe_and_receive_websocket_tcp(int num_receive) {
|
||||
) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-websocket-tcp] message {}/{}:"
|
||||
"ec: {}, topic: {}, payload: {}\n",
|
||||
i + 1, num_receive, ec.message(), topic, payload
|
||||
);
|
||||
std::cout << "message " << i + 1 << "/" << num_receive << std::endl;
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "topic: " << topic << std::endl;
|
||||
std::cout << "payload: " << payload << std::endl;
|
||||
|
||||
if (i == num_receive - 1)
|
||||
c.cancel();
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
@ -68,6 +68,7 @@ constexpr const char spacetime_ca[] =
|
||||
;
|
||||
|
||||
void publish_qos0_websocket_tls() {
|
||||
std::cout << "[Test-publish-qos0-websocket-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -92,7 +93,7 @@ void publish_qos0_websocket_tls() {
|
||||
"test/mqtt-test", "hello world with qos0!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec) {
|
||||
fmt::print("[Test-publish-qos0-websocket-tls] error_code: {}\n", ec.message());
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -102,6 +103,7 @@ void publish_qos0_websocket_tls() {
|
||||
}
|
||||
|
||||
void publish_qos1_websocket_tls() {
|
||||
std::cout << "[Test-publish-qos1-websocket-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -126,10 +128,8 @@ void publish_qos1_websocket_tls() {
|
||||
"test/mqtt-test", "hello world with qos1!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, puback_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos1-websocket-tls] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -139,6 +139,7 @@ void publish_qos1_websocket_tls() {
|
||||
}
|
||||
|
||||
void publish_qos2_websocket_tls() {
|
||||
std::cout << "[Test-publish-qos2-websocket-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -163,10 +164,8 @@ void publish_qos2_websocket_tls() {
|
||||
"test/mqtt-test", "hello world with qos2!",
|
||||
retain_e::no, publish_props{},
|
||||
[&c](error_code ec, reason_code rc, pubcomp_props) {
|
||||
fmt::print(
|
||||
"[Test-publish-qos2-websocket-tls] "
|
||||
"error_code: {}, reason_code: {}\n", ec.message(), rc.message()
|
||||
);
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "reason_code: " << rc.message() << std::endl;
|
||||
c.cancel();
|
||||
}
|
||||
);
|
||||
@ -177,6 +176,7 @@ void publish_qos2_websocket_tls() {
|
||||
|
||||
|
||||
void subscribe_and_receive_websocket_tls(int num_receive) {
|
||||
std::cout << "[Test-subscribe-and-receive-websocket-tls]" << std::endl;
|
||||
using namespace async_mqtt5;
|
||||
asio::io_context ioc;
|
||||
|
||||
@ -212,10 +212,8 @@ void subscribe_and_receive_websocket_tls(int num_receive) {
|
||||
[](error_code ec, std::vector<reason_code> codes, suback_props) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-websocket-tls] "
|
||||
" error_code: {}, reason_code: {}\n", ec.message(), codes[0].message()
|
||||
);
|
||||
std::cout << "subscribe error_code: " << ec.message() << std::endl;
|
||||
std::cout << "subscribe reason_code: " << codes[0].message() << std::endl;
|
||||
}
|
||||
);
|
||||
|
||||
@ -227,11 +225,10 @@ void subscribe_and_receive_websocket_tls(int num_receive) {
|
||||
) {
|
||||
if (ec == asio::error::operation_aborted)
|
||||
return;
|
||||
fmt::print(
|
||||
"[Test-subscribe-and-receive-websocket-tls] message {}/{}:"
|
||||
"ec: {}, topic: {}, payload: {}\n",
|
||||
i + 1, num_receive, ec.message(), topic, payload
|
||||
);
|
||||
std::cout << "message " << i + 1 << "/" << num_receive << std::endl;
|
||||
std::cout << "error_code: " << ec.message() << std::endl;
|
||||
std::cout << "topic: " << topic << std::endl;
|
||||
std::cout << "payload: " << payload << std::endl;
|
||||
|
||||
if (i == num_receive - 1)
|
||||
c.cancel();
|
||||
|
Reference in New Issue
Block a user