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.

205 lines
5.6 KiB

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