Compare commits
No commits in common. "a117d81fc6c3dddcd9d3389fee8292222ca07ac9" and "d544c04709be9e8018e7ffae7b315cb8727442cd" have entirely different histories.
a117d81fc6
...
d544c04709
@ -83,7 +83,7 @@ handle_event(info, {timeout, _, create_transport}, ?STATE_DENIED, State = #state
|
|||||||
{ok, TransportPid} = efka_transport:start_link(self(), Host, Port),
|
{ok, TransportPid} = efka_transport:start_link(self(), Host, Port),
|
||||||
efka_transport:connect(TransportPid),
|
efka_transport:connect(TransportPid),
|
||||||
|
|
||||||
{next_state, ?STATE_CONNECTING, State#state{transport_pid = TransportPid}};
|
{next_state, ?STATE_CONNECTING, State};
|
||||||
|
|
||||||
%% 连接的回复
|
%% 连接的回复
|
||||||
handle_event(info, {connect_reply, Reply}, ?STATE_CONNECTING, State = #state{transport_pid = TransportPid}) ->
|
handle_event(info, {connect_reply, Reply}, ?STATE_CONNECTING, State = #state{transport_pid = TransportPid}) ->
|
||||||
@ -93,7 +93,7 @@ handle_event(info, {connect_reply, Reply}, ?STATE_CONNECTING, State = #state{tra
|
|||||||
{next_state, ?STATE_AUTH, State};
|
{next_state, ?STATE_AUTH, State};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]),
|
lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]),
|
||||||
efka_transport:stop(TransportPid),
|
% efka_transport:stop(TransportPid),
|
||||||
{next_state, ?STATE_DENIED, State}
|
{next_state, ?STATE_DENIED, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -144,11 +144,10 @@ handle_event(info, {server_push_message, PacketId, <<16:8, Directive>>}, _StateN
|
|||||||
lager:debug("[efka_agent] get directive with packet_id: ~p, to device_uuid: ~p, content: ~p", [PacketId, Topic, Content]),
|
lager:debug("[efka_agent] get directive with packet_id: ~p, to device_uuid: ~p, content: ~p", [PacketId, Topic, Content]),
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
|
|
||||||
%% transport进程退出
|
|
||||||
handle_event(info, {'EXIT', TransportPid, Reason}, _StateName, State = #state{transport_pid = TransportPid}) ->
|
handle_event(info, {'EXIT', TransportPid, Reason}, _StateName, State = #state{transport_pid = TransportPid}) ->
|
||||||
lager:warning("[efka_agent] transport pid: ~p, exit with reason: ~p", [TransportPid, Reason]),
|
lager:debug("[efka_agent] transport pid: ~p, exit with reason: ~p", [TransportPid, Reason]),
|
||||||
erlang:start_timer(5000, self(), create_transport),
|
erlang:start_timer(5000, self(), create_transport),
|
||||||
{next_state, ?STATE_DENIED, State#state{transport_pid = undefined}};
|
{next_status, ?STATE_DENIED, State#state{transport_pid = undefined}};
|
||||||
|
|
||||||
handle_event(_EventType, _EventContent, _StateName, State = #state{}) ->
|
handle_event(_EventType, _EventContent, _StateName, State = #state{}) ->
|
||||||
NextStateName = the_next_state_name,
|
NextStateName = the_next_state_name,
|
||||||
|
|||||||
@ -38,7 +38,6 @@
|
|||||||
auth_request(Pid, Timeout) when is_pid(Pid), is_integer(Timeout) ->
|
auth_request(Pid, Timeout) when is_pid(Pid), is_integer(Timeout) ->
|
||||||
gen_server:cast(Pid, {auth_request, Timeout}).
|
gen_server:cast(Pid, {auth_request, Timeout}).
|
||||||
|
|
||||||
-spec connect(Pid :: pid()) -> no_return().
|
|
||||||
connect(Pid) when is_pid(Pid) ->
|
connect(Pid) when is_pid(Pid) ->
|
||||||
gen_server:cast(Pid, connect).
|
gen_server:cast(Pid, connect).
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ response(Pid, PacketId, Response) when is_pid(Pid), is_integer(PacketId) ->
|
|||||||
gen_server:cast(Pid, {response, PacketId, Response}).
|
gen_server:cast(Pid, {response, PacketId, Response}).
|
||||||
|
|
||||||
stop(Pid) when is_pid(Pid) ->
|
stop(Pid) when is_pid(Pid) ->
|
||||||
gen_server:stop(Pid, normal, 2000).
|
gen_server:stop(Pid).
|
||||||
|
|
||||||
%% @doc Spawns the server and registers the local name (unique)
|
%% @doc Spawns the server and registers the local name (unique)
|
||||||
-spec(start_link(ParentPid :: pid(), Host :: string(), Port :: integer()) ->
|
-spec(start_link(ParentPid :: pid(), Host :: string(), Port :: integer()) ->
|
||||||
@ -102,7 +101,7 @@ handle_cast(connect, State = #state{host = Host, port = Port, parent_pid = Paren
|
|||||||
{noreply, State#state{socket = Socket}};
|
{noreply, State#state{socket = Socket}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
ParentPid ! {connect_reply, {error, Reason}},
|
ParentPid ! {connect_reply, {error, Reason}},
|
||||||
{noreply, State#state{socket = undefined}}
|
{noreply, Reason}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
%% auth校验
|
%% auth校验
|
||||||
@ -129,7 +128,7 @@ handle_cast({auth_request, Timeout}, State = #state{parent_pid = ParentPid, sock
|
|||||||
{noreply, State#state{packet_id = PacketId + 1}}
|
{noreply, State#state{packet_id = PacketId + 1}}
|
||||||
after Timeout ->
|
after Timeout ->
|
||||||
ParentPid ! {auth_reply, {error, timeout}},
|
ParentPid ! {auth_reply, {error, timeout}},
|
||||||
{noreply, State#state{packet_id = PacketId + 1}}
|
{stop, normal, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_cast({send, Method, Packet}, State = #state{socket = Socket}) ->
|
handle_cast({send, Method, Packet}, State = #state{socket = Socket}) ->
|
||||||
@ -175,7 +174,7 @@ handle_info(Info, State = #state{}) ->
|
|||||||
%% with Reason. The return value is ignored.
|
%% with Reason. The return value is ignored.
|
||||||
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
|
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
|
||||||
State :: #state{}) -> term()).
|
State :: #state{}) -> term()).
|
||||||
terminate(Reason, #state{}) ->
|
terminate(Reason, _State = #state{}) ->
|
||||||
lager:debug("[efka_transport] terminate with reason: ~p", [Reason]),
|
lager:debug("[efka_transport] terminate with reason: ~p", [Reason]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user