From 9effc2fad7414e1b54fc61c1378ebdf116495a0b Mon Sep 17 00:00:00 2001 From: Feng Date: Wed, 11 Nov 2015 12:18:13 +0800 Subject: [PATCH] monitors --- src/emqttd_cm.erl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/emqttd_cm.erl b/src/emqttd_cm.erl index 4c2c2b252..63cb358e3 100644 --- a/src/emqttd_cm.erl +++ b/src/emqttd_cm.erl @@ -48,9 +48,6 @@ -define(CM_POOL, ?MODULE). --define(LOG(Level, Format, Args, Client), - lager:Level("CM(~s): " ++ Format, [Client#mqtt_client.client_id|Args])). - %%%============================================================================= %%% API %%%============================================================================= @@ -127,7 +124,7 @@ prioritise_cast(Msg, _Len, _State) -> end. prioritise_info(_Msg, _Len, _State) -> - 1. + 3. handle_call(Req, _From, State) -> lager:error("Unexpected request: ~p", [Req]), @@ -136,9 +133,9 @@ handle_call(Req, _From, State) -> handle_cast({register, Client = #mqtt_client{client_id = ClientId, client_pid = Pid}}, State) -> case lookup_proc(ClientId) of - Pid -> + Pid -> {noreply, State}; - _None -> + _ -> ets:insert(mqtt_client, Client), {noreply, setstats(monitor_client(ClientId, Pid, State))} end; @@ -148,7 +145,7 @@ handle_cast({unregister, ClientId, Pid}, State) -> Pid -> ets:delete(mqtt_client, ClientId), {noreply, setstats(State)}; - undefined -> + _ -> {noreply, State} end; @@ -156,8 +153,8 @@ handle_cast(Msg, State) -> lager:error("Unexpected Msg: ~p", [Msg]), {noreply, State}. -handle_info({'DOWN', MRef, process, DownPid, _Reason}, State = #state{monitors = MonDict}) -> - case dict:find(MRef, MonDict) of +handle_info({'DOWN', MRef, process, DownPid, _Reason}, State) -> + case dict:find(MRef, State#state.monitors) of {ok, {ClientId, DownPid}} -> case lookup_proc(ClientId) of DownPid ->