fix(mqtt_sn): reformat some code
This commit is contained in:
parent
6a07c8ef6d
commit
a925395814
|
@ -269,10 +269,10 @@ message_type(Type) ->
|
||||||
io_lib:format("Unknown Type ~p", [Type]).
|
io_lib:format("Unknown Type ~p", [Type]).
|
||||||
|
|
||||||
format(?SN_PUBLISH_MSG(Flags, TopicId, MsgId, Data)) ->
|
format(?SN_PUBLISH_MSG(Flags, TopicId, MsgId, Data)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBLISH, ~p, TopicId=~w, MsgId=~w, Payload=~w",
|
io_lib:format("mqtt_sn_message SN_PUBLISH, ~s, TopicId=~w, MsgId=~w, Payload=~w",
|
||||||
[format_flag(Flags), TopicId, MsgId, Data]);
|
[format_flag(Flags), TopicId, MsgId, Data]);
|
||||||
format(?SN_PUBACK_MSG(Flags, MsgId, ReturnCode)) ->
|
format(?SN_PUBACK_MSG(Flags, MsgId, ReturnCode)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBACK, ~p, MsgId=~w, ReturnCode=~w",
|
io_lib:format("mqtt_sn_message SN_PUBACK, ~s, MsgId=~w, ReturnCode=~w",
|
||||||
[format_flag(Flags), MsgId, ReturnCode]);
|
[format_flag(Flags), MsgId, ReturnCode]);
|
||||||
format(?SN_PUBREC_MSG(?SN_PUBCOMP, MsgId)) ->
|
format(?SN_PUBREC_MSG(?SN_PUBCOMP, MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBCOMP, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_PUBCOMP, MsgId=~w", [MsgId]);
|
||||||
|
@ -281,13 +281,13 @@ format(?SN_PUBREC_MSG(?SN_PUBREC, MsgId)) ->
|
||||||
format(?SN_PUBREC_MSG(?SN_PUBREL, MsgId)) ->
|
format(?SN_PUBREC_MSG(?SN_PUBREL, MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_PUBREL, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_PUBREL, MsgId=~w", [MsgId]);
|
||||||
format(?SN_SUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
format(?SN_SUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_SUBSCRIBE, ~p, MsgId=~w, TopicId=~w",
|
io_lib:format("mqtt_sn_message SN_SUBSCRIBE, ~s, MsgId=~w, TopicId=~w",
|
||||||
[format_flag(Flags), Msgid, Topic]);
|
[format_flag(Flags), Msgid, Topic]);
|
||||||
format(?SN_SUBACK_MSG(Flags, TopicId, MsgId, ReturnCode)) ->
|
format(?SN_SUBACK_MSG(Flags, TopicId, MsgId, ReturnCode)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_SUBACK, ~p, MsgId=~w, TopicId=~w, ReturnCode=~w",
|
io_lib:format("mqtt_sn_message SN_SUBACK, ~s, MsgId=~w, TopicId=~w, ReturnCode=~w",
|
||||||
[format_flag(Flags), MsgId, TopicId, ReturnCode]);
|
[format_flag(Flags), MsgId, TopicId, ReturnCode]);
|
||||||
format(?SN_UNSUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
format(?SN_UNSUBSCRIBE_MSG(Flags, Msgid, Topic)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_UNSUBSCRIBE, ~p, MsgId=~w, TopicId=~w",
|
io_lib:format("mqtt_sn_message SN_UNSUBSCRIBE, ~s, MsgId=~w, TopicId=~w",
|
||||||
[format_flag(Flags), Msgid, Topic]);
|
[format_flag(Flags), Msgid, Topic]);
|
||||||
format(?SN_UNSUBACK_MSG(MsgId)) ->
|
format(?SN_UNSUBACK_MSG(MsgId)) ->
|
||||||
io_lib:format("mqtt_sn_message SN_UNSUBACK, MsgId=~w", [MsgId]);
|
io_lib:format("mqtt_sn_message SN_UNSUBACK, MsgId=~w", [MsgId]);
|
||||||
|
|
|
@ -219,7 +219,7 @@ idle(cast, {connack, ConnAck}, State) ->
|
||||||
{next_state, connected, State};
|
{next_state, connected, State};
|
||||||
|
|
||||||
idle(timeout, _Timeout, State) ->
|
idle(timeout, _Timeout, State) ->
|
||||||
stop({shutdown, idle_timeout}, State);
|
stop(idle_timeout, State);
|
||||||
|
|
||||||
idle(EventType, EventContent, State) ->
|
idle(EventType, EventContent, State) ->
|
||||||
handle_event(EventType, EventContent, idle, State).
|
handle_event(EventType, EventContent, idle, State).
|
||||||
|
@ -374,10 +374,10 @@ connected(cast, {connack, ConnAck}, State) ->
|
||||||
|
|
||||||
connected(cast, {shutdown, Reason, Packet}, State) ->
|
connected(cast, {shutdown, Reason, Packet}, State) ->
|
||||||
ok = handle_outgoing(Packet, State),
|
ok = handle_outgoing(Packet, State),
|
||||||
{stop, {shutdown, Reason}, State};
|
stop(Reason, State);
|
||||||
|
|
||||||
connected(cast, {shutdown, Reason}, State) ->
|
connected(cast, {shutdown, Reason}, State) ->
|
||||||
{stop, {shutdown, Reason}, State};
|
stop(Reason, State);
|
||||||
|
|
||||||
connected(cast, {close, Reason}, State) ->
|
connected(cast, {close, Reason}, State) ->
|
||||||
?LOG(debug, "Force to close the socket due to ~p", [Reason], State),
|
?LOG(debug, "Force to close the socket due to ~p", [Reason], State),
|
||||||
|
@ -614,11 +614,11 @@ handle_return({ok, NChannel}, State, AddEvents) ->
|
||||||
handle_return({ok, Replies, NChannel}, State, AddEvents) ->
|
handle_return({ok, Replies, NChannel}, State, AddEvents) ->
|
||||||
{keep_state, State#state{channel = NChannel}, outgoing_events(append(Replies, AddEvents))};
|
{keep_state, State#state{channel = NChannel}, outgoing_events(append(Replies, AddEvents))};
|
||||||
handle_return({shutdown, Reason, NChannel}, State, _AddEvents) ->
|
handle_return({shutdown, Reason, NChannel}, State, _AddEvents) ->
|
||||||
stop({shutdown, Reason}, State#state{channel = NChannel});
|
stop(Reason, State#state{channel = NChannel});
|
||||||
handle_return({shutdown, Reason, OutPacket, NChannel}, State, _AddEvents) ->
|
handle_return({shutdown, Reason, OutPacket, NChannel}, State, _AddEvents) ->
|
||||||
NState = State#state{channel = NChannel},
|
NState = State#state{channel = NChannel},
|
||||||
ok = handle_outgoing(OutPacket, NState),
|
ok = handle_outgoing(OutPacket, NState),
|
||||||
stop({shutdown, Reason}, NState).
|
stop(Reason, NState).
|
||||||
|
|
||||||
outgoing_events(Actions) ->
|
outgoing_events(Actions) ->
|
||||||
lists:map(fun outgoing_event/1, Actions).
|
lists:map(fun outgoing_event/1, Actions).
|
||||||
|
@ -772,22 +772,26 @@ goto_asleep_state(Duration, State=#state{asleep_timer = AsleepTimer}) ->
|
||||||
-compile({inline, [shutdown/2, shutdown/3]}).
|
-compile({inline, [shutdown/2, shutdown/3]}).
|
||||||
shutdown(Reason, State) ->
|
shutdown(Reason, State) ->
|
||||||
?LOG(error, "shutdown due to ~p", [Reason], State),
|
?LOG(error, "shutdown due to ~p", [Reason], State),
|
||||||
stop({shutdown, Reason}, State).
|
stop(Reason, State).
|
||||||
|
|
||||||
shutdown(Reason, Reply, State) ->
|
shutdown(Reason, Reply, State) ->
|
||||||
?LOG(error, "shutdown due to ~p", [Reason], State),
|
?LOG(error, "shutdown due to ~p", [Reason], State),
|
||||||
stop({shutdown, Reason}, Reply, State).
|
stop(Reason, Reply, State).
|
||||||
|
|
||||||
-compile({inline, [stop/2, stop/3]}).
|
-compile({inline, [stop/2, stop/3]}).
|
||||||
|
stop({shutdown, Reason}, State) ->
|
||||||
|
stop(Reason, State);
|
||||||
stop(Reason, State) ->
|
stop(Reason, State) ->
|
||||||
case Reason of
|
case Reason of
|
||||||
%% FIXME: The Will-Msg should publish when a Session terminated!
|
%% FIXME: The Will-Msg should publish when a Session terminated!
|
||||||
asleep_timeout -> do_publish_will(State);
|
asleep_timeout -> do_publish_will(State);
|
||||||
{shutdown, keepalive_timeout} -> do_publish_will(State);
|
keepalive_timeout -> do_publish_will(State);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
{stop, Reason, State}.
|
{stop, {shutdown, Reason}, State}.
|
||||||
|
|
||||||
|
stop({shutdown, Reason}, Reply, State) ->
|
||||||
|
stop(Reason, Reply, State);
|
||||||
stop(Reason, Reply, State) ->
|
stop(Reason, Reply, State) ->
|
||||||
{stop, Reason, Reply, State}.
|
{stop, Reason, Reply, State}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue