\u521b\u5efaRecord<\/strong><\/div>\nRecord\u901a\u8fc7\u4f7f\u7528#\u7b26\u53f7\u6765\u521b\u5efa\uff0c\u4e0b\u9762\u662f\u521b\u5efaserver_opts\u8fd9\u4e2aRecord\u7684\u5b9e\u4f8b\u7684\u5408\u6cd5\u65b9\u5f0f\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\nOpts1 = #server_opts{port=80}. \r\n<\/pre>\n\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aserver_opts Record\uff0cport\u8bbe\u7f6e\u4e3a80\uff0c\u5176\u4ed6field\u4f7f\u7528\u9ed8\u8ba4\u503c<\/p>\n
\r\nOpts2 = #server_opts{port=80, ip=\"192.168.0.1\"}. \r\n<\/pre>\n\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aserver_opts Record\uff0c\u4f46\u662fip\u8bbe\u7f6e\u4e3a\"192.168.0.1\"<\/p>\n
\u7b80\u800c\u8a00\u4e4b\uff0c\u5f53\u521b\u5efa\u4e00\u4e2aRecord\u65f6\uff0c\u4f60\u53ef\u4ee5\u5305\u542b\u4efb\u4f55field\uff0c\u7701\u7565\u7684field\u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c<\/p>\n
\u8bbf\u95eeRecord<\/strong><\/div>\nRecord\u7684\u8bbf\u95ee\u65b9\u5f0f\u5f88\u7b28\u62d9\uff0c\u5982\u679c\u6211\u60f3\u8bbf\u95eeport\u8fd9\u4e2afield\uff0c\u6211\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\nOpts = #server_opts{port=80, ip=\"192.168.0.1\"}, \r\nOpts#server_opts.port \r\n<\/pre>\n\u6bcf\u6b21\u4f60\u60f3\u8bbf\u95ee\u4e00\u4e2aRecord\u65f6\u4f60\u90fd\u5fc5\u987b\u5305\u542bRecord\u7684\u540d\u5b57\uff0c\u4e3a\u4ec0\u4e48\u8981\u8fd9\u6837\uff1f
\n\u56e0\u4e3aRecord\u4e0d\u662f\u771f\u6b63\u7684\u5185\u90e8\u6570\u636e\u7c7b\u578b\uff0c\u5b83\u53ea\u662f\u7f16\u8bd1\u5668\u7684\u5c0f\u628a\u620f\u3002
\n\u5728\u5185\u90e8\uff0cRecord\u662fTuple\uff0c\u5982\u4e0b\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\n{server_opts, 80, \"127.0.0.1\", 10} \r\n<\/pre>\n\u7f16\u8bd1\u5668\u5c06Record\u7684\u540d\u5b57\u6620\u5c04\u5230Tuple\u91cc\u9762
\nErlang\u865a\u62df\u673a\u8bb0\u5f55\u4e86Record\u7684\u5b9a\u4e49\uff0c\u800c\u7f16\u8bd1\u5668\u5c06\u6240\u6709\u7684Record\u903b\u8f91\u7ffb\u8bd1\u4e3aTuple\u903b\u8f91
\n\u56e0\u6b64\uff0c\u6839\u672c\u5c31\u6ca1\u6709Record\u7c7b\u578b\uff0c\u6240\u4ee5\u6bcf\u6b21\u4f60\u8bbf\u95ee\u4e00\u4e2aRecord\u65f6\u4f60\u5fc5\u987b\u544a\u8bc9Erlang\u6211\u4eec\u5728\u7528\u54ea\u4e2aRecord\uff08\u4e3a\u4e86\u7f16\u8bd1\u5668\u723d\uff0c\u7a0b\u5e8f\u5458\u53d8\u7684\u5f88\u4e0d\u723d\uff09<\/p>\n
\u66f4\u65b0Record<\/strong><\/div>\n\u66f4\u65b0Record\u548c\u521b\u5efaRecord\u5f88\u7c7b\u4f3c\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\nOpts = #server_opts{port=80, ip=\"192.168.0.1\"}, \r\nNewOpts = Opts#server_opts{port=7000}. \r\n<\/pre>\n\u8fd9\u91cc\u9996\u5148\u521b\u5efa\u4e00\u4e2aserver_opts Record
\nNewOpts = Opts#{port=7000}\u521b\u5efa\u4e86\u4e00\u4e2aOpts\u7684\u526f\u672c\uff0c\u5e76\u6307\u5b9aport\u4e3a7000\u5e76\u7ed1\u5b9a\u5230NewOpts<\/p>\n
\u5339\u914dRecord\u548cGuard\u8bed\u53e5<\/strong><\/div>\n\u4e0d\u8c08\u6a21\u5f0f\u5339\u914d\u5c31\u4e0d\u7b97Erlang
\n\u8ba9\u6211\u4eec\u6765\u770b\u770b\u4e00\u4e2a\u4f8b\u5b50\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\nhandle(Opts=#server_opts{port=8000}) -> \r\n % do special port 8080 stuff \r\nhandle(Opts=#server_opts{} -> \r\n % default stuff \r\n<\/pre>\nGuard\u8bed\u53e5\u548c\u4e0a\u9762\u7684\u7c7b\u4f3c\uff0c\u4f8b\u5982\u7ed1\u5b9a\u5c0f\u4e8e1024\u7684\u7aef\u53e3\u901a\u5e38\u9700\u8981root\u6743\u9650\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a
\n\u590d\u5236\u4ee3\u7801\u4ee3\u7801\u5982\u4e0b:<\/p>\n
\r\nhandle(Opts) when Opts#server_opts.port <= 1024 -> \r\n % requires root access \r\nhandle(Opts=#server_opts{}) -> \r\n % Doesn't require root access \r\n<\/pre>\n<\/strong><\/div>\n\u4f7f\u7528Record[\/yiji[<\/p>\n
\u5728\u6211\u4f7f\u7528Erlang\u7684\u6709\u9650\u7684\u65f6\u95f4\u91cc\uff0c\u6211\u53d1\u73b0Record\u4e3b\u8981\u7528\u5728\u4e24\u79cd\u573a\u666f.\u9996\u5148\uff0cRecord\u7528\u6765\u4fdd\u5b58\u72b6\u6001\uff0c\u7279\u522b\u662f\u5728\u4f7f\u7528gen_server\u7684behaviour\u65f6\uff0c\u7531\u4e8eErlang\u4e0d\u80fd\u5168\u5c40\u4fdd\u6301\u72b6\u6001\uff0c\u6240\u4ee5\u72b6\u6001\u5fc5\u987b\u5728\u65b9\u6cd5\u4e4b\u524d\u4f20\u6765\u4f20\u53bb\u3002\u7136\u540e\uff0cRecord\u53ef\u4ee5\u7528\u6765\u4fdd\u5b58\u914d\u7f6e\u9009\u9879\uff0c\u8fd9\u53ef\u4ee5\u8ba4\u4e3a\u662f\u7b2c\u4e00\u70b9\u7684\u5b50\u96c6\u3002\u5c3d\u7ba1\u5982\u6b64\uff0cRecord\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\uff0c\u6700\u660e\u663e\u7684\u662f\u4e0d\u80fd\u5728\u8fd0\u884c\u65f6\u6dfb\u52a0\u548c\u5220\u9664field\uff0c\u8fd9\u548cC\u7684struct\u4e00\u6837\uff0cRecord\u7684\u7ed3\u6784\u5fc5\u987b\u9884\u5148\u5b9a\u4e49\uff0c\u5982\u679c\u4f60\u60f3\u5728\u8fd0\u884c\u65f6\u6dfb\u52a0\u548c\u5220\u9664field\uff0c\u6216\u8005\u4f60\u5728\u8fd0\u884c\u65f6\u624d\u80fd\u786e\u5b9a\u6709\u54ea\u4e9bfield\uff0c\u8fd9\u65f6\u4f60\u5e94\u8be5\u4f7f\u7528dict\u800c\u4e0d\u662fRecord\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728Erlang\u5185\u90e8\u53ea\u6709\u4e24\u79cd\u6df7\u5408\u7684\u6570\u636e\u7c7b\u578b\uff1aList\u548cTuple\uff0c\u800c\u8fd9\u4e24\u79cd\u90fd\u4e0d\u652f\u6301\u547d\u540d\u8bbf\u95ee\uff0c\u6240\u4ee5\u5982\u679c\u6ca1\u6709\u989d\u5916\u7684\u5e93 […]<\/p>\n","protected":false},"author":1903,"featured_media":239440,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-239438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=239438"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239438\/revisions"}],"predecessor-version":[{"id":239439,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239438\/revisions\/239439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/239440"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=239438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=239438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=239438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}