mosquitto_pub: exit if broker actively refuses a connection

Fixes eclipse/mosquitto#1904

If the broker rejects the connection, as opposed to the broker being
down, then there is no hope to establish a connection.  This adds a
status flag so we can signal to the loop that we should just exit.

Signed-off-by: Dan White <dan.white@valpo.edu>
This commit is contained in:
Dan White 2020-11-17 15:11:24 -06:00 committed by Roger Light
parent cdfa2252f1
commit 2f4207e833
2 changed files with 7 additions and 1 deletions

View File

@ -180,7 +180,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
}else{ }else{
err_printf(&cfg, "Connection error: %s\n", mosquitto_connack_string(result)); 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;
} }
} }
} }
@ -246,6 +247,10 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
#endif #endif
} }
if(status == STATUS_NOHOPE){
return MOSQ_ERR_CONN_REFUSED;
}
if(status == STATUS_CONNACK_RECVD){ if(status == STATUS_CONNACK_RECVD){
pos = 0; pos = 0;
read_len = line_buf_len; read_len = line_buf_len;

View File

@ -21,6 +21,7 @@ Contributors:
#define STATUS_WAITING 2 #define STATUS_WAITING 2
#define STATUS_DISCONNECTING 3 #define STATUS_DISCONNECTING 3
#define STATUS_DISCONNECTED 4 #define STATUS_DISCONNECTED 4
#define STATUS_NOHOPE 5
extern int mid_sent; extern int mid_sent;
extern struct mosq_config cfg; extern struct mosq_config cfg;