comment
This commit is contained in:
parent
e8133366e1
commit
c6668c6dc9
|
@ -111,8 +111,8 @@ handle_info({inet_reply, _Ref, ok}, State) ->
|
||||||
|
|
||||||
handle_info({inet_async, Sock, _Ref, {ok, Data}}, State = #state{peer_name = PeerName, socket = Sock}) ->
|
handle_info({inet_async, Sock, _Ref, {ok, Data}}, State = #state{peer_name = PeerName, socket = Sock}) ->
|
||||||
lager:debug("RECV from ~s: ~p", [PeerName, Data]),
|
lager:debug("RECV from ~s: ~p", [PeerName, Data]),
|
||||||
process_received_bytes(
|
process_received_bytes(Data,
|
||||||
Data, control_throttle(State #state{ await_recv = false }));
|
control_throttle(State #state{await_recv = false}));
|
||||||
|
|
||||||
handle_info({inet_async, _Sock, _Ref, {error, Reason}}, State) ->
|
handle_info({inet_async, _Sock, _Ref, {error, Reason}}, State) ->
|
||||||
network_error(Reason, State);
|
network_error(Reason, State);
|
||||||
|
@ -170,7 +170,7 @@ process_received_bytes(Bytes, State = #state{parse_state = ParseState,
|
||||||
control_throttle(State #state{parse_state = ParseState1}),
|
control_throttle(State #state{parse_state = ParseState1}),
|
||||||
hibernate};
|
hibernate};
|
||||||
{ok, Packet, Rest} ->
|
{ok, Packet, Rest} ->
|
||||||
case emqtt_protocol:handle_packet(Packet, ProtoState) of
|
case emqtt_protocol:received(Packet, ProtoState) of
|
||||||
{ok, ProtoState1} ->
|
{ok, ProtoState1} ->
|
||||||
process_received_bytes(Rest, State#state{parse_state = emqtt_parser:init(),
|
process_received_bytes(Rest, State#state{parse_state = emqtt_parser:init(),
|
||||||
proto_state = ProtoState1});
|
proto_state = ProtoState1});
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%% Copyright (c) 2012-2015, Feng Lee <feng@emqtt.io>
|
%%% @Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>
|
||||||
%%
|
%%%
|
||||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% of this software and associated documentation files (the "Software"), to deal
|
%%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% in the Software without restriction, including without limitation the rights
|
%%% in the Software without restriction, including without limitation the rights
|
||||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
%% copies of the Software, and to permit persons to whom the Software is
|
%%% copies of the Software, and to permit persons to whom the Software is
|
||||||
%% furnished to do so, subject to the following conditions:
|
%%% furnished to do so, subject to the following conditions:
|
||||||
%%
|
%%%
|
||||||
%% The above copyright notice and this permission notice shall be included in all
|
%%% The above copyright notice and this permission notice shall be included in all
|
||||||
%% copies or substantial portions of the Software.
|
%%% copies or substantial portions of the Software.
|
||||||
%%
|
%%%
|
||||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%------------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
|
%%% @doc
|
||||||
|
%%% emqtt keepalive.
|
||||||
|
%%%
|
||||||
|
%%% @end
|
||||||
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_keepalive).
|
-module(emqtt_keepalive).
|
||||||
|
|
||||||
-author('feng@emqtt.io').
|
-author('feng@emqtt.io').
|
||||||
|
@ -28,9 +32,12 @@
|
||||||
|
|
||||||
-record(keepalive, {transport, socket, recv_oct, timeout_sec, timeout_msg, timer_ref}).
|
-record(keepalive, {transport, socket, recv_oct, timeout_sec, timeout_msg, timer_ref}).
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Create a keepalive.
|
||||||
%%
|
%%
|
||||||
%% @doc create a keepalive.
|
%% @end
|
||||||
%%
|
%%------------------------------------------------------------------------------
|
||||||
new({Transport, Socket}, TimeoutSec, TimeoutMsg) when TimeoutSec > 0 ->
|
new({Transport, Socket}, TimeoutSec, TimeoutMsg) when TimeoutSec > 0 ->
|
||||||
{ok, [{recv_oct, RecvOct}]} = Transport:getstat(Socket, [recv_oct]),
|
{ok, [{recv_oct, RecvOct}]} = Transport:getstat(Socket, [recv_oct]),
|
||||||
Ref = erlang:send_after(TimeoutSec*1000, self(), TimeoutMsg),
|
Ref = erlang:send_after(TimeoutSec*1000, self(), TimeoutMsg),
|
||||||
|
@ -41,9 +48,12 @@ new({Transport, Socket}, TimeoutSec, TimeoutMsg) when TimeoutSec > 0 ->
|
||||||
timeout_msg = TimeoutMsg,
|
timeout_msg = TimeoutMsg,
|
||||||
timer_ref = Ref}.
|
timer_ref = Ref}.
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Try to resume keepalive, called when timeout.
|
||||||
%%
|
%%
|
||||||
%% @doc try to resume keepalive, called when timeout.
|
%% @end
|
||||||
%%
|
%%------------------------------------------------------------------------------
|
||||||
resume(KeepAlive = #keepalive {transport = Transport,
|
resume(KeepAlive = #keepalive {transport = Transport,
|
||||||
socket = Socket,
|
socket = Socket,
|
||||||
recv_oct = RecvOct,
|
recv_oct = RecvOct,
|
||||||
|
@ -61,9 +71,12 @@ resume(KeepAlive = #keepalive {transport = Transport,
|
||||||
{resumed, KeepAlive#keepalive{recv_oct = NewRecvOct, timer_ref = NewRef}}
|
{resumed, KeepAlive#keepalive{recv_oct = NewRecvOct, timer_ref = NewRef}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Cancel Keepalive.
|
||||||
%%
|
%%
|
||||||
%% @doc cancel keepalive
|
%% @end
|
||||||
%%
|
%%------------------------------------------------------------------------------
|
||||||
cancel(#keepalive{timer_ref = Ref}) ->
|
cancel(#keepalive{timer_ref = Ref}) ->
|
||||||
cancel(Ref);
|
cancel(Ref);
|
||||||
cancel(undefined) ->
|
cancel(undefined) ->
|
||||||
|
|
Loading…
Reference in New Issue