This commit is contained in:
anlicheng 2026-05-08 00:32:24 +08:00
parent b607b90416
commit 05eef80903
2 changed files with 11 additions and 12 deletions

View File

@ -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).

View File

@ -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) ->