Handle DISCONNECT with will.

pull/1203/head
Roger A. Light 7 years ago
parent 3b6b6d5fa8
commit b2c0c3d573

@ -109,6 +109,7 @@ enum mosquitto_client_state {
mosq_cs_expiring = 15,
mosq_cs_connecting = 16,
mosq_cs_duplicate = 17, /* client that has been taken over by another with the same id */
mosq_cs_disconnect_with_will = 18,
};
enum mosquitto__protocol {

@ -796,7 +796,7 @@ handle_connect_error:
int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
{
int rc;
uint8_t reason_code;
uint8_t reason_code = 0;
mosquitto_property *properties = NULL;
if(!context){
@ -833,7 +833,11 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
return MOSQ_ERR_PROTOCOL;
}
}
context->state = mosq_cs_disconnecting;
if(reason_code == MQTT_RC_DISCONNECT_WITH_WILL_MSG){
context->state = mosq_cs_disconnect_with_will;
}else{
context->state = mosq_cs_disconnecting;
}
do_disconnect(db, context);
return MOSQ_ERR_SUCCESS;
}

@ -12,6 +12,7 @@ test :
ptest :
$(MAKE) -C broker ptest
$(MAKE) -C lib ptest
$(MAKE) -C unit test
clean :
$(MAKE) -C lib clean

@ -0,0 +1,48 @@
#!/usr/bin/env python
# Test whether a client will is transmitted when a client disconnects with DISCONNECT with will.
# MQTT 5
from mosq_test_helper import *
def do_test():
rc = 1
keepalive = 60
mid = 1
connect1_packet = mosq_test.gen_connect("will-qos0-test", keepalive=keepalive, proto_ver=5)
connack1_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
connect2_packet = mosq_test.gen_connect("will-helper", keepalive=keepalive, proto_ver=5, will_topic="will/test", will_payload="will delay", will_qos=2)
connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
disconnect_packet = mosq_test.gen_disconnect(reason_code=4, proto_ver=5)
subscribe_packet = mosq_test.gen_subscribe(mid, "will/test", 0, proto_ver=5)
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=5)
publish_packet = mosq_test.gen_publish("will/test", qos=0, payload="will delay", proto_ver=5)
port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock1 = mosq_test.do_client_connect(connect1_packet, connack1_packet, timeout=30, port=port)
mosq_test.do_send_receive(sock1, subscribe_packet, suback_packet, "suback")
sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, timeout=30, port=port)
sock2.send(disconnect_packet)
if mosq_test.expect_packet(sock1, "publish", publish_packet):
rc = 0
sock2.close()
sock1.close()
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde)
exit(rc)
do_test()

@ -131,6 +131,7 @@ endif
./07-will-delay.py
./07-will-delay-recover.py
./07-will-delay-reconnect.py
./07-will-disconnect-with-will.py
08 :
ifeq ($(WITH_TLS),yes)

@ -107,6 +107,7 @@ tests = [
(1, './07-will-delay.py'),
(1, './07-will-delay-recover.py'),
(1, './07-will-delay-reconnect.py'),
(1, './07-will-disconnect-with-will.py'),
(2, './08-ssl-connect-no-auth.py'),
(2, './08-ssl-connect-no-auth-wrong-ca.py'),

Loading…
Cancel
Save