Add reason code to mosquitto_disconnect_with_properties()

pull/1072/head
Roger Light 7 years ago
parent 14c2f528cf
commit 3cb8a52ef3

@ -86,7 +86,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
break; break;
} }
} }
mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props);
} }
}else{ }else{
if(result && !cfg.quiet){ if(result && !cfg.quiet){

@ -30,6 +30,7 @@ Contributors:
#endif #endif
#include <mosquitto.h> #include <mosquitto.h>
#include <mqtt_protocol.h>
#include "client_shared.h" #include "client_shared.h"
#include "pub_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; last_mid_sent = mid;
if(cfg.pub_mode == MSGMODE_STDIN_LINE){ if(cfg.pub_mode == MSGMODE_STDIN_LINE){
if(mid == last_mid){ if(mid == last_mid){
mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props);
disconnect_sent = true; disconnect_sent = true;
} }
}else if(disconnect_sent == false){ }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; 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); rc2 = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, buf, cfg.qos, cfg.retain);
if(rc2){ if(rc2){
if(!cfg.quiet) fprintf(stderr, "Error: Publish returned %d, disconnecting.\n", 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; break;
}else{ }else{
@ -201,7 +202,7 @@ int pub_shared_loop(struct mosquitto *mosq)
if(feof(stdin)){ if(feof(stdin)){
if(last_mid == -1){ if(last_mid == -1){
/* Empty file */ /* Empty file */
mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props);
disconnect_sent = true; disconnect_sent = true;
status = STATUS_DISCONNECTING; status = STATUS_DISCONNECTING;
}else{ }else{
@ -211,7 +212,7 @@ int pub_shared_loop(struct mosquitto *mosq)
} }
}else if(status == STATUS_WAITING){ }else if(status == STATUS_WAITING){
if(last_mid_sent == last_mid && disconnect_sent == false){ 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; disconnect_sent = true;
} }
#ifdef WIN32 #ifdef WIN32

@ -32,6 +32,7 @@ Contributors:
#endif #endif
#include <mosquitto.h> #include <mosquitto.h>
#include <mqtt_protocol.h>
#include "client_shared.h" #include "client_shared.h"
static struct mosq_config cfg; static struct mosq_config cfg;
@ -44,7 +45,7 @@ void my_signal_handler(int signum)
{ {
if(signum == SIGALRM){ if(signum == SIGALRM){
process_messages = false; 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 #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){ if(cfg.retained_only && !message->retain && process_messages){
process_messages = false; process_messages = false;
mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props);
return; return;
} }
@ -79,7 +80,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
msg_count++; msg_count++;
if(cfg.msg_count == msg_count){ if(cfg.msg_count == msg_count){
process_messages = false; 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){ if(result && !cfg.quiet){
fprintf(stderr, "%s\n", mosquitto_connack_string(result)); 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.quiet) printf("\n");
if(cfg.exit_after_sub){ if(cfg.exit_after_sub){
mosquitto_disconnect_with_properties(mosq, cfg.disconnect_props); mosquitto_disconnect_with_properties(mosq, 0, cfg.disconnect_props);
} }
} }

@ -212,10 +212,10 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking, const mos
int mosquitto_disconnect(struct mosquitto *mosq) 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; int rc;
if(!mosq) return MOSQ_ERR_INVAL; if(!mosq) return MOSQ_ERR_INVAL;

@ -685,6 +685,7 @@ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
* *
* Parameters: * Parameters:
* mosq - a valid mosquitto instance. * mosq - a valid mosquitto instance.
* reason_code - the disconnect reason code.
* properties - a valid mosquitto_property list, or NULL. * properties - a valid mosquitto_property list, or NULL.
* *
* Returns: * 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_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT. * 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);
/* ====================================================================== /* ======================================================================

Loading…
Cancel
Save