From 05eef80903475d907d2717b5549e530c22e4980e Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 8 May 2026 00:32:24 +0800 Subject: [PATCH] fix --- src/host/iot_host.erl | 6 ++++-- src/transport/tcp/ssl_channel.erl | 17 +++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/host/iot_host.erl b/src/host/iot_host.erl index 1182364..d85ffcf 100644 --- a/src/host/iot_host.erl +++ b/src/host/iot_host.erl @@ -214,7 +214,8 @@ handle_event({call, From}, get_status, _, State = #state{channel_pid = ChannelPi handle_event({call, From}, {container_call, ReceiverPid, Request}, _, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) -> case HasSession andalso is_pid(ChannelPid) of true -> - Ref = ssl_channel:container_call(ChannelPid, ReceiverPid, Request), + Ref = make_ref(), + ok = ssl_channel:container_call(ChannelPid, ReceiverPid, Ref, Request), {keep_state, State, [{reply, From, {ok, Ref}}]}; false -> logger:debug("[iot_host] uuid: ~p, invalid state: ~p", [UUID, state_map(State)]), @@ -376,7 +377,8 @@ container_call(Pid, Request) when is_pid(Pid) -> start_auth_command(ChannelPid, Auth, From) when is_pid(ChannelPid), is_boolean(Auth) -> HostPid = self(), spawn(fun() -> - Ref = ssl_channel:activate(ChannelPid, Auth), + Ref = make_ref(), + ok = ssl_channel:activate(ChannelPid, self(), Ref, Auth), Result = iot_host:await_reply(HostPid, Ref, ?AUTH_COMMAND_TIMEOUT), HostPid ! {auth_command_result, From, Auth, ChannelPid, Result} end). diff --git a/src/transport/tcp/ssl_channel.erl b/src/transport/tcp/ssl_channel.erl index c0cc313..67e9eda 100644 --- a/src/transport/tcp/ssl_channel.erl +++ b/src/transport/tcp/ssl_channel.erl @@ -13,7 +13,7 @@ -define(INFLIGHT_TIMEOUT, 60000). %% API --export([pub/4, container_call/3, cancel_command_call/2, activate/2]). +-export([pub/4, container_call/4, cancel_command_call/2, activate/4]). -export([start_link/3, stop/2]). %% gen_server callbacks @@ -41,19 +41,16 @@ pub(Pid, Topic, Qos, Content) when is_pid(Pid), is_binary(Topic), is_integer(Qos), is_binary(Content) -> gen_server:cast(Pid, {pub, Topic, Qos, Content}). --spec activate(Pid :: pid(), Auth :: boolean()) -> Ref :: reference(). -activate(Pid, Auth) when is_pid(Pid), is_boolean(Auth) -> +-spec activate(Pid :: pid(), ReceiverPid :: pid(), Ref :: reference(), Auth :: boolean()) -> ok. +activate(Pid, ReceiverPid, Ref, Auth) when is_pid(Pid), is_pid(ReceiverPid), is_reference(Ref), is_boolean(Auth) -> Command = case Auth of true -> activate; false -> deactivate end, - Ref = make_ref(), - ReceiverPid = self(), gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {auth, Command}}), - Ref. + ok. --spec container_call(Pid :: pid(), ReceiverPid :: pid(), Request :: map()) -> Ref :: reference(). -container_call(Pid, ReceiverPid, Request) when is_pid(Pid), is_pid(ReceiverPid), is_map(Request) -> - Ref = make_ref(), +-spec container_call(Pid :: pid(), ReceiverPid :: pid(), Ref :: reference(), Request :: map()) -> ok. +container_call(Pid, ReceiverPid, Ref, Request) when is_pid(Pid), is_pid(ReceiverPid), is_reference(Ref), is_map(Request) -> gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {container, Request}}), - Ref. + ok. -spec cancel_command_call(Pid :: pid(), Ref :: reference()) -> ok. cancel_command_call(Pid, Ref) when is_pid(Pid), is_reference(Ref) ->