From 94d20f88f408506a69d5038da5afa28f9f1162ff Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 27 Apr 2026 11:26:01 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=B6=88=E6=81=AF=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/host/iot_host.erl | 4 +++- src/transport/http/container_handler.erl | 14 ++++++++++++++ src/transport/tcp/ssl_channel.erl | 8 +++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/host/iot_host.erl b/src/host/iot_host.erl index b55a63a..49aab46 100644 --- a/src/host/iot_host.erl +++ b/src/host/iot_host.erl @@ -125,9 +125,11 @@ remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) container_call(Pid, docker_container_builder:remove_request(ContainerName)). -spec await_reply(Pid :: pid(), Ref :: reference(), Timeout :: integer()) -> - {ok, Result :: term()} | {error, Reason :: term()}. + ok | {ok, Result :: term()} | {error, Reason :: term()}. await_reply(Pid, Ref, Timeout) when is_pid(Pid), is_reference(Ref), is_integer(Timeout) -> receive + {request_reply, Ref, ok} -> + ok; {request_reply, Ref, {ok, Result}} -> {ok, Result}; {request_reply, Ref, {error, Reason}} -> diff --git a/src/transport/http/container_handler.erl b/src/transport/http/container_handler.erl index 8d7e319..8f697e6 100644 --- a/src/transport/http/container_handler.erl +++ b/src/transport/http/container_handler.erl @@ -24,6 +24,8 @@ handle_request("GET", "/container/get_all", #{<<"uuid">> := UUID}, _) when is_bi case iot_host:get_containers(Pid) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -49,6 +51,8 @@ handle_request("POST", "/container/push_config", _, case iot_host:config_container(Pid, ContainerName, Config) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, Timeout) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -69,6 +73,8 @@ handle_request("POST", "/container/deploy", _, #{<<"uuid">> := UUID, <<"task_id" case iot_host:deploy_container(Pid, TaskId, Config) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -88,6 +94,8 @@ handle_request("POST", "/container/start", _, #{<<"uuid">> := UUID, <<"container case iot_host:start_container(Pid, ContainerName) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -107,6 +115,8 @@ handle_request("POST", "/container/stop", _, #{<<"uuid">> := UUID, <<"container_ case iot_host:stop_container(Pid, ContainerName) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -125,6 +135,8 @@ handle_request("POST", "/container/kill", _, #{<<"uuid">> := UUID, <<"container_ case iot_host:kill_container(Pid, ContainerName) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> @@ -144,6 +156,8 @@ handle_request("POST", "/container/remove", _, #{<<"uuid">> := UUID, <<"containe case iot_host:remove_container(Pid, ContainerName) of {ok, Ref} -> case iot_host:await_reply(Pid, Ref, ?REQ_TIMEOUT) of + ok -> + {ok, 200, request_success_response(<<"ok">>)}; {ok, Result} -> {ok, 200, request_success_response(Result)}; {error, Reason} -> diff --git a/src/transport/tcp/ssl_channel.erl b/src/transport/tcp/ssl_channel.erl index 913fdfa..87239e3 100644 --- a/src/transport/tcp/ssl_channel.erl +++ b/src/transport/tcp/ssl_channel.erl @@ -196,7 +196,7 @@ handle_request_frame(Ref, case iot_host:attach_channel(HostPid, self()) of ok -> erlang:monitor(process, HostPid), - send_reply_frame(Transport, Socket, Ref, {auth_response, {ok, <<"ok">>}}), + send_reply_frame(Transport, Socket, Ref, {auth_response, ok}), {noreply, State#state{uuid = UUID, host_pid = HostPid}}; {denied, Reason} when is_binary(Reason) -> erlang:monitor(process, HostPid), @@ -265,8 +265,10 @@ send_reply_frame(Transport, Socket, Ref, Reply) -> Packet = term_to_binary({response, Ref, Reply}), Transport:send(Socket, Packet). --spec decode_reply({container_response, {ok, term()} | {error, term()}} | tuple()) -> - {ok, term()} | {error, term()}. +-spec decode_reply({container_response, ok | {ok, term()} | {error, term()}} | tuple()) -> + ok | {ok, term()} | {error, term()}. +decode_reply({container_response, ok}) -> + ok; decode_reply({container_response, {ok, Result}}) -> {ok, Result}; decode_reply({container_response, {error, Reason}}) ->