소스 검색

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 년 전
부모
커밋
3061aa2fd9
2개의 변경된 파일10개의 추가작업 그리고 8개의 파일을 삭제
  1. +4
    -0
      src/ibrowse_http_client.erl
  2. +6
    -8
      src/ibrowse_lb.erl

+ 4
- 0
src/ibrowse_http_client.erl 파일 보기

@ -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 파일 보기

@ -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.

불러오는 중...
취소
저장