fix(mqttsn): ack the DISCONNECT packet even if it is not connected
MQTT-SN v1.2 spec: "As with MQTT, the DISCONNECT message is sent by a client to indicate that it wants to close the connection. The gateway will acknowledge the receipt of that message by returning a DISCONNECT to the client."
This commit is contained in:
parent
a49750049f
commit
8339bccc69
|
@ -443,6 +443,12 @@ handle_in(
|
||||||
handle_in(?SN_ADVERTISE_MSG(_GwId, _Radius), Channel) ->
|
handle_in(?SN_ADVERTISE_MSG(_GwId, _Radius), Channel) ->
|
||||||
% ignore
|
% ignore
|
||||||
shutdown(normal, Channel);
|
shutdown(normal, Channel);
|
||||||
|
%% Ack DISCONNECT even if it is not connected
|
||||||
|
handle_in(
|
||||||
|
?SN_DISCONNECT_MSG(_Duration),
|
||||||
|
Channel = #channel{conn_state = idle}
|
||||||
|
) ->
|
||||||
|
handle_out(disconnect, normal, Channel);
|
||||||
handle_in(
|
handle_in(
|
||||||
Publish =
|
Publish =
|
||||||
?SN_PUBLISH_MSG(
|
?SN_PUBLISH_MSG(
|
||||||
|
|
|
@ -176,6 +176,18 @@ t_connect(_) ->
|
||||||
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
|
?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),
|
||||||
|
|
||||||
send_disconnect_msg(Socket, undefined),
|
send_disconnect_msg(Socket, undefined),
|
||||||
|
%% assert: mqttsn gateway will ack disconnect msg with DISCONNECT packet
|
||||||
|
?assertEqual(<<2, ?SN_DISCONNECT>>, receive_response(Socket)),
|
||||||
|
gen_udp:close(Socket).
|
||||||
|
|
||||||
|
t_first_disconnect(_) ->
|
||||||
|
SockName = {'mqttsn:udp:default', 1884},
|
||||||
|
?assertEqual(true, lists:keymember(SockName, 1, esockd:listeners())),
|
||||||
|
|
||||||
|
{ok, Socket} = gen_udp:open(0, [binary]),
|
||||||
|
send_disconnect_msg(Socket, undefined),
|
||||||
|
|
||||||
|
%% assert: mqttsn gateway will ack disconnect msg with DISCONNECT packet
|
||||||
?assertEqual(<<2, ?SN_DISCONNECT>>, receive_response(Socket)),
|
?assertEqual(<<2, ?SN_DISCONNECT>>, receive_response(Socket)),
|
||||||
gen_udp:close(Socket).
|
gen_udp:close(Socket).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue