Преглед изворни кода

Hibernate after a packet sent

Feng Lee пре 9 година
родитељ
комит
498915e5b3
3 измењених фајлова са 6 додато и 5 уклоњено
  1. 2 2
      src/emqttd_client.erl
  2. 2 1
      src/emqttd_session.erl
  3. 2 2
      src/emqttd_ws_client.erl

+ 2 - 2
src/emqttd_client.erl

@@ -238,7 +238,7 @@ handle_info({inet_async, _Sock, _Ref, {error, Reason}}, State) ->
     shutdown(Reason, State);
 
 handle_info({inet_reply, _Sock, ok}, State) ->
-    {noreply, State};
+    {noreply, State, hibernate};
 
 handle_info({inet_reply, _Sock, {error, Reason}}, State) ->
     shutdown(Reason, State);
@@ -299,7 +299,7 @@ received(Bytes, State = #client_state{parser_fun  = ParserFun,
                                       proto_state = ProtoState}) ->
     case catch ParserFun(Bytes) of
         {more, NewParser}  ->
-            {noreply, run_socket(State#client_state{parser_fun = NewParser})};
+            {noreply, run_socket(State#client_state{parser_fun = NewParser}), hibernate};
         {ok, Packet, Rest} ->
             emqttd_metrics:received(Packet),
             case emqttd_protocol:received(Packet, ProtoState) of

+ 2 - 1
src/emqttd_session.erl

@@ -333,7 +333,8 @@ prioritise_info(Msg, _Len, _State) ->
         _                -> 0
     end.
 
-handle_pre_hibernate(State) ->
+handle_pre_hibernate(State = #state{client_id = ClientId}) ->
+    io:format("Session(~s) will hibernate!~n", [ClientId]),
     {hibernate, emit_stats(State)}.
 
 handle_call({publish, Msg = #mqtt_message{qos = ?QOS_2, pktid = PacketId}}, _From,

+ 2 - 2
src/emqttd_ws_client.erl

@@ -129,7 +129,7 @@ handle_call(session, _From, State = #wsclient_state{proto_state = ProtoState}) -
 
 handle_call(Req, _From, State = #wsclient_state{peer = Peer}) ->
     ?WSLOG(error, Peer, "Unexpected request: ~p", [Req]),
-    {reply, {error, unsupported_request}, State}.
+    reply({error, unsupported_request}, State).
 
 handle_cast({received, Packet}, State = #wsclient_state{peer = Peer, proto_state = ProtoState}) ->
     emqttd_metrics:received(Packet),
@@ -147,7 +147,7 @@ handle_cast({received, Packet}, State = #wsclient_state{peer = Peer, proto_state
 
 handle_cast(Msg, State = #wsclient_state{peer = Peer}) ->
     ?WSLOG(error, Peer, "Unexpected msg: ~p", [Msg]),
-    {noreply, State}.
+    {noreply, State, hibernate}.
 
 handle_info({subscribe, TopicTable}, State) ->
     with_proto(