浏览代码

代码修改

erlArango_v1
lijie 5 年前
父节点
当前提交
4eb1be6db0
共有 6 个文件被更改,包括 26 次插入42 次删除
  1. +3
    -4
      include/agHttpCli.hrl
  2. +2
    -0
      rebar.config
  3. +1
    -1
      src/httpCli/agAgencyUtils.erl
  4. +4
    -4
      src/httpCli/agHttpProtocol.erl
  5. +13
    -30
      src/httpCli/agKvsToBeam.erl
  6. +3
    -3
      src/httpCli/test.erl

+ 3
- 4
include/agHttpCli.hrl 查看文件

@ -14,7 +14,7 @@
-define(DEFAULT_IS_RECONNECT, true).
-define(DEFAULT_RECONNECT_MAX, 120000).
-define(DEFAULT_RECONNECT_MIN, 500).
-define(DEFAULT_TIMEOUT, 5000).
-define(DEFAULT_TIMEOUT, infinity).
-define(DEFAULT_BODY, undefined).
-define(DEFAULT_HEADERS, []).
-define(DEFAULT_PID, self()).
@ -49,10 +49,9 @@
}).
-record(recvState, {
stage = header :: header | body | done, %% tcp可能会有多个包
stage = header :: header | body | done, %% tcp可能会有多个包
contentLength :: undefined | non_neg_integer() | chunked,
statusCode :: undefined | 100..505,
reason :: undefined | binary(),
headers :: undefined | [binary()],
buffer = <<>> :: binary(),
body = <<>> :: binary()
@ -86,7 +85,7 @@
port :: 0..65535,
hostname :: string(),
protocol :: protocol(),
poolSize :: binary(),
poolSize :: binary(),
userPassword :: binary()
}).

+ 2
- 0
rebar.config 查看文件

@ -1 +1,3 @@
{erl_opts, [{i, "include"}]}.
{edoc_opts, [{preprocess, true}]}.

+ 1
- 1
src/httpCli/agAgencyUtils.erl 查看文件

@ -38,7 +38,7 @@ agencyReply({PidForm, RequestId, TimerRef}, Reply) ->
catch PidForm ! #miAgHttpCliRet{requestId = RequestId, reply = Reply},
ok;
agencyReply(undefined, RequestRet) ->
?WARN(not_curInfo ,"not find curInfo ret is:~p~n ",[RequestRet]),
?WARN(not_curInfo, "not find curInfo ret is:~p~n ", [RequestRet]),
ok.
-spec agencyReply(undefined | pid(), requestId(), undefined | reference(), term()) -> ok.

+ 4
- 4
src/httpCli/agHttpProtocol.erl 查看文件

@ -59,7 +59,7 @@ response(undefined, Rn, RnRn, Data) ->
BodySize == ContentLength ->
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
BodySize > ContentLength ->
?WARN(agTcpAgencyIns, "11 contentLength get to long data why? more: ~p ~n",[BodySize - ContentLength]),
?WARN(agTcpAgencyIns, "11 contentLength get to long data why? more: ~p ~n", [BodySize - ContentLength]),
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
true ->
{ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}
@ -93,10 +93,10 @@ response(#recvState{stage = body, contentLength = ContentLength, body = Body} =
BodySize == ContentLength ->
{done, RecvState#recvState{stage = done, body = CurData}};
BodySize > ContentLength ->
?WARN(agTcpAgencyIns, "22 contentLength get to long data why? more: ~p ~n",[BodySize - ContentLength]),
?WARN(agTcpAgencyIns, "22 contentLength get to long data why? more: ~p ~n", [BodySize - ContentLength]),
{done, #recvState{stage = done, body = CurData}};
true ->
{ok,RecvState#recvState{body = CurData}}
{ok, RecvState#recvState{body = CurData}}
end;
response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data) ->
CurBody = <<OldBody/binary, Data/binary>>,
@ -116,7 +116,7 @@ response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data) ->
BodySize == ContentLength ->
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
BodySize > ContentLength ->
?WARN(agTcpAgencyIns, "33 contentLength get to long data why? more: ~p ~n",[BodySize - ContentLength]),
?WARN(agTcpAgencyIns, "33 contentLength get to long data why? more: ~p ~n", [BodySize - ContentLength]),
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
true ->
{ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}

+ 13
- 30
src/httpCli/agKvsToBeam.erl 查看文件

@ -7,8 +7,9 @@
load/2
]).
-type key() :: atom() | binary() | float() | integer() | list() | tuple().
-type value() :: atom() | binary() | float() | integer() | list() | tuple().
%% map类型的数据不能当做key
-type key() :: atom() | binary() | bitstring() | float() | integer() | list() | tuple().
-type value() :: atom() | binary() | bitstring() | float() | integer() | list() | tuple() | map().
-spec load(term(), [{key(), value()}]) -> ok.
load(Module, KVs) ->
@ -19,19 +20,18 @@ load(Module, KVs) ->
ok.
forms(Module, KVs) ->
Mod = erl_syntax:attribute(erl_syntax:atom(module),
[erl_syntax:atom(Module)]),
ExportList = [erl_syntax:arity_qualifier(erl_syntax:atom(get),
erl_syntax:integer(1))],
Export = erl_syntax:attribute(erl_syntax:atom(export),
[erl_syntax:list(ExportList)]),
Function = erl_syntax:function(erl_syntax:atom(get),
lookup_clauses(KVs)),
%% -module(Module).
Mod = erl_syntax:attribute(erl_syntax:atom(module), [erl_syntax:atom(Module)]),
%% -export([get/0]).
ExportList = [erl_syntax:arity_qualifier(erl_syntax:atom(get), erl_syntax:integer(1))],
Export = erl_syntax:attribute(erl_syntax:atom(export), [erl_syntax:list(ExportList)]),
%% get(K) -> V
Function = erl_syntax:function(erl_syntax:atom(get), lookup_clauses(KVs, [])),
[erl_syntax:revert(X) || X <- [Mod, Export, Function]].
lookup_clause(Key, Value) ->
Var = to_syntax(Key),
Body = to_syntax(Value),
Var = erl_syntax:abstract(Key),
Body = erl_syntax:abstract(Value),
erl_syntax:clause([Var], [], [Body]).
lookup_clause_anon() ->
@ -39,24 +39,7 @@ lookup_clause_anon() ->
Body = erl_syntax:atom(undefined),
erl_syntax:clause([Var], [], [Body]).
lookup_clauses(KVs) ->
lookup_clauses(KVs, []).
lookup_clauses([], Acc) ->
lists:reverse(lists:flatten([lookup_clause_anon() | Acc]));
lookup_clauses([{Key, Value} | T], Acc) ->
lookup_clauses(T, [lookup_clause(Key, Value) | Acc]).
to_syntax(Atom) when is_atom(Atom) ->
erl_syntax:atom(Atom);
to_syntax(Binary) when is_binary(Binary) ->
String = erl_syntax:string(binary_to_list(Binary)),
erl_syntax:binary([erl_syntax:binary_field(String)]);
to_syntax(Float) when is_float(Float) ->
erl_syntax:float(Float);
to_syntax(Integer) when is_integer(Integer) ->
erl_syntax:integer(Integer);
to_syntax(List) when is_list(List) ->
erl_syntax:list([to_syntax(X) || X <- List]);
to_syntax(Tuple) when is_tuple(Tuple) ->
erl_syntax:tuple([to_syntax(X) || X <- tuple_to_list(Tuple)]).
lookup_clauses(T, [lookup_clause(Key, Value) | Acc]).

+ 3
- 3
src/httpCli/test.erl 查看文件

@ -8,16 +8,16 @@ tt(C, N) ->
application:start(erlArango),
agHttpCli:startPool(tt, [{poolSize, 100}], []),
Request = {<<"GET">>, <<"/_api/database/current">>, [], []},
io:format("IMY********************** start time ~p~n",[erlang:system_time(millisecond)]),
io:format("IMY********************** start time ~p~n", [erlang:system_time(millisecond)]),
[spawn(test, test, [N, Request]) || _Idx <- lists:seq(1, C)].
%%test(N, Request).
%%test(N, Request).
%% /_api/database
test(0, Request) ->
R1 = {<<"GET">>, <<"/_api/database">>, [], []},
agHttpCli:callAgency(tt, R1, 5000),
io:format("IMY********************** test over ~p~n",[erlang:system_time(millisecond)]);
io:format("IMY********************** test over ~p~n", [erlang:system_time(millisecond)]);
test(N, Request) ->
erlang:put(cnt, N),
agHttpCli:callAgency(tt, Request, 5000),

正在加载...
取消
保存