Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: convert session_present flag to boolean to follow the declared type #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/emqtt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ reconnect(_EventType, _, _State) ->
waiting_for_connack(cast, #mqtt_packet{} = P, State) ->
waiting_for_connack(cast, {P, default_via(State)}, State);
waiting_for_connack(cast, {?CONNACK_PACKET(?RC_SUCCESS,
SessPresent,
SessPresentFlag,
Properties), Via},
State = #state{properties = AllProps,
clientid = ClientId,
Expand All @@ -1052,7 +1052,7 @@ waiting_for_connack(cast, {?CONNACK_PACKET(?RC_SUCCESS,
Reply = {ok, Properties},
State1 = State#state{clientid = assign_id(ClientId, AllProps1),
properties = AllProps1,
session_present = SessPresent},
session_present = flag_to_bool(SessPresentFlag)},
State2 = qoe_inject(connected, State1),
State3 = ensure_retry_timer(ensure_keepalive_timer(State2)),
Retry = [{next_event, info, immediate_retry} || not emqtt_inflight:is_empty(Inflight)],
Expand All @@ -1066,7 +1066,7 @@ waiting_for_connack(cast, {?CONNACK_PACKET(?RC_SUCCESS,
end;

waiting_for_connack(cast, {?CONNACK_PACKET(ReasonCode,
_SessPresent,
_SessPresentFlag,
Properties), Via},
State = #state{proto_ver = ProtoVer, socket = Via, reconnect = Re}) ->
Reason = reason_code_name(ReasonCode, ProtoVer),
Expand Down Expand Up @@ -2255,3 +2255,6 @@ redact_packet(#mqtt_packet{variable = #mqtt_packet_connect{} = Conn} = Packet) -
Packet#mqtt_packet{variable = Conn#mqtt_packet_connect{password = <<"******">>}};
redact_packet(Packet) ->
Packet.

flag_to_bool(0) -> false;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, can be fixed in https://github.com/emqx/emqtt/blob/fix-session_present-type/src/emqtt_frame.erl#L218
similarly to how CONNECT packet flags are parsed to bools: https://github.com/emqx/emqtt/blob/fix-session_present-type/src/emqtt_frame.erl#L202

But it would require changing the record field, e.g:

#mqtt_packet_connack{session_present  = SessionPresent,

Instead of:

#mqtt_packet_connack{ack_flags   = AckFlags,

flag_to_bool(1) -> true.
Loading