diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index 68e0ae3..1bb95d2 100644 --- a/src/ibrowse_http_client.erl +++ b/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, diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index 1e644eb..cc067fc 100644 --- a/src/ibrowse_lb.erl +++ b/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.