From 2cb114418758e338f4f384d8f645212c59ef4393 Mon Sep 17 00:00:00 2001 From: benjaminplee Date: Tue, 18 Nov 2014 22:32:02 +0000 Subject: [PATCH] Aliased remaining production ets table names For consistency, added macro aliases for remaining ets table names to be found all in one place. --- include/ibrowse.hrl | 2 ++ src/ibrowse.erl | 26 +++++++++++++------------- src/ibrowse_http_client.erl | 6 +++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/ibrowse.hrl b/include/ibrowse.hrl index 76ab236..d6b8f1c 100644 --- a/include/ibrowse.hrl +++ b/include/ibrowse.hrl @@ -20,5 +20,7 @@ -define(CONNECTIONS_LOCAL_TABLE, ibrowse_lb). -define(LOAD_BALANCER_NAMED_TABLE, ibrowse_lb). +-define(CONF_TABLE, ibrowse_conf). +-define(STREAM_TABLE, ibrowse_stream). -endif. diff --git a/src/ibrowse.erl b/src/ibrowse.erl index b541398..0ade277 100644 --- a/src/ibrowse.erl +++ b/src/ibrowse.erl @@ -558,7 +558,7 @@ send_req_direct(Conn_pid, Url, Headers, Method, Body, Options, Timeout) -> %% stream_to option %% @spec stream_next(Req_id :: req_id()) -> ok | {error, unknown_req_id} stream_next(Req_id) -> - case ets:lookup(ibrowse_stream, {req_id_pid, Req_id}) of + case ets:lookup(?STREAM_TABLE, {req_id_pid, Req_id}) of [] -> {error, unknown_req_id}; [{_, Pid}] -> @@ -573,7 +573,7 @@ stream_next(Req_id) -> %% error returned. %% @spec stream_close(Req_id :: req_id()) -> ok | {error, unknown_req_id} stream_close(Req_id) -> - case ets:lookup(ibrowse_stream, {req_id_pid, Req_id}) of + case ets:lookup(?STREAM_TABLE, {req_id_pid, Req_id}) of [] -> {error, unknown_req_id}; [{_, Pid}] -> @@ -747,8 +747,8 @@ init(_) -> put(my_trace_flag, State#state.trace), put(ibrowse_trace_token, "ibrowse"), ?LOAD_BALANCER_NAMED_TABLE = ets:new(?LOAD_BALANCER_NAMED_TABLE, [named_table, public, {keypos, 2}]), - ibrowse_conf = ets:new(ibrowse_conf, [named_table, protected, {keypos, 2}]), - ibrowse_stream = ets:new(ibrowse_stream, [named_table, public]), + ?CONF_TABLE = ets:new(?CONF_TABLE, [named_table, protected, {keypos, 2}]), + ?STREAM_TABLE = ets:new(?STREAM_TABLE, [named_table, public]), import_config(), {ok, #state{}}. @@ -770,7 +770,7 @@ import_config(Filename) -> end. apply_config(Terms) -> - ets:delete_all_objects(ibrowse_conf), + ets:delete_all_objects(?CONF_TABLE), insert_config(Terms). insert_config(Terms) -> @@ -783,12 +783,12 @@ insert_config(Terms) -> {{options, Host, Port}, Options}], lists:foreach( fun({X, Y}) -> - ets:insert(ibrowse_conf, + ets:insert(?CONF_TABLE, #ibrowse_conf{key = X, value = Y}) end, I); ({K, V}) -> - ets:insert(ibrowse_conf, + ets:insert(?CONF_TABLE, #ibrowse_conf{key = K, value = V}); (X) -> @@ -799,7 +799,7 @@ insert_config(Terms) -> %% @doc Internal export get_config_value(Key) -> try - [#ibrowse_conf{value = V}] = ets:lookup(ibrowse_conf, Key), + [#ibrowse_conf{value = V}] = ets:lookup(?CONF_TABLE, Key), V catch error:badarg -> @@ -809,7 +809,7 @@ get_config_value(Key) -> %% @doc Internal export get_config_value(Key, DefVal) -> try - case ets:lookup(ibrowse_conf, Key) of + case ets:lookup(?CONF_TABLE, Key) of [] -> DefVal; [#ibrowse_conf{value = V}] -> @@ -821,7 +821,7 @@ get_config_value(Key, DefVal) -> end. set_config_value(Key, Val) -> - ets:insert(ibrowse_conf, #ibrowse_conf{key = Key, value = Val}). + ets:insert(?CONF_TABLE, #ibrowse_conf{key = Key, value = Val}). %%-------------------------------------------------------------------- %% Function: handle_call/3 %% Description: Handling call messages @@ -888,7 +888,7 @@ handle_cast(_Msg, State) -> %%-------------------------------------------------------------------- handle_info(all_trace_off, State) -> Mspec = [{{ibrowse_conf,{trace,'$1','$2'},true},[],[{{'$1','$2'}}]}], - Trace_on_dests = ets:select(ibrowse_conf, Mspec), + Trace_on_dests = ets:select(?CONF_TABLE, Mspec), Fun = fun(#lb_pid{host_port = {H, P}, pid = Pid}, _) -> case lists:member({H, P}, Trace_on_dests) of false -> @@ -900,7 +900,7 @@ handle_info(all_trace_off, State) -> Acc end, ets:foldl(Fun, undefined, ?LOAD_BALANCER_NAMED_TABLE), - ets:select_delete(ibrowse_conf, [{{ibrowse_conf,{trace,'$1','$2'},true},[],['true']}]), + ets:select_delete(?CONF_TABLE, [{{ibrowse_conf,{trace,'$1','$2'},true},[],['true']}]), {noreply, State}; handle_info({trace, Bool}, State) -> @@ -916,7 +916,7 @@ handle_info({trace, Bool, Host, Port}, State) -> Acc end, ets:foldl(Fun, undefined, ?LOAD_BALANCER_NAMED_TABLE), - ets:insert(ibrowse_conf, #ibrowse_conf{key = {trace, Host, Port}, + ets:insert(?CONF_TABLE, #ibrowse_conf{key = {trace, Host, Port}, value = Bool}), {noreply, State}; diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index ad24351..c4154ab 100644 --- a/src/ibrowse_http_client.erl +++ b/src/ibrowse_http_client.erl @@ -801,7 +801,7 @@ send_req_1(From, {Caller, once} when is_pid(Caller) or is_atom(Caller) -> Async_pid_rec = {{req_id_pid, ReqId}, self()}, - true = ets:insert(ibrowse_stream, Async_pid_rec), + true = ets:insert(?STREAM_TABLE, Async_pid_rec), {Caller, true}; undefined -> {undefined, false}; @@ -1835,7 +1835,7 @@ do_reply(#state{prev_req_id = Prev_req_id} = State, %% stream_once and sync requests on the same connection, it will %% take a while for the req_id-pid mapping to get cleared, but it %% should do no harm. - ets:delete(ibrowse_stream, {req_id_pid, Prev_req_id}), + ets:delete(?STREAM_TABLE, {req_id_pid, Prev_req_id}), State_1#state{prev_req_id = ReqId}; do_reply(State, _From, StreamTo, ReqId, Resp_format, Msg) -> State_1 = dec_pipeline_counter(State), @@ -1853,7 +1853,7 @@ do_error_reply(#state{reqs = Reqs, tunnel_setup_queue = Tun_q} = State, Err) -> ReqList = queue:to_list(Reqs), lists:foreach(fun(#request{from=From, stream_to=StreamTo, req_id=ReqId, response_format = Resp_format}) -> - ets:delete(ibrowse_stream, {req_id_pid, ReqId}), + ets:delete(?STREAM_TABLE, {req_id_pid, ReqId}), do_reply(State, From, StreamTo, ReqId, Resp_format, {error, Err}) end, ReqList), lists:foreach(