Publish will msg when abnormal terminate

This commit is contained in:
Feng Lee 2019-08-09 15:28:47 +08:00
parent 03744ead30
commit 3032731a2d
1 changed files with 9 additions and 5 deletions

View File

@ -265,8 +265,6 @@ handle_in(?DISCONNECT_PACKET(?RC_SUCCESS), PState) ->
{stop, normal, PState#protocol{will_msg = undefined}};
handle_in(?DISCONNECT_PACKET(RC), PState = #protocol{proto_ver = Ver}) ->
%% TODO:
%% {stop, {shutdown, abnormal_disconnet}, PState};
{stop, {shutdown, emqx_reason_codes:name(RC, Ver)}, PState};
handle_in(?AUTH_PACKET(), PState) ->
@ -439,9 +437,15 @@ handle_timeout(TRef, Msg, PState = #protocol{session = Session}) ->
handle_out({publish, Publishes}, PState#protocol{session = NSession})
end.
terminate(Reason, _PState) ->
io:format("Terminated for ~p~n", [Reason]),
ok.
terminate(normal, _PState) ->
ok;
terminate(_Reason, #protocol{will_msg = WillMsg}) ->
publish_will_msg(WillMsg).
publish_will_msg(undefined) ->
ok;
publish_will_msg(Msg) ->
emqx_broker:publish(Msg).
%%--------------------------------------------------------------------
%% Validate incoming packet