瀏覽代碼

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 10 年之前
父節點
當前提交
2cb1144187
共有 3 個文件被更改,包括 18 次插入16 次删除
  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 查看文件

@ -20,5 +20,7 @@
-define(CONNECTIONS_LOCAL_TABLE, ibrowse_lb). -define(CONNECTIONS_LOCAL_TABLE, ibrowse_lb).
-define(LOAD_BALANCER_NAMED_TABLE, ibrowse_lb). -define(LOAD_BALANCER_NAMED_TABLE, ibrowse_lb).
-define(CONF_TABLE, ibrowse_conf).
-define(STREAM_TABLE, ibrowse_stream).
-endif. -endif.

+ 13
- 13
src/ibrowse.erl 查看文件

@ -558,7 +558,7 @@ send_req_direct(Conn_pid, Url, Headers, Method, Body, Options, Timeout) ->
%% <code>stream_to</code> option %% <code>stream_to</code> option
%% @spec stream_next(Req_id :: req_id()) -> ok | {error, unknown_req_id} %% @spec stream_next(Req_id :: req_id()) -> ok | {error, unknown_req_id}
stream_next(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}; {error, unknown_req_id};
[{_, Pid}] -> [{_, Pid}] ->
@ -573,7 +573,7 @@ stream_next(Req_id) ->
%% error returned. %% error returned.
%% @spec stream_close(Req_id :: req_id()) -> ok | {error, unknown_req_id} %% @spec stream_close(Req_id :: req_id()) -> ok | {error, unknown_req_id}
stream_close(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}; {error, unknown_req_id};
[{_, Pid}] -> [{_, Pid}] ->
@ -747,8 +747,8 @@ init(_) ->
put(my_trace_flag, State#state.trace), put(my_trace_flag, State#state.trace),
put(ibrowse_trace_token, "ibrowse"), put(ibrowse_trace_token, "ibrowse"),
?LOAD_BALANCER_NAMED_TABLE = ets:new(?LOAD_BALANCER_NAMED_TABLE, [named_table, public, {keypos, 2}]), ?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(), import_config(),
{ok, #state{}}. {ok, #state{}}.
@ -770,7 +770,7 @@ import_config(Filename) ->
end. end.
apply_config(Terms) -> apply_config(Terms) ->
ets:delete_all_objects(ibrowse_conf),
ets:delete_all_objects(?CONF_TABLE),
insert_config(Terms). insert_config(Terms).
insert_config(Terms) -> insert_config(Terms) ->
@ -783,12 +783,12 @@ insert_config(Terms) ->
{{options, Host, Port}, Options}], {{options, Host, Port}, Options}],
lists:foreach( lists:foreach(
fun({X, Y}) -> fun({X, Y}) ->
ets:insert(ibrowse_conf,
ets:insert(?CONF_TABLE,
#ibrowse_conf{key = X, #ibrowse_conf{key = X,
value = Y}) value = Y})
end, I); end, I);
({K, V}) -> ({K, V}) ->
ets:insert(ibrowse_conf,
ets:insert(?CONF_TABLE,
#ibrowse_conf{key = K, #ibrowse_conf{key = K,
value = V}); value = V});
(X) -> (X) ->
@ -799,7 +799,7 @@ insert_config(Terms) ->
%% @doc Internal export %% @doc Internal export
get_config_value(Key) -> get_config_value(Key) ->
try try
[#ibrowse_conf{value = V}] = ets:lookup(ibrowse_conf, Key),
[#ibrowse_conf{value = V}] = ets:lookup(?CONF_TABLE, Key),
V V
catch catch
error:badarg -> error:badarg ->
@ -809,7 +809,7 @@ get_config_value(Key) ->
%% @doc Internal export %% @doc Internal export
get_config_value(Key, DefVal) -> get_config_value(Key, DefVal) ->
try try
case ets:lookup(ibrowse_conf, Key) of
case ets:lookup(?CONF_TABLE, Key) of
[] -> [] ->
DefVal; DefVal;
[#ibrowse_conf{value = V}] -> [#ibrowse_conf{value = V}] ->
@ -821,7 +821,7 @@ get_config_value(Key, DefVal) ->
end. end.
set_config_value(Key, Val) -> 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 %% Function: handle_call/3
%% Description: Handling call messages %% Description: Handling call messages
@ -888,7 +888,7 @@ handle_cast(_Msg, State) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
handle_info(all_trace_off, State) -> handle_info(all_trace_off, State) ->
Mspec = [{{ibrowse_conf,{trace,'$1','$2'},true},[],[{{'$1','$2'}}]}], 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}, _) -> Fun = fun(#lb_pid{host_port = {H, P}, pid = Pid}, _) ->
case lists:member({H, P}, Trace_on_dests) of case lists:member({H, P}, Trace_on_dests) of
false -> false ->
@ -900,7 +900,7 @@ handle_info(all_trace_off, State) ->
Acc Acc
end, end,
ets:foldl(Fun, undefined, ?LOAD_BALANCER_NAMED_TABLE), 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}; {noreply, State};
handle_info({trace, Bool}, State) -> handle_info({trace, Bool}, State) ->
@ -916,7 +916,7 @@ handle_info({trace, Bool, Host, Port}, State) ->
Acc Acc
end, end,
ets:foldl(Fun, undefined, ?LOAD_BALANCER_NAMED_TABLE), 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}), value = Bool}),
{noreply, State}; {noreply, State};

+ 3
- 3
src/ibrowse_http_client.erl 查看文件

@ -801,7 +801,7 @@ send_req_1(From,
{Caller, once} when is_pid(Caller) or {Caller, once} when is_pid(Caller) or
is_atom(Caller) -> is_atom(Caller) ->
Async_pid_rec = {{req_id_pid, ReqId}, self()}, 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}; {Caller, true};
undefined -> undefined ->
{undefined, false}; {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 %% 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 %% take a while for the req_id-pid mapping to get cleared, but it
%% should do no harm. %% 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}; State_1#state{prev_req_id = ReqId};
do_reply(State, _From, StreamTo, ReqId, Resp_format, Msg) -> do_reply(State, _From, StreamTo, ReqId, Resp_format, Msg) ->
State_1 = dec_pipeline_counter(State), 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), ReqList = queue:to_list(Reqs),
lists:foreach(fun(#request{from=From, stream_to=StreamTo, req_id=ReqId, lists:foreach(fun(#request{from=From, stream_to=StreamTo, req_id=ReqId,
response_format = Resp_format}) -> 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}) do_reply(State, From, StreamTo, ReqId, Resp_format, {error, Err})
end, ReqList), end, ReqList),
lists:foreach( lists:foreach(

Loading…
取消
儲存