Преглед изворни кода

Fix connack reason code when crash

terry-xiaoyu пре 6 година
родитељ
комит
b29ceb9f6b
2 измењених фајлова са 6 додато и 1 уклоњено
  1. 1 1
      src/emqx_channel.erl
  2. 5 0
      src/emqx_reason_codes.erl

+ 1 - 1
src/emqx_channel.erl

@@ -239,7 +239,7 @@ handle_in(?CONNECT_PACKET(ConnPkt), Channel) ->
         {ok, NConnPkt, NChannel} ->
             process_connect(NConnPkt, NChannel);
         {error, ReasonCode, NChannel} ->
-            handle_out({connack, ReasonCode, ConnPkt}, NChannel)
+            handle_out({connack, emqx_reason_codes:formalized(connack, ReasonCode), ConnPkt}, NChannel)
     end;
 
 handle_in(Packet = ?PUBLISH_PACKET(_QoS), Channel) ->

+ 5 - 0
src/emqx_reason_codes.erl

@@ -25,6 +25,7 @@
         , text/2
         , connack_error/1
         , mqtt_frame_error/1
+        , formalized/2
         ]).
 
 -export([compat/2]).
@@ -178,3 +179,7 @@ connack_error(_) -> ?RC_NOT_AUTHORIZED.
 
 mqtt_frame_error(mqtt_frame_too_large) -> ?RC_PACKET_TOO_LARGE;
 mqtt_frame_error(_) -> ?RC_MALFORMED_PACKET.
+
+formalized(connack, Code) when is_integer(Code) -> Code;
+formalized(connack, Code) when is_integer(Code) ->
+    ?RC_SERVER_UNAVAILABLE.