This commit is contained in:
周子博 2018-10-25 16:19:57 +08:00
parent 6675e3d496
commit db2e47470a
2 changed files with 12 additions and 12 deletions

View File

@ -281,23 +281,13 @@ process_packet(?CONNECT_PACKET(
clean_start = CleanStart, clean_start = CleanStart,
keepalive = Keepalive, keepalive = Keepalive,
properties = ConnProps, properties = ConnProps,
will_props = WillProps,
client_id = ClientId, client_id = ClientId,
username = Username, username = Username,
password = Password} = Connect), PState) -> password = Password} = Connect), PState) ->
%% TODO: Mountpoint... %% TODO: Mountpoint...
%% Msg -> emqx_mountpoint:mount(MountPoint, Msg) %% Msg -> emqx_mountpoint:mount(MountPoint, Msg)
Connect1 = if WillMsg = make_will_msg(Connect),
ProtoVer =:= ?MQTT_PROTO_V5 ->
WillDelayInterval = get_property('Will-Delay-Interval', WillProps, 0),
SessionExpiryInterval = get_property('Session-Expiry-Interval', ConnProps, 0),
WillProps1 = set_property('Will-Delay-Interval', erlang:min(SessionExpiryInterval, WillDelayInterval), WillProps),
Connect#mqtt_packet_connect{will_props = WillProps1};
true ->
Connect
end,
WillMsg = emqx_packet:will_msg(Connect1),
PState1 = set_username(Username, PState1 = set_username(Username,
PState#pstate{client_id = ClientId, PState#pstate{client_id = ClientId,
@ -687,6 +677,16 @@ get_property(_Name, undefined, Default) ->
get_property(Name, Props, Default) -> get_property(Name, Props, Default) ->
maps:get(Name, Props, Default). maps:get(Name, Props, Default).
make_will_msg(#mqtt_packet_connect{proto_ver = ProtoVer,
will_props = WillProps} = Connect) ->
emqx_packet:will_msg(if
ProtoVer =:= ?MQTT_PROTO_V5 ->
WillDelayInterval = get_property('Will-Delay-Interval', WillProps, 0),
Connect#mqtt_packet_connect{will_props = set_property('Will-Delay-Interval', WillDelayInterval, WillProps)};
true ->
Connect
end).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Check Packet %% Check Packet
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------

View File

@ -619,7 +619,7 @@ handle_info({timeout, Timer, emit_stats},
end; end;
handle_info({timeout, Timer, expired}, State = #state{expiry_timer = Timer}) -> handle_info({timeout, Timer, expired}, State = #state{expiry_timer = Timer}) ->
?LOG(info, "expired, shutdown now:(", [], State), ?LOG(info, "expired, shutdown now:(", [], State),
shutdown(expired, State#state{will_msg = undefined}); shutdown(expired, State);
handle_info({timeout, Timer, will_delay}, State = #state{will_msg = WillMsg, will_delay_timer = Timer}) -> handle_info({timeout, Timer, will_delay}, State = #state{will_msg = WillMsg, will_delay_timer = Timer}) ->
send_willmsg(WillMsg), send_willmsg(WillMsg),