|
|
|
@ -45,13 +45,18 @@ struct mosquitto *mosq = NULL;
|
|
|
|
|
int last_mid = 0;
|
|
|
|
|
static bool timed_out = false;
|
|
|
|
|
static int connack_result = 0;
|
|
|
|
|
bool connack_received = false;
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
void my_signal_handler(int signum)
|
|
|
|
|
{
|
|
|
|
|
if(signum == SIGALRM || signum == SIGTERM || signum == SIGINT){
|
|
|
|
|
if(connack_received){
|
|
|
|
|
process_messages = false;
|
|
|
|
|
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
|
|
|
|
|
}else{
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(signum == SIGALRM){
|
|
|
|
|
timed_out = true;
|
|
|
|
@ -123,6 +128,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
|
|
|
|
|
UNUSED(flags);
|
|
|
|
|
UNUSED(properties);
|
|
|
|
|
|
|
|
|
|
connack_received = true;
|
|
|
|
|
|
|
|
|
|
connack_result = result;
|
|
|
|
|
if(!result){
|
|
|
|
|
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);
|
|
|
|
|