diff --git a/client/pub_client.c b/client/pub_client.c index f3d150e4..e35c1a76 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -180,7 +180,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag }else{ err_printf(&cfg, "Connection error: %s\n", mosquitto_connack_string(result)); } - mosquitto_disconnect_v5(mosq, 0, cfg.disconnect_props); + // let the loop know that this is an unrecoverable connection + status = STATUS_NOHOPE; } } } @@ -252,6 +253,10 @@ int pub_stdin_line_loop(struct mosquitto *mosq) #endif } + if(status == STATUS_NOHOPE){ + return MOSQ_ERR_CONN_REFUSED; + } + if(status == STATUS_CONNACK_RECVD){ pos = 0; read_len = line_buf_len; diff --git a/client/pub_shared.h b/client/pub_shared.h index fd2102a3..5a33ade2 100644 --- a/client/pub_shared.h +++ b/client/pub_shared.h @@ -21,6 +21,7 @@ Contributors: #define STATUS_WAITING 2 #define STATUS_DISCONNECTING 3 #define STATUS_DISCONNECTED 4 +#define STATUS_NOHOPE 5 extern int mid_sent; extern struct mosq_config cfg;