You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 line
4.4 KiB

5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
  1. %% beam cache 模块名
  2. -define(agBeamPool, agBeamPool).
  3. -define(agBeamAgency, agBeamAgency).
  4. %% 默认值定义
  5. -define(DEFAULT_BASE_URL, <<"http://127.0.0.1:8529">>).
  6. -define(USER_PASSWORD, <<"root:156736">>).
  7. -define(DEFAULT_BACKLOG_SIZE, 1024).
  8. -define(DEFAULT_INIT_OPTS, undefined).
  9. -define(DEFAULT_CONNECT_TIMEOUT, 5000).
  10. -define(DEFAULT_POOL_SIZE, 16).
  11. -define(DEFAULT_POOL_STRATEGY, random).
  12. -define(DEFAULT_POOL_OPTIONS, []).
  13. -define(DEFAULT_IS_RECONNECT, true).
  14. -define(DEFAULT_RECONNECT_MAX, 120000).
  15. -define(DEFAULT_RECONNECT_MIN, 500).
  16. -define(DEFAULT_TIMEOUT, 5000).
  17. -define(DEFAULT_BODY, undefined).
  18. -define(DEFAULT_HEADERS, []).
  19. -define(DEFAULT_PID, self()).
  20. -define(DEFAULT_PROTOCOL, tcp).
  21. -define(DEFAULT_PORTO(Protocol), 8529).
  22. %%-define(DEFAULT_PORTO(Protocol), case Protocol of tcp -> 80; _ -> 443 end).
  23. -define(DEFAULT_SOCKET_OPTS, [binary, {active, true}, {delay_send, true}, {nodelay, true}, {keepalive, true}, {recbuf, 1048576}, {send_timeout, 5000}, {send_timeout_close, true}]).
  24. -define(GET_FROM_LIST(Key, List), agMiscUtils:getListValue(Key, List, undefined)).
  25. -define(GET_FROM_LIST(Key, List, Default), agMiscUtils:getListValue(Key, List, Default)).
  26. -define(WARN(Tag, Format, Data), agMiscUtils:warnMsg(Tag, Format, Data)).
  27. -define(miDoNetConnect, miDoNetConnect).
  28. -record(miAgHttpCliRet, {
  29. requestId :: requestId(),
  30. reply :: term()
  31. }).
  32. -record(request, {
  33. requestId :: requestId(),
  34. pid :: pid() | undefined,
  35. timeout :: timeout(),
  36. timestamp :: erlang:timestamp()
  37. }).
  38. -record(requestRet1, {
  39. state :: body | done,
  40. body :: undefined | binary(),
  41. contentLength :: undefined | non_neg_integer() | chunked,
  42. headers :: undefined | [binary()],
  43. reason :: undefined | binary(),
  44. statusCode :: undefined | 100..505
  45. }).
  46. -record(recvState, {
  47. statusCode :: undefined | 100..505,
  48. reason :: undefined | binary(),
  49. headers :: undefined | [binary()],
  50. contentLength :: undefined | non_neg_integer() | chunked,
  51. stage = header :: header | body | done, %% 一个请求收到tcp可能会有多个包 最多分三个阶接收
  52. body :: undefined | binary()
  53. }).
  54. -record(httpParam, {
  55. headers = [] :: [binary()],
  56. body = undefined :: undefined | binary(),
  57. pid = self() :: pid(),
  58. timeout = 1000 :: non_neg_integer()
  59. }).
  60. -record(reconnectState, {
  61. min :: non_neg_integer(),
  62. max :: non_neg_integer() | infinity,
  63. current :: non_neg_integer() | undefined
  64. }).
  65. -record(cliState, {
  66. binPatterns :: tuple(),
  67. requestsIn = 1 :: non_neg_integer(),
  68. requestsOut = 0 :: non_neg_integer(),
  69. status = leisure :: waiting | leisure,
  70. backlogNum = 0 :: integer(),
  71. backlogSize = 0 :: integer(),
  72. curInfo = undefined :: tuple(),
  73. recvState :: recvState() | undefined
  74. }).
  75. -record(poolOpts, {
  76. host :: host(),
  77. port :: 0..65535,
  78. hostname :: string(),
  79. protocol :: protocol(),
  80. poolSize ::binary(),
  81. userPassword :: binary()
  82. }).
  83. -record(binPatterns, {
  84. rn :: binary:cp(),
  85. rnrn :: binary:cp()
  86. }).
  87. -type binPatterns() :: #binPatterns {}.
  88. -type miAgHttpCliRet() :: #miAgHttpCliRet{}.
  89. -type request() :: #request{}.
  90. -type recvState() :: #recvState{}.
  91. -type httpParam() :: #httpParam{}.
  92. -type cliState() :: #cliState{}.
  93. -type reconnectState() :: #reconnectState{}.
  94. -type poolName() :: atom().
  95. -type serverName() :: atom().
  96. -type protocol() :: ssl | tcp.
  97. -type method() :: binary().
  98. -type headers() :: [{iodata(), iodata()}].
  99. -type body() :: iodata() | undefined.
  100. -type path() :: binary().
  101. -type host() :: binary().
  102. -type poolSize() :: pos_integer().
  103. -type backlogSize() :: pos_integer() | infinity.
  104. -type requestId() :: {serverName(), reference()}.
  105. -type externalRequestId() :: term().
  106. -type response() :: {externalRequestId(), term()}.
  107. -type socket() :: inet:socket() | ssl:sslsocket().
  108. -type error() :: {error, term()}.
  109. -type poolCfg() ::
  110. {baseUrl, binary()} |
  111. {user, binary()} |
  112. {password, binary()} |
  113. {poolSize, poolSize()}.
  114. -type agencyOpt() ::
  115. {reconnect, boolean()} |
  116. {backlogSize, backlogSize()} |
  117. {reconnectTimeMin, pos_integer()} |
  118. {reconnectTimeMax, pos_integer()} |
  119. {socketOpts, [gen_tcp:connect_option(), ...]}.
  120. -type poolCfgs() :: [poolCfg()].
  121. -type poolOpts() :: #poolOpts{}.
  122. -type agencyOpts() :: [agencyOpt()].
  123. -record(dbUrl, {
  124. host :: host(),
  125. path :: path(),
  126. port :: 0..65535,
  127. hostname :: string(),
  128. protocol :: protocol(),
  129. poolName :: atom() %% 请求该URL用到的poolName
  130. }).
  131. -type dbUrl() :: #dbUrl{}.