diff --git a/apps/iot/src/http_handlers/host_handler.erl b/apps/iot/src/http_handlers/host_handler.erl index 3013a1e..5c67102 100644 --- a/apps/iot/src/http_handlers/host_handler.erl +++ b/apps/iot/src/http_handlers/host_handler.erl @@ -44,12 +44,11 @@ handle_request("GET", "/host/status", #{<<"uuid">> := UUID}, _) when is_binary(U %% 删除对应的主机信息 handle_request("POST", "/host/delete", _, #{<<"uuid">> := UUID}) when is_binary(UUID) -> - case iot_host_sup:delete_host(UUID) of - ok -> - lager:debug("[host_handler] will delete host uuid: ~p", [UUID]), + case iot_host:get_pid(UUID) of + Pid when is_pid(Pid) -> + ok = iot_host_sup:delete_host(UUID), {ok, 200, iot_util:json_data(<<"success">>)}; - {error, Reason} -> - lager:debug("[host_handler] delete host uuid: ~p, get error is: ~p", [UUID, Reason]), + undefined -> {ok, 200, iot_util:json_error(404, <<"error">>)} end; diff --git a/apps/iot/src/iot_host_sup.erl b/apps/iot/src/iot_host_sup.erl index 16f8b4e..9b12b06 100644 --- a/apps/iot/src/iot_host_sup.erl +++ b/apps/iot/src/iot_host_sup.erl @@ -37,13 +37,7 @@ ensured_host_started(UUID) when is_binary(UUID) -> delete_host(UUID) -> Id = iot_host:get_name(UUID), - case supervisor:terminate_child(?MODULE, Id) of - {error, running} -> - iot_host:kill(UUID), - ok; - _ -> - ok - end, + ok = supervisor:terminate_child(?MODULE, Id), case supervisor:delete_child(?MODULE, Id) of {error, running} -> %% ensure killed then delete again diff --git a/apps/iot/src/message/message_codec.erl b/apps/iot/src/message/message_codec.erl index c4c6cc9..769c11e 100644 --- a/apps/iot/src/message/message_codec.erl +++ b/apps/iot/src/message/message_codec.erl @@ -113,7 +113,7 @@ decode0(_, _) -> %%% helper methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec marshal(Type :: integer(), Field :: any()) -> binary(). +-spec marshal(Type :: ?I8 | ?I16 | ?I32 | ?Bytes, Field :: integer() | binary()) -> binary(). marshal(?I8, Field) when is_integer(Field) -> <>; marshal(?I16, Field) when is_integer(Field) ->