mosquitto/test/lib/cpp/01-will-unpwd-set.cpp

62 lines
941 B
C++
Raw Permalink Normal View History

2014-05-08 00:27:00 +02:00
#include <cstring>
2023-12-23 13:59:58 +01:00
#include <mosquitto/libmosquittopp.h>
2014-05-08 00:27:00 +02:00
static int run = -1;
class mosquittopp_test : public mosqpp::mosquittopp
{
2025-09-17 12:19:46 +02:00
public:
mosquittopp_test(const char *id);
2025-09-17 12:19:46 +02:00
void on_connect(int rc);
void on_disconnect(int rc);
2014-05-08 00:27:00 +02:00
};
mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
{
}
2025-09-17 12:19:46 +02:00
void mosquittopp_test::on_connect(int rc)
{
if(rc){
exit(1);
}else{
disconnect();
}
}
2025-09-17 12:19:46 +02:00
void mosquittopp_test::on_disconnect(int rc)
{
run = rc;
}
2025-09-17 12:19:46 +02:00
2014-05-08 00:27:00 +02:00
int main(int argc, char *argv[])
{
2024-02-26 01:19:49 +01:00
mosquittopp_test *mosq;
2014-05-08 00:27:00 +02:00
if(argc != 2){
return 1;
}
int port = atoi(argv[1]);
2014-05-08 00:27:00 +02:00
mosqpp::lib_init();
mosq = new mosquittopp_test("01-will-unpwd-set");
mosq->username_pw_set("oibvvwqw", "#'^2hg9a&nm38*us");
mosq->will_set("will-topic", strlen("will message"), "will message", 2, false);
mosq->connect("localhost", port, 60);
2014-05-08 00:27:00 +02:00
while(run == -1){
mosq->loop();
}
2020-05-05 12:56:10 +02:00
delete mosq;
2014-05-08 00:27:00 +02:00
mosqpp::lib_cleanup();
return run;
}