Make DISCONNECT packet with reason code 0x00 when this packet doesn't have payload

This commit is contained in:
周子博 2018-09-06 17:17:09 +08:00
parent 42b3c9b4d6
commit 917eb8e29f
2 changed files with 5 additions and 6 deletions

View File

@ -76,6 +76,9 @@ parse_remaining_len(_Bin, _Header, _Multiplier, Length,
error(mqtt_frame_too_large);
parse_remaining_len(<<>>, Header, Multiplier, Length, Options) ->
{more, fun(Bin) -> parse_remaining_len(Bin, Header, Multiplier, Length, Options) end};
%% Match DISCONNECT without payload
parse_remaining_len(<<0:8, Rest/binary>>, Header = #mqtt_packet_header{type = ?DISCONNECT}, 1, 0, _Options) ->
wrap(Header, #mqtt_packet_disconnect{reason_code = ?RC_SUCCESS}, Rest);
%% Match PINGREQ.
parse_remaining_len(<<0:8, Rest/binary>>, Header, 1, 0, Options) ->
parse_frame(Rest, Header, 0, Options);

View File

@ -399,15 +399,11 @@ process_packet(?UNSUBSCRIBE_PACKET(PacketId, Properties, RawTopicFilters),
process_packet(?PACKET(?PINGREQ), PState) ->
send(?PACKET(?PINGRESP), PState);
process_packet(?DISCONNECT_PACKET(16#00), PState) ->
process_packet(?DISCONNECT_PACKET(?RC_SUCCESS), PState) ->
%% Clean willmsg
{stop, normal, PState#pstate{will_msg = undefined}};
process_packet(?DISCONNECT_PACKET(_), PState) ->
{stop, normal, PState};
process_packet(Packet = ?PACKET(?DISCONNECT), PState) ->
if Packet#mqtt_packet.variable =:= undefined ->
{stop, normal, PState#pstate{will_msg = undefined}}
end.
{stop, normal, PState}.
%%------------------------------------------------------------------------------
%% ConnAck --> Client