Skip to content

Commit d407fe1

Browse files
committed
Fixed a bug in stop
1 parent 9cbba74 commit d407fe1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ports/atomvm_mqtt_client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,15 @@ static NativeHandlerResult consume_mailbox(Context *ctx)
616616
uint64_t ref_ticks = term_to_ref_ticks(ref);
617617
term req = term_get_tuple_element(msg, 2);
618618

619+
NativeHandlerResult result = NativeContinue;
619620
if (term_is_atom(req)) {
620621

621622
int cmd = interop_atom_term_select_int(cmd_table, req, ctx->global);
622623
switch (cmd) {
623624

624625
case MQTTStopCmd:
625626
do_stop(ctx, pid, ref_ticks);
627+
result = NativeTerminate;
626628
break;
627629

628630
case MQTTDisconnectCmd:
@@ -674,7 +676,7 @@ static NativeHandlerResult consume_mailbox(Context *ctx)
674676

675677
mailbox_remove_message(&ctx->mailbox, &ctx->heap);
676678

677-
return NativeContinue;
679+
return result;
678680
}
679681

680682
//

src/mqtt_client.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,12 @@ do_unsubscribe(Port, Topic) ->
768768

769769
%% @private
770770
do_stop(Port) ->
771-
port:do_disconnect(Port),
771+
case port:do_disconnect(Port) of
772+
ok ->
773+
ok;
774+
Error ->
775+
io:format("Warning: Unable to disconnect from MQTT broker due to error ~p~n", [Error])
776+
end,
772777
Port ! stop.
773778

774779
%% @private

0 commit comments

Comments
 (0)