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.

196 lines
5.3 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 година
пре 5 година
пре 5 година
пре 5 година
  1. %% beam cache 模块名
  2. -define(agBeamPool, agBeamPool).
  3. -define(agBeamAgency, agBeamAgency).
  4. %% 默认值定义
  5. -define(DEFAULT_BASE_URL, <<"http://120.77.213.39:8529">>).
  6. -define(DEFAULT_DBNAME, <<"_db/_system">>).
  7. -define(USER_PASSWORD, <<"root:156736">>).
  8. -define(DEFAULT_BACKLOG_SIZE, 1024).
  9. -define(DEFAULT_INIT_OPTS, undefined).
  10. -define(DEFAULT_CONNECT_TIMEOUT, 5000).
  11. -define(DEFAULT_POOL_SIZE, 16).
  12. -define(DEFAULT_POOL_STRATEGY, random).
  13. -define(DEFAULT_POOL_OPTIONS, []).
  14. -define(DEFAULT_IS_RECONNECT, true).
  15. -define(DEFAULT_RECONNECT_MAX, 120000).
  16. -define(DEFAULT_RECONNECT_MIN, 500).
  17. -define(DEFAULT_TIMEOUT, infinity).
  18. -define(DEFAULT_BODY, undefined).
  19. -define(DEFAULT_HEADERS, []).
  20. -define(DEFAULT_PID, self()).
  21. -define(DEFAULT_PROTOCOL, tcp).
  22. -define(DEFAULT_PORTO(Protocol), 8529).
  23. %%-define(DEFAULT_PORTO(Protocol), case Protocol of tcp -> 80; _ -> 443 end).
  24. -define(DEFAULT_SOCKET_OPTS, [binary, {active, true}, {delay_send, true}, {nodelay, true}, {keepalive, true}, {recbuf, 1048576}, {send_timeout, 5000}, {send_timeout_close, true}]).
  25. -define(GET_FROM_LIST(Key, List), agMiscUtils:getListValue(Key, List, undefined)).
  26. -define(GET_FROM_LIST(Key, List, Default), agMiscUtils:getListValue(Key, List, Default)).
  27. -define(WARN(Tag, Format, Data), agMiscUtils:warnMsg(Tag, Format, Data)).
  28. -define(miDoNetConnect, miDoNetConnect).
  29. -record(miRequest, {
  30. method :: method()
  31. , path :: path()
  32. , headers :: headers()
  33. , body :: body()
  34. , requestId :: tuple()
  35. , fromPid :: pid()
  36. , overTime = infinity :: timeout()
  37. , isSystem = false :: boolean()
  38. }).
  39. -record(miAgHttpCliRet, {
  40. requestId :: requestId(),
  41. reply :: term()
  42. }).
  43. -record(requestRet, {
  44. statusCode :: undefined | 100..505,
  45. contentLength :: undefined | non_neg_integer() | chunked,
  46. body :: undefined | binary()
  47. }).
  48. -record(recvState, {
  49. stage = header :: header | body | done, %% 一个请求收到tcp可能会有多个包 最多分三个阶接收
  50. contentLength :: undefined | non_neg_integer() | chunked,
  51. statusCode :: undefined | 100..505,
  52. headers :: undefined | [binary()],
  53. buffer = <<>> :: binary(),
  54. body = <<>> :: binary()
  55. }).
  56. -record(reconnectState, {
  57. min :: non_neg_integer(),
  58. max :: non_neg_integer() | infinity,
  59. current :: non_neg_integer() | undefined
  60. }).
  61. -record(cliState, {
  62. requestsIn = 1 :: non_neg_integer(),
  63. requestsOut = 0 :: non_neg_integer(),
  64. status = leisure :: waiting | leisure,
  65. backlogNum = 0 :: integer(),
  66. backlogSize = 0 :: integer(),
  67. curInfo = undefined :: tuple(),
  68. recvState :: recvState() | undefined
  69. }).
  70. -record(dbOpts, {
  71. host :: host(),
  72. port :: 0..65535,
  73. hostname :: string(),
  74. dbName :: binary(),
  75. protocol :: protocol(),
  76. poolSize :: binary(),
  77. userPassword :: binary(),
  78. socketOpts :: [gen_tcp:connect_option(), ...]
  79. }).
  80. -record(agencyOpts, {
  81. reconnect :: boolean(),
  82. backlogSize :: backlogSize(),
  83. reconnectTimeMin :: pos_integer(),
  84. reconnectTimeMax :: pos_integer()
  85. }).
  86. -type miRequest() :: #miRequest{}.
  87. -type miAgHttpCliRet() :: #miAgHttpCliRet{}.
  88. -type requestRet() :: #requestRet{}.
  89. -type recvState() :: #recvState{}.
  90. -type cliState() :: #cliState{}.
  91. -type reconnectState() :: #reconnectState{}.
  92. -type poolName() :: atom().
  93. -type poolNameOrSocket() :: atom() | socket().
  94. -type serverName() :: atom().
  95. -type protocol() :: ssl | tcp.
  96. -type method() :: binary().
  97. -type headers() :: [{iodata(), iodata()}].
  98. -type body() :: iodata() | undefined.
  99. -type path() :: binary().
  100. -type host() :: binary().
  101. -type poolSize() :: pos_integer().
  102. -type backlogSize() :: pos_integer() | infinity.
  103. -type requestId() :: {serverName(), reference()}.
  104. -type externalRequestId() :: term().
  105. -type response() :: {externalRequestId(), term()}.
  106. -type socket() :: inet:socket() | ssl:sslsocket().
  107. -type error() :: {error, term()}.
  108. -type dbCfg() ::
  109. {baseUrl, binary()} |
  110. {dbName, binary()} |
  111. {userPassword, binary()} |
  112. {poolSize, poolSize()} |
  113. {socketOpts, [gen_tcp:connect_option(), ...]}.
  114. -type agencyCfg() ::
  115. {reconnect, boolean()} |
  116. {backlogSize, backlogSize()} |
  117. {reconnectTimeMin, pos_integer()} |
  118. {reconnectTimeMax, pos_integer()}.
  119. -type dbCfgs() :: [dbCfg()].
  120. -type dbOpts() :: #dbOpts{}.
  121. -type agencyCfgs() :: [agencyCfg()].
  122. -type agencyOpts() :: #agencyOpts{}.
  123. %% http header 头
  124. %% -type header() ::
  125. %% 'Cache-Control' |
  126. %% 'Connection' |
  127. %% 'Date' |
  128. %% 'Pragma'|
  129. %% 'Transfer-Encoding' |
  130. %% 'Upgrade' |
  131. %% 'Via' |
  132. %% 'Accept' |
  133. %% 'Accept-Charset'|
  134. %% 'Accept-Encoding' |
  135. %% 'Accept-Language' |
  136. %% 'Authorization' |
  137. %% 'From' |
  138. %% 'Host' |
  139. %% 'If-Modified-Since' |
  140. %% 'If-Match' |
  141. %% 'If-None-Match' |
  142. %% 'If-Range'|
  143. %% 'If-Unmodified-Since' |
  144. %% 'Max-Forwards' |
  145. %% 'Proxy-Authorization' |
  146. %% 'Range'|
  147. %% 'Referer' |
  148. %% 'User-Agent' |
  149. %% 'Age' |
  150. %% 'Location' |
  151. %% 'Proxy-Authenticate'|
  152. %% 'Public' |
  153. %% 'Retry-After' |
  154. %% 'Server' |
  155. %% 'Vary' |
  156. %% 'Warning'|
  157. %% 'Www-Authenticate' |
  158. %% 'Allow' |
  159. %% 'Content-Base' |
  160. %% 'Content-Encoding'|
  161. %% 'Content-Language' |
  162. %% 'Content-Length' |
  163. %% 'Content-Location'|
  164. %% 'Content-Md5' |
  165. %% 'Content-Range' |
  166. %% 'Content-Type' |
  167. %% 'Etag'|
  168. %% 'Expires' |
  169. %% 'Last-Modified' |
  170. %% 'Accept-Ranges' |
  171. %% 'Set-Cookie'|
  172. %% 'Set-Cookie2' |
  173. %% 'X-Forwarded-For' |
  174. %% 'Cookie' |
  175. %% 'Keep-Alive' |
  176. %% 'Proxy-Connection' |
  177. %% binary() |
  178. %% string().