Procházet zdrojové kódy

代码修改

erlArango_v1
lijie před 5 roky
rodič
revize
4eb1be6db0
6 změnil soubory, kde provedl 26 přidání a 42 odebrání
  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 Zobrazit soubor

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

+ 2
- 0
rebar.config Zobrazit soubor

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

+ 1
- 1
src/httpCli/agAgencyUtils.erl Zobrazit soubor

@ -38,7 +38,7 @@ agencyReply({PidForm, RequestId, TimerRef}, Reply) ->
catch PidForm ! #miAgHttpCliRet{requestId = RequestId, reply = Reply}, catch PidForm ! #miAgHttpCliRet{requestId = RequestId, reply = Reply},
ok; ok;
agencyReply(undefined, RequestRet) -> 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. ok.
-spec agencyReply(undefined | pid(), requestId(), undefined | reference(), term()) -> ok. -spec agencyReply(undefined | pid(), requestId(), undefined | reference(), term()) -> ok.

+ 4
- 4
src/httpCli/agHttpProtocol.erl Zobrazit soubor

@ -59,7 +59,7 @@ response(undefined, Rn, RnRn, Data) ->
BodySize == ContentLength -> BodySize == ContentLength ->
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}; {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
BodySize > ContentLength -> 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}}; {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
true -> true ->
{ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}} {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 -> BodySize == ContentLength ->
{done, RecvState#recvState{stage = done, body = CurData}}; {done, RecvState#recvState{stage = done, body = CurData}};
BodySize > ContentLength -> 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}}; {done, #recvState{stage = done, body = CurData}};
true -> true ->
{ok,RecvState#recvState{body = CurData}}
{ok, RecvState#recvState{body = CurData}}
end; end;
response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data) -> response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data) ->
CurBody = <<OldBody/binary, Data/binary>>, CurBody = <<OldBody/binary, Data/binary>>,
@ -116,7 +116,7 @@ response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data) ->
BodySize == ContentLength -> BodySize == ContentLength ->
{done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}; {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
BodySize > ContentLength -> 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}}; {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}};
true -> true ->
{ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}} {ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}

+ 13
- 30
src/httpCli/agKvsToBeam.erl Zobrazit soubor

@ -7,8 +7,9 @@
load/2 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. -spec load(term(), [{key(), value()}]) -> ok.
load(Module, KVs) -> load(Module, KVs) ->
@ -19,19 +20,18 @@ load(Module, KVs) ->
ok. ok.
forms(Module, KVs) -> 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]]. [erl_syntax:revert(X) || X <- [Mod, Export, Function]].
lookup_clause(Key, Value) -> 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]). erl_syntax:clause([Var], [], [Body]).
lookup_clause_anon() -> lookup_clause_anon() ->
@ -39,24 +39,7 @@ lookup_clause_anon() ->
Body = erl_syntax:atom(undefined), Body = erl_syntax:atom(undefined),
erl_syntax:clause([Var], [], [Body]). erl_syntax:clause([Var], [], [Body]).
lookup_clauses(KVs) ->
lookup_clauses(KVs, []).
lookup_clauses([], Acc) -> lookup_clauses([], Acc) ->
lists:reverse(lists:flatten([lookup_clause_anon() | Acc])); lists:reverse(lists:flatten([lookup_clause_anon() | Acc]));
lookup_clauses([{Key, Value} | T], 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 Zobrazit soubor

@ -8,16 +8,16 @@ tt(C, N) ->
application:start(erlArango), application:start(erlArango),
agHttpCli:startPool(tt, [{poolSize, 100}], []), agHttpCli:startPool(tt, [{poolSize, 100}], []),
Request = {<<"GET">>, <<"/_api/database/current">>, [], []}, 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)]. [spawn(test, test, [N, Request]) || _Idx <- lists:seq(1, C)].
%%test(N, Request).
%%test(N, Request).
%% /_api/database %% /_api/database
test(0, Request) -> test(0, Request) ->
R1 = {<<"GET">>, <<"/_api/database">>, [], []}, R1 = {<<"GET">>, <<"/_api/database">>, [], []},
agHttpCli:callAgency(tt, R1, 5000), 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) -> test(N, Request) ->
erlang:put(cnt, N), erlang:put(cnt, N),
agHttpCli:callAgency(tt, Request, 5000), agHttpCli:callAgency(tt, Request, 5000),

Načítá se…
Zrušit
Uložit