Kaynağa Gözat

Encapsulated the iteration of connections and msgs

Use of foldl for iteration is not hidden as implementation
detail.  Also hid details of how to message conn to set
tracing within API.
pull/123/head
benjaminplee 10 yıl önce
ebeveyn
işleme
3061aa2fd9
2 değiştirilmiş dosya ile 10 ekleme ve 8 silme
  1. +4
    -0
      src/ibrowse_http_client.erl
  2. +6
    -8
      src/ibrowse_lb.erl

+ 4
- 0
src/ibrowse_http_client.erl Dosyayı Görüntüle

@ -19,6 +19,7 @@
start/1,
start/2,
stop/1,
trace/2,
send_req/7
]).
@ -101,6 +102,9 @@ stop(Conn_pid) ->
ok
end.
trace(Conn_pid, Bool) ->
catch Conn_pid ! {trace, Bool}.
send_req(Conn_Pid, Url, Headers, Method, Body, Options, Timeout) ->
gen_server:call(
Conn_Pid,

+ 6
- 8
src/ibrowse_lb.erl Dosyayı Görüntüle

@ -122,10 +122,7 @@ handle_call(stop, _From, #state{ets_tid = undefined} = State) ->
gen_server:reply(_From, ok),
{stop, normal, State};
handle_call(stop, _From, #state{ets_tid = Tid} = State) ->
ets:foldl(fun({Pid, _}, Acc) ->
ibrowse_http_client:stop(Pid),
Acc
end, [], Tid),
for_each_connection_pid(Tid, fun(Pid) -> ibrowse_http_client:stop(Pid) end),
gen_server:reply(_From, ok),
{stop, normal, State};
@ -172,10 +169,7 @@ handle_info({trace, Bool}, #state{ets_tid = undefined} = State) ->
put(my_trace_flag, Bool),
{noreply, State};
handle_info({trace, Bool}, #state{ets_tid = Tid} = State) ->
ets:foldl(fun({Pid, _}, Acc) when is_pid(Pid) ->
catch Pid ! {trace, Bool},
Acc
end, undefined, Tid),
for_each_connection_pid(Tid, fun(Pid) -> ibrowse_http_client:trace(Pid, Bool) end),
put(my_trace_flag, Bool),
{noreply, State};
@ -250,3 +244,7 @@ record_new_connection(Tid, Pid) ->
record_request_for_connection(Tid, Pid) ->
catch ets:update_counter(Tid, Pid, {2, 1, ?PIPELINE_MAX, ?PIPELINE_MAX}).
for_each_connection_pid(Tid, Fun) ->
catch ets:foldl(fun({Pid, _}, _) -> Fun(Pid) end, undefined, Tid),
ok.

Yükleniyor…
İptal
Kaydet