Przeglądaj źródła

Merge pull request #584 from emqtt/emq10

Fix issue#575 - Compatible with the Qos0 PUBREL packet
Feng Lee 9 lat temu
rodzic
commit
3166ebba92
1 zmienionych plików z 9 dodań i 3 usunięć
  1. 9 3
      src/emqttd_parser.erl

+ 9 - 3
src/emqttd_parser.erl

@@ -44,10 +44,10 @@ limit(Opts) ->
             -> {ok, mqtt_packet()} | {error, any()} | {more, fun()}).
 parse(<<>>, {none, Limit}) ->
     {more, fun(Bin) -> parse(Bin, {none, Limit}) end};
-parse(<<PacketType:4, Dup:1, QoS:2, Retain:1, Rest/binary>>, {none, Limit}) ->
-    parse_remaining_len(Rest, #mqtt_packet_header{type   = PacketType,
+parse(<<Type:4, Dup:1, QoS:2, Retain:1, Rest/binary>>, {none, Limit}) ->
+    parse_remaining_len(Rest, #mqtt_packet_header{type   = Type,
                                                   dup    = bool(Dup),
-                                                  qos    = QoS,
+                                                  qos    = fixqos(Type, QoS),
                                                   retain = bool(Retain)}, Limit);
 parse(Bin, Cont) -> Cont(Bin).
 
@@ -218,3 +218,9 @@ bool(1) -> true.
 protocol_name_approved(Ver, Name) ->
     lists:member({Ver, Name}, ?PROTOCOL_NAMES).
 
+%% Fix Issue#575
+fixqos(?PUBREL, 0)      -> 1;
+fixqos(?SUBSCRIBE, 0)   -> 1;
+fixqos(?UNSUBSCRIBE, 0) -> 1;
+fixqos(_Type, QoS)      -> QoS.
+