fix format
This commit is contained in:
parent
fb6e3dc066
commit
e8133366e1
|
@ -74,8 +74,9 @@ init(SockArgs = {Transport, Sock, _SockFun}) ->
|
||||||
proto_state = emqtt_protocol:init(Transport, NewSock, Peername)}),
|
proto_state = emqtt_protocol:init(Transport, NewSock, Peername)}),
|
||||||
gen_server:enter_loop(?MODULE, [], State, 10000).
|
gen_server:enter_loop(?MODULE, [], State, 10000).
|
||||||
|
|
||||||
handle_call(info, _From, State = #state{
|
%%TODO: Not enough...
|
||||||
conn_name=ConnName, proto_state = ProtoState}) ->
|
handle_call(info, _From, State = #state{conn_name=ConnName,
|
||||||
|
proto_state = ProtoState}) ->
|
||||||
{reply, [{conn_name, ConnName} | emqtt_protocol:info(ProtoState)], State};
|
{reply, [{conn_name, ConnName} | emqtt_protocol:info(ProtoState)], State};
|
||||||
|
|
||||||
handle_call(Req, _From, State) ->
|
handle_call(Req, _From, State) ->
|
||||||
|
@ -87,7 +88,8 @@ handle_cast(Msg, State) ->
|
||||||
handle_info(timeout, State) ->
|
handle_info(timeout, State) ->
|
||||||
stop({shutdown, timeout}, State);
|
stop({shutdown, timeout}, State);
|
||||||
|
|
||||||
handle_info({stop, duplicate_id, _NewPid}, State=#state{ proto_state = ProtoState, conn_name=ConnName}) ->
|
handle_info({stop, duplicate_id, _NewPid}, State=#state{proto_state = ProtoState,
|
||||||
|
conn_name=ConnName}) ->
|
||||||
%% TODO: to...
|
%% TODO: to...
|
||||||
%% need transfer data???
|
%% need transfer data???
|
||||||
%% emqtt_client:transfer(NewPid, Data),
|
%% emqtt_client:transfer(NewPid, Data),
|
||||||
|
@ -145,7 +147,8 @@ terminate(Reason, #state{ peer_name = PeerName, keepalive = KeepAlive, proto_sta
|
||||||
{undefined, _} -> ok;
|
{undefined, _} -> ok;
|
||||||
{_, {shutdown, Error}} ->
|
{_, {shutdown, Error}} ->
|
||||||
emqtt_protocol:shutdown(Error, ProtoState);
|
emqtt_protocol:shutdown(Error, ProtoState);
|
||||||
{_, _} -> ok %TODO:
|
{_, _} ->
|
||||||
|
ok
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -158,8 +161,7 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
process_received_bytes(<<>>, State) ->
|
process_received_bytes(<<>>, State) ->
|
||||||
{noreply, State, hibernate};
|
{noreply, State, hibernate};
|
||||||
|
|
||||||
process_received_bytes(Bytes,
|
process_received_bytes(Bytes, State = #state{parse_state = ParseState,
|
||||||
State = #state{ parse_state = ParseState,
|
|
||||||
proto_state = ProtoState,
|
proto_state = ProtoState,
|
||||||
conn_name = ConnStr}) ->
|
conn_name = ConnStr}) ->
|
||||||
case emqtt_parser:parse(Bytes, ParseState) of
|
case emqtt_parser:parse(Bytes, ParseState) of
|
||||||
|
@ -170,9 +172,7 @@ process_received_bytes(Bytes,
|
||||||
{ok, Packet, Rest} ->
|
{ok, Packet, Rest} ->
|
||||||
case emqtt_protocol:handle_packet(Packet, ProtoState) of
|
case emqtt_protocol:handle_packet(Packet, ProtoState) of
|
||||||
{ok, ProtoState1} ->
|
{ok, ProtoState1} ->
|
||||||
process_received_bytes(
|
process_received_bytes(Rest, State#state{parse_state = emqtt_parser:init(),
|
||||||
Rest,
|
|
||||||
State#state{ parse_state = emqtt_parser:init(),
|
|
||||||
proto_state = ProtoState1});
|
proto_state = ProtoState1});
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
lager:error("MQTT protocol error ~p for connection ~p~n", [Error, ConnStr]),
|
lager:error("MQTT protocol error ~p for connection ~p~n", [Error, ConnStr]),
|
||||||
|
@ -204,8 +204,7 @@ control_throttle(State = #state{ conn_state = Flow,
|
||||||
conserve = Conserve}) ->
|
conserve = Conserve}) ->
|
||||||
case {Flow, Conserve} of
|
case {Flow, Conserve} of
|
||||||
{running, true} -> State #state{conn_state = blocked};
|
{running, true} -> State #state{conn_state = blocked};
|
||||||
{blocked, false} -> run_socket(State #state{
|
{blocked, false} -> run_socket(State #state{conn_state = running});
|
||||||
conn_state = running });
|
|
||||||
{_, _} -> run_socket(State)
|
{_, _} -> run_socket(State)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
%% 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.
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqtt_protocol).
|
-module(emqtt_protocol).
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
-include("emqtt.hrl").
|
||||||
|
@ -29,14 +28,12 @@
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% API Function Exports
|
%% API Function Exports
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
|
||||||
-export([init/3, client_id/1]).
|
-export([init/3, client_id/1]).
|
||||||
|
|
||||||
-export([handle_packet/2, send_message/2, send_packet/2, redeliver/2, shutdown/2]).
|
-export([handle_packet/2, send_message/2, send_packet/2, redeliver/2, shutdown/2]).
|
||||||
|
|
||||||
-export([info/1]).
|
-export([info/1]).
|
||||||
|
|
||||||
|
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% Protocol State
|
%% Protocol State
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
@ -54,20 +51,12 @@
|
||||||
will_msg
|
will_msg
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%%----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-ifdef(use_specs).
|
|
||||||
|
|
||||||
-type(proto_state() :: #proto_state{}).
|
-type(proto_state() :: #proto_state{}).
|
||||||
|
|
||||||
-spec(send_message({pid() | tuple(), mqtt_message()}, proto_state()) -> {ok, proto_state()}).
|
-spec(send_message({pid() | tuple(), mqtt_message()}, proto_state()) -> {ok, proto_state()}).
|
||||||
|
|
||||||
-spec(handle_packet(mqtt_packet(), proto_state()) -> {ok, proto_state()} | {error, any()}).
|
-spec(handle_packet(mqtt_packet(), proto_state()) -> {ok, proto_state()} | {error, any()}).
|
||||||
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%%----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-define(PACKET_TYPE(Packet, Type),
|
-define(PACKET_TYPE(Packet, Type),
|
||||||
Packet = #mqtt_packet{header = #mqtt_packet_header { type = Type }}).
|
Packet = #mqtt_packet{header = #mqtt_packet_header { type = Type }}).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue