session
This commit is contained in:
parent
dccbee2905
commit
fedb5c209a
|
@ -140,13 +140,13 @@ terminate(Reason, #state{proto_state = unefined}) ->
|
||||||
io:format("client terminated: ~p, reason: ~p~n", [self(), Reason]),
|
io:format("client terminated: ~p, reason: ~p~n", [self(), Reason]),
|
||||||
%%TODO: fix keep_alive...
|
%%TODO: fix keep_alive...
|
||||||
%%emqtt_keep_alive:cancel(KeepAlive),
|
%%emqtt_keep_alive:cancel(KeepAlive),
|
||||||
%emqtt_protocol:client_terminated(ProtoState),
|
%emqtt_protocol:connection_lost(ProtoState),
|
||||||
ok;
|
ok;
|
||||||
|
|
||||||
terminate(_Reason, #state { keepalive = KeepAlive, proto_state = ProtoState }) ->
|
terminate(_Reason, #state { keepalive = KeepAlive, proto_state = ProtoState }) ->
|
||||||
%%TODO: fix keep_alive...
|
%%TODO: fix keep_alive...
|
||||||
emqtt_keepalive:cancel(KeepAlive),
|
emqtt_keepalive:cancel(KeepAlive),
|
||||||
emqtt_protocol:client_terminated(ProtoState),
|
emqtt_protocol:connection_lost(ProtoState),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
-export([initial_state/2]).
|
-export([initial_state/2]).
|
||||||
|
|
||||||
-export([handle_packet/2, send_message/2, send_packet/2, client_terminated/1]).
|
-export([handle_packet/2, send_message/2, send_packet/2, connection_lost/1]).
|
||||||
|
|
||||||
-export([info/1]).
|
-export([info/1]).
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ send_packet(Packet, #proto_state{socket = Sock, peer_name = PeerName, client_id
|
||||||
erlang:port_command(Sock, Data).
|
erlang:port_command(Sock, Data).
|
||||||
|
|
||||||
%%TODO: fix me later...
|
%%TODO: fix me later...
|
||||||
client_terminated(#proto_state{client_id = ClientId} = State) ->
|
connection_lost(#proto_state{client_id = ClientId} = State) ->
|
||||||
ok.
|
ok.
|
||||||
%emqtt_cm:unregister(ClientId, self()).
|
%emqtt_cm:unregister(ClientId, self()).
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
|
|
||||||
-export([create/2, resume/2, destroy/1]).
|
-export([lookup/1, create/2, resume/2, destroy/1]).
|
||||||
|
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% gen_server Function Exports
|
%% gen_server Function Exports
|
||||||
|
@ -62,12 +62,18 @@
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
|
-record(state, { expires = 24, %hours
|
||||||
|
max_queue = 1000 }).
|
||||||
|
|
||||||
|
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
%% API Function Definitions
|
%% API Function Definitions
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
|
||||||
start_link() ->
|
start_link(SessOpts) ->
|
||||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
|
gen_server:start_link({local, ?SERVER}, ?MODULE, [SessOpts], []).
|
||||||
|
|
||||||
|
lookup(ClientId) -> ok.
|
||||||
|
|
||||||
create(ClientId, Pid) -> ok.
|
create(ClientId, Pid) -> ok.
|
||||||
|
|
||||||
|
@ -79,8 +85,12 @@ destroy(ClientId) -> ok.
|
||||||
%% gen_server Function Definitions
|
%% gen_server Function Definitions
|
||||||
%% ------------------------------------------------------------------
|
%% ------------------------------------------------------------------
|
||||||
|
|
||||||
init(Args) ->
|
init(SessOpts) ->
|
||||||
{ok, Args}.
|
{ok, SessOpts} = application:get_env(session),
|
||||||
|
State = #state{ expires = proplists:get_value(expires, SessOpts, 24) * 3600,
|
||||||
|
max_queue = proplists:get_value(max_queue, SessOpts, 1000) },
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
|
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{reply, ok, State}.
|
{reply, ok, State}.
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{error_logger_redirect, false},
|
{error_logger_redirect, false},
|
||||||
{crash_log, "log/emqtt_crash.log"},
|
{crash_log, "log/emqtt_crash.log"},
|
||||||
{handlers, [
|
{handlers, [
|
||||||
{lager_console_backend, info},
|
{lager_console_backend, debug},
|
||||||
{lager_file_backend, [
|
{lager_file_backend, [
|
||||||
{file, "log/emqtt_error.log"},
|
{file, "log/emqtt_error.log"},
|
||||||
{level, error},
|
{level, error},
|
||||||
|
@ -33,6 +33,14 @@
|
||||||
]},
|
]},
|
||||||
{emqtt, [
|
{emqtt, [
|
||||||
{auth, {anonymous, []}}, %internal, anonymous
|
{auth, {anonymous, []}}, %internal, anonymous
|
||||||
|
{session, [
|
||||||
|
{expires, 24},
|
||||||
|
{max_queue, 1000},
|
||||||
|
{qos0, false}
|
||||||
|
]},
|
||||||
|
{retain, [
|
||||||
|
|
||||||
|
]},
|
||||||
{listen, [
|
{listen, [
|
||||||
{mqtt, 1883, [
|
{mqtt, 1883, [
|
||||||
{max_conns, 1024},
|
{max_conns, 1024},
|
||||||
|
|
Loading…
Reference in New Issue