This commit is contained in:
Feng Lee 2015-01-12 19:24:44 +08:00
parent dccbee2905
commit fedb5c209a
4 changed files with 28 additions and 10 deletions

View File

@ -140,13 +140,13 @@ terminate(Reason, #state{proto_state = unefined}) ->
io:format("client terminated: ~p, reason: ~p~n", [self(), Reason]),
%%TODO: fix keep_alive...
%%emqtt_keep_alive:cancel(KeepAlive),
%emqtt_protocol:client_terminated(ProtoState),
%emqtt_protocol:connection_lost(ProtoState),
ok;
terminate(_Reason, #state { keepalive = KeepAlive, proto_state = ProtoState }) ->
%%TODO: fix keep_alive...
emqtt_keepalive:cancel(KeepAlive),
emqtt_protocol:client_terminated(ProtoState),
emqtt_protocol:connection_lost(ProtoState),
ok.
code_change(_OldVsn, State, _Extra) ->

View File

@ -45,7 +45,7 @@
-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]).
@ -277,7 +277,7 @@ send_packet(Packet, #proto_state{socket = Sock, peer_name = PeerName, client_id
erlang:port_command(Sock, Data).
%%TODO: fix me later...
client_terminated(#proto_state{client_id = ClientId} = State) ->
connection_lost(#proto_state{client_id = ClientId} = State) ->
ok.
%emqtt_cm:unregister(ClientId, self()).

View File

@ -53,7 +53,7 @@
-export([start_link/0]).
-export([create/2, resume/2, destroy/1]).
-export([lookup/1, create/2, resume/2, destroy/1]).
%% ------------------------------------------------------------------
%% gen_server Function Exports
@ -62,12 +62,18 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-record(state, { expires = 24, %hours
max_queue = 1000 }).
%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
start_link(SessOpts) ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [SessOpts], []).
lookup(ClientId) -> ok.
create(ClientId, Pid) -> ok.
@ -79,8 +85,12 @@ destroy(ClientId) -> ok.
%% gen_server Function Definitions
%% ------------------------------------------------------------------
init(Args) ->
{ok, Args}.
init(SessOpts) ->
{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) ->
{reply, ok, State}.

View File

@ -14,7 +14,7 @@
{error_logger_redirect, false},
{crash_log, "log/emqtt_crash.log"},
{handlers, [
{lager_console_backend, info},
{lager_console_backend, debug},
{lager_file_backend, [
{file, "log/emqtt_error.log"},
{level, error},
@ -33,6 +33,14 @@
]},
{emqtt, [
{auth, {anonymous, []}}, %internal, anonymous
{session, [
{expires, 24},
{max_queue, 1000},
{qos0, false}
]},
{retain, [
]},
{listen, [
{mqtt, 1883, [
{max_conns, 1024},