Pārlūkot izejas kodu

Aliased remaining production ets table names

For consistency, added macro aliases for remaining
ets table names to be found all in one place.
pull/123/head
benjaminplee pirms 10 gadiem
vecāks
revīzija
2cb1144187
3 mainītis faili ar 18 papildinājumiem un 16 dzēšanām
  1. +2
    -0
      include/ibrowse.hrl
  2. +13
    -13
      src/ibrowse.erl
  3. +3
    -3
      src/ibrowse_http_client.erl

+ 2
- 0
include/ibrowse.hrl Parādīt failu

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

+ 13
- 13
src/ibrowse.erl Parādīt failu

@ -558,7 +558,7 @@ send_req_direct(Conn_pid, Url, Headers, Method, Body, Options, Timeout) ->
%% <code>stream_to</code> 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};

+ 3
- 3
src/ibrowse_http_client.erl Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt