fix packetId
This commit is contained in:
parent
dad124edb1
commit
3db88cc129
@ -189,14 +189,13 @@ handle_event({call, From}, dropped_message_count, _StateName, State = #state{dro
|
|||||||
{keep_state, State, [{reply, From, DroppedCount}]};
|
{keep_state, State, [{reply, From, DroppedCount}]};
|
||||||
|
|
||||||
%% 异步建立到服务器的连接
|
%% 异步建立到服务器的连接
|
||||||
handle_event(info, {timeout, _, create_transport}, ?STATE_DISCONNECTED, State) ->
|
handle_event(info, {timeout, _, create_transport}, ?STATE_DISCONNECTED, State = #state{next_pkt_id = PktId}) ->
|
||||||
case connect_socket() of
|
case connect_socket() of
|
||||||
{ok, Socket} ->
|
{ok, Socket} ->
|
||||||
{Ref, State1} = next_packet_id(State),
|
AuthPacket = auth_packet(PktId),
|
||||||
AuthPacket = auth_packet(Ref),
|
|
||||||
ok = ssl:send(Socket, AuthPacket),
|
ok = ssl:send(Socket, AuthPacket),
|
||||||
logger:debug("[efka_iot_client] send auth request, ref: ~p", [Ref]),
|
logger:debug("[efka_iot_client] send auth request, packet_id: ~p", [PktId]),
|
||||||
{next_state, ?STATE_AUTH, State1#state{socket = Socket, auth_ref = Ref}, [{state_timeout, 5000, auth_timeout}]};
|
{next_state, ?STATE_AUTH, State#state{socket = Socket, auth_ref = PktId, next_pkt_id = PktId + 1}, [{state_timeout, 5000, auth_timeout}]};
|
||||||
{error, _Reason} ->
|
{error, _Reason} ->
|
||||||
schedule_reconnect(),
|
schedule_reconnect(),
|
||||||
{keep_state, State#state{socket = undefined}}
|
{keep_state, State#state{socket = undefined}}
|
||||||
@ -452,10 +451,6 @@ decode_pb_frame(Payload, MsgName) ->
|
|||||||
{error, {bad_protobuf, MsgName, Class, Reason}}
|
{error, {bad_protobuf, MsgName, Class, Reason}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec next_packet_id(#state{}) -> {pos_integer(), #state{}}.
|
|
||||||
next_packet_id(State = #state{next_pkt_id = PacketId}) ->
|
|
||||||
{PacketId, State#state{next_pkt_id = PacketId + 1}}.
|
|
||||||
|
|
||||||
-spec connect_socket() -> {ok, ssl:sslsocket()} | {error, term()}.
|
-spec connect_socket() -> {ok, ssl:sslsocket()} | {error, term()}.
|
||||||
connect_socket() ->
|
connect_socket() ->
|
||||||
{ok, Props} = application:get_env(efka, iot_server),
|
{ok, Props} = application:get_env(efka, iot_server),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user