fix
This commit is contained in:
parent
b607b90416
commit
05eef80903
@ -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}) ->
|
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
|
case HasSession andalso is_pid(ChannelPid) of
|
||||||
true ->
|
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}}]};
|
{keep_state, State, [{reply, From, {ok, Ref}}]};
|
||||||
false ->
|
false ->
|
||||||
logger:debug("[iot_host] uuid: ~p, invalid state: ~p", [UUID, state_map(State)]),
|
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) ->
|
start_auth_command(ChannelPid, Auth, From) when is_pid(ChannelPid), is_boolean(Auth) ->
|
||||||
HostPid = self(),
|
HostPid = self(),
|
||||||
spawn(fun() ->
|
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),
|
Result = iot_host:await_reply(HostPid, Ref, ?AUTH_COMMAND_TIMEOUT),
|
||||||
HostPid ! {auth_command_result, From, Auth, ChannelPid, Result}
|
HostPid ! {auth_command_result, From, Auth, ChannelPid, Result}
|
||||||
end).
|
end).
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
-define(INFLIGHT_TIMEOUT, 60000).
|
-define(INFLIGHT_TIMEOUT, 60000).
|
||||||
|
|
||||||
%% API
|
%% 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]).
|
-export([start_link/3, stop/2]).
|
||||||
%% gen_server callbacks
|
%% 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) ->
|
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}).
|
gen_server:cast(Pid, {pub, Topic, Qos, Content}).
|
||||||
|
|
||||||
-spec activate(Pid :: pid(), Auth :: boolean()) -> Ref :: reference().
|
-spec activate(Pid :: pid(), ReceiverPid :: pid(), Ref :: reference(), Auth :: boolean()) -> ok.
|
||||||
activate(Pid, Auth) when is_pid(Pid), is_boolean(Auth) ->
|
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,
|
Command = case Auth of true -> activate; false -> deactivate end,
|
||||||
Ref = make_ref(),
|
|
||||||
ReceiverPid = self(),
|
|
||||||
gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {auth, Command}}),
|
gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {auth, Command}}),
|
||||||
Ref.
|
ok.
|
||||||
|
|
||||||
-spec container_call(Pid :: pid(), ReceiverPid :: pid(), Request :: map()) -> Ref :: reference().
|
-spec container_call(Pid :: pid(), ReceiverPid :: pid(), Ref :: reference(), Request :: map()) -> ok.
|
||||||
container_call(Pid, ReceiverPid, Request) when is_pid(Pid), is_pid(ReceiverPid), is_map(Request) ->
|
container_call(Pid, ReceiverPid, Ref, Request) when is_pid(Pid), is_pid(ReceiverPid), is_reference(Ref), is_map(Request) ->
|
||||||
Ref = make_ref(),
|
|
||||||
gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {container, Request}}),
|
gen_server:cast(Pid, {command_call, ReceiverPid, Ref, {container, Request}}),
|
||||||
Ref.
|
ok.
|
||||||
|
|
||||||
-spec cancel_command_call(Pid :: pid(), Ref :: reference()) -> ok.
|
-spec cancel_command_call(Pid :: pid(), Ref :: reference()) -> ok.
|
||||||
cancel_command_call(Pid, Ref) when is_pid(Pid), is_reference(Ref) ->
|
cancel_command_call(Pid, Ref) when is_pid(Pid), is_reference(Ref) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user