Feng пре 10 година
родитељ
комит
c7f0e33674
2 измењених фајлова са 7 додато и 16 уклоњено
  1. 1 10
      src/emqttd.erl
  2. 6 6
      src/emqttd_client.erl

+ 1 - 10
src/emqttd.erl

@@ -91,8 +91,7 @@ open_listener({https, Port, Options}) ->
 	mochiweb:start_http(Port, Options, MFArgs).
 
 open_listener(Protocol, Port, Options) ->
-    Rl = rate_limiter(emqttd_opts:g(rate_limit, Options)),
-    MFArgs = {emqttd_client, start_link, [[{rate_limiter, Rl} | env(mqtt)]]},
+    MFArgs = {emqttd_client, start_link, [env(mqtt)]},
     esockd:open(Protocol, Port, merge_sockopts(Options) , MFArgs).
 
 merge_sockopts(Options) ->
@@ -100,14 +99,6 @@ merge_sockopts(Options) ->
                                  proplists:get_value(sockopts, Options, [])),
     emqttd_opts:merge(Options, [{sockopts, SockOpts}]).
 
-%% TODO: will refactor in 0.14.0 release.
-rate_limiter(undefined) ->
-    undefined;
-rate_limiter(Config) ->
-    Bps = fun(S) -> list_to_integer(string:strip(S)) * 1024 end,
-    [Burst, Rate] = [Bps(S) || S <- string:tokens(Config, ",")],
-    esockd_rate_limiter:new(Burst, Rate).
-
 %%------------------------------------------------------------------------------
 %% @doc Close Listeners
 %% @end

+ 6 - 6
src/emqttd_client.erl

@@ -281,14 +281,14 @@ received(Bytes, State = #client_state{parser_fun  = ParserFun,
 
 rate_limit(_Size, State = #client_state{rate_limit = undefined}) ->
     run_socket(State);
-rate_limit(Size, State = #client_state{rate_limit = Limiter}) ->
-    case esockd_ratelimit:check(Limiter, Size) of
-        {0, Limiter1} ->
-            run_socket(State#client_state{conn_state = running, rate_limit = Limiter1});
-        {Pause, Limiter1} ->
+rate_limit(Size, State = #client_state{rate_limit = Rl}) ->
+    case Rl:check(Size) of
+        {0, Rl1} ->
+            run_socket(State#client_state{conn_state = running, rate_limit = Rl1});
+        {Pause, Rl1} ->
             ?LOG(error, "Rate limiter pause for ~p", [Size, Pause], State),
             erlang:send_after(Pause, self(), activate_sock),
-            State#client_state{conn_state = blocked, rate_limit = Limiter1}    
+            State#client_state{conn_state = blocked, rate_limit = Rl1}
     end.
 
 run_socket(State = #client_state{conn_state = blocked}) ->