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);
|
2014-05-08 00:27:00 +02:00
|
|
|
|
2025-09-17 12:19:46 +02:00
|
|
|
void on_connect(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
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
void mosquittopp_test::on_connect(int rc)
|
|
|
|
|
{
|
|
|
|
|
if(rc){
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2025-08-24 00:15:16 +02:00
|
|
|
if(argc != 2){
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2018-04-16 11:02:22 +02:00
|
|
|
int port = atoi(argv[1]);
|
2022-02-01 10:52:41 +01:00
|
|
|
int rc;
|
2018-04-16 11:02:22 +02:00
|
|
|
|
2014-05-08 00:27:00 +02:00
|
|
|
mosqpp::lib_init();
|
|
|
|
|
|
|
|
|
|
mosq = new mosquittopp_test("01-keepalive-pingreq");
|
|
|
|
|
|
2020-01-30 16:06:15 +01:00
|
|
|
mosq->connect("localhost", port, 5);
|
2014-05-08 00:27:00 +02:00
|
|
|
|
|
|
|
|
while(run == -1){
|
2022-02-01 10:52:41 +01:00
|
|
|
rc = mosq->loop();
|
2025-09-17 12:19:46 +02:00
|
|
|
if(rc){
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-05-08 00:27:00 +02:00
|
|
|
}
|
2020-08-12 12:01:28 +02:00
|
|
|
delete mosq;
|
2014-05-08 00:27:00 +02:00
|
|
|
|
|
|
|
|
mosqpp::lib_cleanup();
|
|
|
|
|
|
|
|
|
|
return run;
|
|
|
|
|
}
|