diff --git a/client/pub_client.c b/client/pub_client.c index 722308b6..7211b4f0 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -86,7 +86,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result) break; } } - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); } }else{ if(result && !cfg.quiet){ diff --git a/client/pub_shared.c b/client/pub_shared.c index 08f941bb..83a1ffee 100644 --- a/client/pub_shared.c +++ b/client/pub_shared.c @@ -30,6 +30,7 @@ Contributors: #endif #include +#include #include "client_shared.h" #include "pub_shared.h" @@ -56,11 +57,11 @@ void my_publish_callback(struct mosquitto *mosq, void *obj, int mid) last_mid_sent = mid; if(cfg.pub_mode == MSGMODE_STDIN_LINE){ if(mid == last_mid){ - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); disconnect_sent = true; } }else if(disconnect_sent == false){ - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); disconnect_sent = true; } } @@ -183,7 +184,7 @@ int pub_shared_loop(struct mosquitto *mosq) rc2 = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, buf, cfg.qos, cfg.retain); if(rc2){ if(!cfg.quiet) fprintf(stderr, "Error: Publish returned %d, disconnecting.\n", rc2); - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); } break; }else{ @@ -201,7 +202,7 @@ int pub_shared_loop(struct mosquitto *mosq) if(feof(stdin)){ if(last_mid == -1){ /* Empty file */ - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); disconnect_sent = true; status = STATUS_DISCONNECTING; }else{ @@ -211,7 +212,7 @@ int pub_shared_loop(struct mosquitto *mosq) } }else if(status == STATUS_WAITING){ if(last_mid_sent == last_mid && disconnect_sent == false){ - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); disconnect_sent = true; } #ifdef WIN32 diff --git a/client/sub_client.c b/client/sub_client.c index 8a9cf3a9..473c58c3 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -32,6 +32,7 @@ Contributors: #endif #include +#include #include "client_shared.h" static struct mosq_config cfg; @@ -44,7 +45,7 @@ void my_signal_handler(int signum) { if(signum == SIGALRM){ process_messages = false; - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); } } #endif @@ -61,7 +62,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit if(cfg.retained_only && !message->retain && process_messages){ process_messages = false; - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); return; } @@ -79,7 +80,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit msg_count++; if(cfg.msg_count == msg_count){ process_messages = false; - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); } } } @@ -98,7 +99,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag if(result && !cfg.quiet){ fprintf(stderr, "%s\n", mosquitto_connack_string(result)); } - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); } } @@ -113,7 +114,7 @@ void my_subscribe_callback(struct mosquitto *mosq, void *obj, int mid, int qos_c if(!cfg.quiet) printf("\n"); if(cfg.exit_after_sub){ - mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); + mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props); } } diff --git a/lib/connect.c b/lib/connect.c index 69e98216..016bc73d 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -212,10 +212,10 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking, const mos int mosquitto_disconnect(struct mosquitto *mosq) { - return mosquitto_disconnect_with_properties(mosq, NULL); + return mosquitto_disconnect_with_properties(mosq, 0, NULL); } -int mosquitto_disconnect_with_properties(struct mosquitto *mosq, const mosquitto_property *properties) +int mosquitto_disconnect_with_properties(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties) { int rc; if(!mosq) return MOSQ_ERR_INVAL; diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 13af7e7a..7ffbc16c 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -685,6 +685,7 @@ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); * * Parameters: * mosq - a valid mosquitto instance. + * reason_code - the disconnect reason code. * properties - a valid mosquitto_property list, or NULL. * * Returns: @@ -694,7 +695,7 @@ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq); * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden. * MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT. */ -libmosq_EXPORT int mosquitto_disconnect_with_properties(struct mosquitto *mosq, const mosquitto_property *properties); +libmosq_EXPORT int mosquitto_disconnect_with_properties(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties); /* ======================================================================