2023-12-23 13:59:58 +01:00
|
|
|
#include <mosquitto/libmosquittopp.h>
|
2023-01-02 12:42:57 +01: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);
|
2023-01-02 12:42:57 +01:00
|
|
|
|
2025-09-17 12:19:46 +02:00
|
|
|
void on_connect(int rc);
|
2023-01-02 12:42:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-17 12:19:46 +02:00
|
|
|
|
2023-01-02 12:42:57 +01:00
|
|
|
void mosquittopp_test::on_connect(int rc)
|
|
|
|
|
{
|
|
|
|
|
if(rc){
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-17 12:19:46 +02:00
|
|
|
|
2023-01-02 12:42:57 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2024-02-26 01:19:49 +01:00
|
|
|
mosquittopp_test *mosq;
|
2023-01-02 12:42:57 +01:00
|
|
|
|
2025-08-24 00:15:16 +02:00
|
|
|
if(argc != 2){
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2023-01-02 12:42:57 +01:00
|
|
|
int port = atoi(argv[1]);
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
mosqpp::lib_init();
|
|
|
|
|
|
|
|
|
|
mosq = new mosquittopp_test("01-server-keepalive-pingreq");
|
|
|
|
|
mosq->int_option(MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
|
|
|
|
|
|
|
|
|
|
mosq->connect("localhost", port, 60);
|
|
|
|
|
|
|
|
|
|
while(run == -1){
|
|
|
|
|
rc = mosq->loop();
|
2025-09-17 12:19:46 +02:00
|
|
|
if(rc){
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-01-02 12:42:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete mosq;
|
|
|
|
|
mosqpp::lib_cleanup();
|
|
|
|
|
|
|
|
|
|
return run;
|
|
|
|
|
}
|