{"id":38299,"date":"2025-05-20T07:26:28","date_gmt":"2025-05-19T23:26:28","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38299.html"},"modified":"2025-05-20T07:26:28","modified_gmt":"2025-05-19T23:26:28","slug":"%e6%96%bd%e7%a3%8a%e8%80%81%e5%b8%88%e5%9f%ba%e4%ba%8emuduo%e7%bd%91%e7%bb%9c%e5%ba%93%e7%9a%84%e9%9b%86%e7%be%a4%e8%81%8a%e5%a4%a9%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%80","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38299.html","title":{"rendered":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00)"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u6280\u672f\u6808<\/li>\n<li>\u9879\u76ee\u9700\u6c42<\/li>\n<li>\u73af\u5883\u5b89\u88c5<\/li>\n<li>\n<ul>\n<li>muduo\u7f51\u7edc\u5e93\u5b89\u88c5<\/li>\n<li>\n<ul>\n<li>\u7f16\u8bd1\u9519\u8bef:<\/li>\n<li>\u89e3\u51b3\u529e\u6cd5:<\/li>\n<li>\u79fb\u52a8\u5934\u6587\u4ef6\u548c\u5e93\u6587\u4ef6<\/li>\n<\/ul>\n<\/li>\n<li>redis\u548cmysql\u5b89\u88c5<\/li>\n<li>\u9a8c\u8bc1mysql\u73af\u5883<\/li>\n<li>\u4fee\u6539mysql\u5bc6\u7801<\/li>\n<li>Nginx&#8211;\u5148\u4e0d\u5b89\u88c5<\/li>\n<\/ul>\n<\/li>\n<li>Json\u4ecb\u7ecd<\/li>\n<li>\n<ul>\n<li>\u4e3a\u4ec0\u4e48\u9700\u8981json?<\/li>\n<li>\u4ec0\u4e48\u662f json \u5e8f\u5217\u5316?<\/li>\n<li>\u5e38\u7528\u7684\u6570\u636e\u4f20\u8f93\u5e8f\u5217\u5316\u683c\u5f0f?<\/li>\n<li>\u76f4\u63a5\u4f7f\u7528json\u7b2c\u4e09\u65b9\u5e93<\/li>\n<li>json\u5e8f\u5217\u5316\u4ee3\u7801\u6f14\u793a<\/li>\n<li>\u590d\u6742\u952e\u503c\u5bf9\u6f14\u793a<\/li>\n<li>\u5bb9\u5668\u5e8f\u5217\u5316\u6f14\u793a<\/li>\n<li>json\u53cd\u5e8f\u5217\u5316\u6f14\u793a<\/li>\n<li>\u4f7f\u7528\u603b\u7ed3<\/li>\n<\/ul>\n<\/li>\n<li>muduo\u7f51\u7edc\u5e93\u7b80\u4ecb<\/li>\n<li>\n<ul>\n<li>muduo\u7f51\u7edc\u5e93\u662f\u4ec0\u4e48?<\/li>\n<li>\u6838\u5fc3\u601d\u60f3<\/li>\n<\/ul>\n<\/li>\n<li>\u8865\u5145muduo\u7f51\u7edc\u5e93\u77e5\u8bc6<\/li>\n<li>\n<ul>\n<li>Muduo \u7684\u7ebf\u7a0b\u6a21\u578b\u6982\u89c8&#xff1a;<\/li>\n<li>\u4e3b\u7ebf\u7a0b&#xff08;EventLoop \u6240\u5728\u7ebf\u7a0b&#xff09;<\/li>\n<li>\u5de5\u4f5c\u7ebf\u7a0b&#xff08;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u7ebf\u7a0b&#xff09;<\/li>\n<li>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u8bbe\u8ba1&#xff1f;<\/li>\n<li>\u7ebf\u7a0b\u4e4b\u95f4\u5982\u4f55\u901a\u4fe1&#xff1f;<\/li>\n<\/ul>\n<\/li>\n<li>muduo\u7f51\u7edc\u5e93\u7f16\u7a0b<\/li>\n<li>\n<ul>\n<li>\u5e93\u7684\u641c\u7d22\u8def\u5f84\u95ee\u9898<\/li>\n<li>muduo\u7684\u4fbf\u5229\u6027<\/li>\n<li>\u57fa\u4e8emuduo\u7684\u670d\u52a1\u5668\u7f16\u7a0b<\/li>\n<li>\u7f16\u8bd1\u9519\u8bef\u95ee\u9898\u89e3\u51b3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u6280\u672f\u6808<\/h2>\n<li>Json\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316<\/li>\n<li>muduo\u7f51\u7edc\u5e93\u5f00\u53d1<\/li>\n<li>nginx\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\u548c\u73af\u5883\u90e8\u7f72<\/li>\n<li>nginx\u7684tcp\u8d1f\u8f7d\u5747\u8861\u5668\u914d\u7f6e<\/li>\n<li>redis\u7f13\u5b58\u670d\u52a1\u5668\u7f16\u7a0b\u5b9e\u8df5<\/li>\n<li>\u57fa\u4e8e\u53d1\u5e03-\u8ba2\u9605\u7684\u670d\u52a1\u5668\u4e2d\u95f4\u4ef6redis\u6d88\u606f\u961f\u5217\u7f16\u7a0b\u5b9e\u8df5<\/li>\n<li>MySQL\u6570\u636e\u5e93\u7f16\u7a0b<\/li>\n<li>CMake\u6784\u5efa\u7f16\u8bd1\u73af\u5883<\/li>\n<li>Github\u6258\u7ba1\u9879\u76ee<\/li>\n<h2>\u9879\u76ee\u9700\u6c42<\/h2>\n<li>\u5ba2\u6237\u7aef\u65b0\u7528\u6237\u6ce8\u518c<\/li>\n<li>\u5ba2\u6237\u7aef\u7528\u6237\u767b\u5f55<\/li>\n<li>\u6dfb\u52a0\u597d\u53cb\u548c\u6dfb\u52a0\u7fa4\u7ec4<\/li>\n<li>\u597d\u53cb\u804a\u5929<\/li>\n<li>\u7fa4\u7ec4\u804a\u5929<\/li>\n<li>\u79bb\u7ebf\u6d88\u606f<\/li>\n<li>nginx\u914d\u7f6etcp\u8d1f\u8f7d\u5747\u8861<\/li>\n<li>\u96c6\u7fa4\u804a\u5929\u7cfb\u7edf\u652f\u6301\u5ba2\u6237\u7aef\u8de8\u670d\u52a1\u5668\u901a\u4fe1<\/li>\n<h2>\u73af\u5883\u5b89\u88c5<\/h2>\n<h3>muduo\u7f51\u7edc\u5e93\u5b89\u88c5<\/h3>\n<p>\u5177\u4f53\u5b89\u88c5\u65b9\u6cd5: \u89c1\u8001\u5e08\u535a\u5ba2<\/p>\n<p>https:\/\/blog.csdn.net\/QIANGWEIYUAN\/article\/details\/89023980<\/p>\n<h4>\u7f16\u8bd1\u9519\u8bef:<\/h4>\n<p>\u4ee5\u4e0b\u7f16\u8bd1\u9519\u8bef, \u662f\u7531\u4e8e Boost \u5e93\u5728\u5934\u6587\u4ef6\u4e2d\u4f7f\u7528\u4e86 C \u98ce\u683c\u7684\u7c7b\u578b\u8f6c\u6362&#xff08;(Model*)0&#xff09;&#xff0c;\u800c\u4f60\u7684\u7f16\u8bd1\u5668\u8bbe\u7f6e\u4e86 -Werror&#061;old-style-cast&#xff0c;\u5c06\u6240\u6709\u8b66\u544a\u89c6\u4e3a\u9519\u8bef&#xff0c;\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\u3002<\/p>\n<p>\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp: In static member function \u2018static void boost::concepts::requirement&lt;Model&gt;::failed()\u2019:<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp:35:37: error: use of old-style cast to \u2018Model*\u2019 [-Werror&#061;old-style-cast]<br \/>\n   35 |     static void failed() { ((Model*)0)-&gt;~Model(); }<br \/>\n      |                                     ^<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp: In static member function \u2018static void boost::concepts::requirement&lt;boost::concepts::failed************ Model::************&gt;::failed()\u2019:<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp:50:37: error: use of old-style cast to \u2018Model*\u2019 [-Werror&#061;old-style-cast]<br \/>\n   50 |     static void failed() { ((Model*)0)-&gt;~Model(); }<br \/>\n      |                                     ^<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp: In static member function \u2018static void boost::concepts::constraint&lt;Model&gt;::failed()\u2019:<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/detail\/general.hpp:65:37: error: use of old-style cast to \u2018Model*\u2019 [-Werror&#061;old-style-cast]<br \/>\n   65 |     static void failed() { ((Model*)0)-&gt;constraints(); }<br \/>\n      |                                     ^<br \/>\nIn file included from \/root\/anaconda3\/include\/boost\/concept_check.hpp:31,<br \/>\n                 from \/root\/anaconda3\/include\/boost\/circular_buffer\/base.hpp:22,<br \/>\n                 from \/root\/anaconda3\/include\/boost\/circular_buffer.hpp:58,<br \/>\n                 from \/root\/hzhdata\/2025-bigproject\/1-chat-web\/package\/muduo\/muduo\/base\/BoundedBlockingQueue.h:12,<br \/>\n                 from \/root\/hzhdata\/2025-bigproject\/1-chat-web\/package\/muduo\/muduo\/base\/AsyncLogging.h:10,<br \/>\n                 from \/root\/hzhdata\/2025-bigproject\/1-chat-web\/package\/muduo\/muduo\/base\/AsyncLogging.cc:6:<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/usage.hpp: In destructor \u2018boost::concepts::usage_requirements&lt;Model&gt;::~usage_requirements()\u2019:<br \/>\n\/root\/anaconda3\/include\/boost\/concept\/usage.hpp:20:38: error: use of old-style cast to \u2018Model*\u2019 [-Werror&#061;old-style-cast]<br \/>\n   20 |     ~usage_requirements() { ((Model*)0)-&gt;~Model(); }<br \/>\n      |                                      ^<br \/>\ncc1plus: all warnings being treated as errors<br \/>\nmake[2]: *** [muduo\/base\/CMakeFiles\/muduo_base.dir\/build.make:63: muduo\/base\/CMakeFiles\/muduo_base.dir\/AsyncLogging.cc.o] Error 1<br \/>\nmake[1]: *** [CMakeFiles\/Makefile2:196: muduo\/base\/CMakeFiles\/muduo_base.dir\/all] Error 2<br \/>\nmake: *** [Makefile:141: all] Error 2<\/p>\n<h4>\u89e3\u51b3\u529e\u6cd5:<\/h4>\n<p>\u4fee\u6539 CMakeLists.txt<\/p>\n<p>\u5728 CMakeLists.txt \u4e2d\u6dfb\u52a0&#xff1a;<\/p>\n<p>if(CMAKE_CXX_COMPILER_ID MATCHES &#034;GNU|Clang&#034;)<br \/>\n    add_compile_options(-Wno-old-style-cast)  # \u5ffd\u7565\u8be5\u8b66\u544a<br \/>\nendif()<\/p>\n<h4>\u79fb\u52a8\u5934\u6587\u4ef6\u548c\u5e93\u6587\u4ef6<\/h4>\n<p>install\u547d\u4ee4\u5e76\u6ca1\u6709\u628a\u5b83\u4eec\u62f7\u8d1d\u5230\u7cfb\u7edf\u8def\u5f84\u4e0b&#xff0c;\u5bfc\u81f4\u6211\u4eec\u6bcf\u6b21\u7f16\u8bd1\u7a0b\u5e8f\u90fd\u9700\u8981\u6307\u5b9amuduo\u5e93\u7684\u5934\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\u8def\u5f84&#xff0c;\u5f88\u9ebb\u70e6&#xff0c;\u6240\u4ee5\u6211\u4eec\u9009\u62e9\u76f4\u63a5\u628ainlcude&#xff08;\u5934\u6587\u4ef6&#xff09;\u548clib&#xff08;\u5e93\u6587\u4ef6&#xff09;\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u62f7\u8d1d\u5230\u7cfb\u7edf\u76ee\u5f55\u4e0b&#xff1a;<\/p>\n<p>root&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11<span class=\"token comment\"># ls<\/span><br \/>\ninclude  lib<br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11<span class=\"token comment\"># cd include\/<\/span><br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/include<span class=\"token comment\"># ls<\/span><br \/>\nmuduo<br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/include<span class=\"token comment\"># mv muduo\/ \/usr\/include\/<\/span><br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/include<span class=\"token comment\"># cd ..<\/span><br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11<span class=\"token comment\"># ls<\/span><br \/>\ninclude  lib<br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11<span class=\"token comment\"># cd lib\/<\/span><br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/lib<span class=\"token comment\"># ls<\/span><br \/>\nlibmuduo_base.a  libmuduo_http.a  libmuduo_inspect.a  libmuduo_net.a<br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/lib<span class=\"token comment\"># mv * \/usr\/local\/lib\/<\/span><br \/>\nroot&#064;tony-virtual-machine:\/home\/tony\/package\/build\/release-install-cpp11\/lib<span class=\"token comment\"># <\/span><\/p>\n<p>\u62f7\u8d1d\u5b8c\u6210\u4ee5\u540e\u4f7f\u7528muduo\u5e93\u7f16\u5199C&#043;&#043;\u7f51\u7edc\u7a0b\u5e8f&#xff0c;\u4e0d\u7528\u5728\u6307\u5b9a\u5934\u6587\u4ef6\u548clib\u5e93\u6587\u4ef6\u8def\u5f84\u4fe1\u606f\u4e86&#xff0c;\u56e0\u4e3ag&#043;&#043;\u4f1a\u81ea\u52a8\u4ece\/usr\/include\u548c\/usr\/local\/lib\u8def\u5f84\u4e0b\u5bfb\u627e\u6240\u9700\u8981\u7684\u6587\u4ef6\u3002<\/p>\n<h3>redis\u548cmysql\u5b89\u88c5<\/h3>\n<p>ubuntu\u7684 \u5305\u5b89\u88c5<\/p>\n<p>sudo apt install mysql-server<br \/>\nsudo apt install redis-server<\/p>\n<h3>\u9a8c\u8bc1mysql\u73af\u5883<\/h3>\n<p>\u67e5\u770b \u8fd0\u884c\u4e2d\u7684 \u670d\u52a1<\/p>\n<p>netstat -tanp<\/p>\n<p>mysql \u9ed8\u8ba4 3306 \u7aef\u53e3<\/p>\n<p>tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      70276\/mysqld <\/p>\n<p>\u767b\u5f55\u4e00\u4e0b mysql<\/p>\n<p>\u521d\u6b21\u5b89\u88c5&#8212;&#8211;&gt; \u5148\u67e5\u770b \u9ed8\u8ba4\u5bc6\u7801<\/p>\n<p>sudo cat \/etc\/mysql\/debian.cnf<\/p>\n<p>\u7136\u540e<\/p>\n<p>mysql -u root -p&lt;\u5bc6\u7801&gt;<\/p>\n<p>\u53ef\u80fd\u7684\u9519\u8bef:<\/p>\n<p>ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;\/tmp\/mysql.sock&#039; (2)<\/p>\n<p>\u8fd9\u662f\u7531\u4e8e socket\u6587\u4ef6\u8def\u5f84\u4e0d\u6b63\u786e<\/p>\n<p>\u4e34\u65f6\u4fee\u6539:&#8212;-&gt; \u67e5\u770b\u5bc6\u7801\u65f6, \u5c31\u663e\u793a\u4e86 socket\u7684\u8def\u5f84<\/p>\n<p>mysql -u root -p&lt;\u5bc6\u7801&gt; -S \/var\/run\/mysqld\/mysqld.sock<\/p>\n<p>\u6c38\u4e45\u4fee\u6539:<\/p>\n<p>sudo nano \/etc\/mysql\/my.cnf<\/p>\n<p>\/\/\u6dfb\u52a0<br \/>\n[client]<br \/>\nsocket &#061; \/var\/run\/mysqld\/mysqld.sock<\/p>\n<h3>\u4fee\u6539mysql\u5bc6\u7801<\/h3>\n<p>\/\/\u8fdb\u5165mysql\u540e<br \/>\nALTER USER &#039;root&#039;&#064;&#039;localhost&#039; IDENTIFIED BY &#039;\u4f60\u7684\u65b0\u5bc6\u7801&#039;;<br \/>\nFLUSH PRIVILEGES;  &#8212; \u5237\u65b0\u6743\u9650<\/p>\n<h3>Nginx\u2013\u5148\u4e0d\u5b89\u88c5<\/h3>\n<p>\u5148\u505a\u4e00\u4e2a \u5355\u673a\u7684<\/p>\n<h2>Json\u4ecb\u7ecd<\/h2>\n<h3>\u4e3a\u4ec0\u4e48\u9700\u8981json?<\/h3>\n<p>\u4e4b\u6240\u4ee5\u9700\u8981 JSON&#xff08;JavaScript Object Notation&#xff09;&#xff0c;\u662f\u56e0\u4e3a\u5b83\u662f\u4e00\u79cd\u975e\u5e38\u65b9\u4fbf\u3001\u901a\u7528\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\u3002\u7b80\u5355\u6765\u8bf4&#xff0c;JSON \u662f\u8ba9\u4e0d\u540c\u7cfb\u7edf\u6216\u7a0b\u5e8f\u4e4b\u95f4\u6c9f\u901a\u7684\u4e00\u79cd\u201c\u901a\u7528\u8bed\u8a00\u201d\u3002<\/p>\n<h3>\u4ec0\u4e48\u662f json \u5e8f\u5217\u5316?<\/h3>\n<p>\u4e00\u4e2a\u5f62\u8c61\u7684\u4f8b\u5b50: <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250519232627-682bbe2371006.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>\u5e38\u7528\u7684\u6570\u636e\u4f20\u8f93\u5e8f\u5217\u5316\u683c\u5f0f?<\/h3>\n<p>\u5728\u7f51\u7edc\u4e2d&#xff0c;\u5e38\u7528\u7684\u6570\u636e\u4f20\u8f93\u5e8f\u5217\u5316\u683c\u5f0f\u6709XML&#xff0c;Json&#xff0c;ProtoBuf&#xff0c;\u5728\u516c\u53f8\u7ea7\u522b\u7684\u9879\u76ee\u4e2d&#xff0c;\u5927\u91cf\u7684\u5728\u4f7f\u7528ProtoBuf\u4f5c\u4e3a\u6570\u636e\u5e8f\u5217\u5316\u7684\u65b9\u5f0f&#xff0c;\u4ee5\u5176\u6570\u636e\u538b\u7f29\u7f16\u7801\u4f20\u8f93&#xff0c;\u5360\u7528\u5e26\u5bbd\u5c0f&#xff0c;\u540c\u6837\u7684\u6570\u636e\u4fe1\u606f&#xff0c;\u662fJson\u76841\/10&#xff0c;XML\u76841\/20&#xff0c;\u4f46\u662f\u4f7f\u7528\u8d77\u6765\u6bd4Json\u7a0d\u590d\u6742\u4e00\u4e9b&#xff0c;\u6240\u4ee5\u9879\u76ee\u4e2d\u6211\u4eec\u9009\u62e9\u5e38\u7528\u7684Json\u683c\u5f0f\u6765\u6253\u5305\u4f20\u8f93\u6570\u636e\u3002<\/p>\n<p>\u5173\u4e8e protobuf , \u6709\u53e6\u4e00\u4e2a\u9879\u76ee, rpc \u6846\u67b6<\/p>\n<h3>\u76f4\u63a5\u4f7f\u7528json\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<p>JSON for Modern C&#043;&#043;<\/p>\n<p>\u4f18\u70b9\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u4ec5\u662f\u4e00\u4e2a\u5934\u6587\u4ef6 : json.hpp&#xff0c; \u76f4\u63a5 \u62c9\u5165\u9879\u76ee \u5373\u53ef<\/li>\n<li>C&#043;&#043; 11 \u6807\u51c6\u7f16\u5199<\/li>\n<li>\u4f7f\u7528 json \u50cf\u4f7f\u7528 STL \u5bb9\u5668\u4e00\u6837<\/li>\n<li>STL \u548c json \u5bb9\u5668\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362<\/li>\n<\/ul>\n<p>\u76f4\u63a5\u53bb github \u4e0b\u8f7d json.hpp \u6587\u4ef6\u5373\u53ef<\/p>\n<p>https:\/\/github.com\/nlohmann\/json\/releases\/tag\/v3.12.0<\/p>\n<h3>json\u5e8f\u5217\u5316\u4ee3\u7801\u6f14\u793a<\/h3>\n<p>\u4f55\u4e3a\u5e8f\u5217\u5316? &#8212;-&gt; \u6570\u636e\u5bf9\u8c61 \u8f6c\u5316\u4e3a json \u5b57\u7b26\u4e32<\/p>\n<p>\u4e3b\u8981\u51fd\u6570: string str &#061; js.dump(); \u8fd9\u662f \u8f6c\u6362\u5b57\u7b26\u4e32\u7684 \u4e3b\u8981 \u51fd\u6570<\/p>\n<p>nlohmann::json \u9ed8\u8ba4\u4f7f\u7528 std::map \u5b58\u50a8\u5bf9\u8c61&#xff0c;\u800c std::map \u672c\u8eab\u5c31\u662f\u81ea\u52a8\u6309 key \u6392\u5e8f&#xff08;\u5b57\u5178\u5e8f&#xff09;\u7684\u3002<\/p>\n<p>\u56e0\u6b64 \u9ed8\u8ba4 \u8f93\u51fa \u662f\u5b57\u5178\u5e8f<\/p>\n<p>using ordered_json &#061; nlohmann::ordered_json; \u5c31\u53ef\u4ee5\u4e0d\u6392\u5e8f, \u6309\u7167\u63d2\u5165\u987a\u5e8f<\/p>\n<p>\u5934\u6587\u4ef6:<\/p>\n<p>#include &#034;json.hpp&#034;<br \/>\nusing json &#061; nlohmann::json;    \/\/ \u8fd9\u4e2a\u4f5c\u7528\u57df\u662f\u4f5c\u8005\u540d\u5b57, \u5728 hpp\u6587\u4ef6\u5c31\u53ef\u4ee5\u770b\u5230, \u4e0d\u7528\u8bb0<\/p>\n<p>\u6f14\u793a:<\/p>\n<p>#include &#034;json.hpp&#034;<br \/>\nusing json &#061; nlohmann::json;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>\/\/ json\u5e8f\u5217\u5316\u793a\u4f8b1<br \/>\nvoid func1()<br \/>\n{<br \/>\n    json js;<br \/>\n    js[&#034;msg_type&#034;] &#061; 2;<br \/>\n    js[&#034;from&#034;] &#061; &#034;zhangsan&#034;;<br \/>\n    js[&#034;to&#034;] &#061; &#034;li si&#034;;<br \/>\n    js[&#034;msg&#034;] &#061; &#034;hello, waht are you doing?&#034;;<\/p>\n<p>    cout &lt;&lt; js &lt;&lt; endl;<\/p>\n<p>    \/\/ \u8f6c\u5b57\u7b26\u4e32\u8f93\u51fa<br \/>\n    string sendbuf &#061; js.dump();<br \/>\n    cout &lt;&lt; sendbuf.c_str() &lt;&lt; endl;   \/\/ \u7f51\u7edc\u4f20\u9001\u4e00\u822c\u90fd\u662f char*, string \u8f6c\u4e00\u4e0b<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n    func1();<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>\u8f93\u51fa:<\/p>\n<p>{&#034;from&#034;:&#034;zhangsan&#034;,&#034;msg&#034;:&#034;hello, waht are you doing?&#034;,&#034;msg_type&#034;:2,&#034;to&#034;:&#034;li si&#034;}<br \/>\n{&#034;from&#034;:&#034;zhangsan&#034;,&#034;msg&#034;:&#034;hello, waht are you doing?&#034;,&#034;msg_type&#034;:2,&#034;to&#034;:&#034;li si&#034;}<\/p>\n<h3>\u590d\u6742\u952e\u503c\u5bf9\u6f14\u793a<\/h3>\n<p>\u952e\u7684\u503c\u8fd8\u662f\u952e<\/p>\n<p>void func2()<br \/>\n{<br \/>\n    json js;<br \/>\n    \/\/ \u6dfb\u52a0\u6570\u7ec4<br \/>\n    js[&#034;id&#034;] &#061; {1, 2, 3, 4, 5};<br \/>\n    \/\/ \u6dfb\u52a0key-value<br \/>\n    js[&#034;name&#034;] &#061; &#034;zhang san&#034;;<br \/>\n    \/\/ \u6dfb\u52a0\u5bf9\u8c61<br \/>\n    js[&#034;msg&#034;][&#034;zhang san&#034;] &#061; &#034;hello world&#034;;<br \/>\n    js[&#034;msg&#034;][&#034;liu shuo&#034;] &#061; &#034;hello china&#034;;<br \/>\n    \/\/ \u4e0a\u9762\u7b49\u540c\u4e8e\u4e0b\u9762\u8fd9\u53e5\u4e00\u6b21\u6027\u6dfb\u52a0\u6570\u7ec4\u5bf9\u8c61<br \/>\n    js[&#034;msg&#034;] &#061; {{&#034;zhang san&#034;, &#034;hello world&#034;}, {&#034;liu shuo&#034;, &#034;hello china&#034;}};<br \/>\n    cout &lt;&lt; js &lt;&lt; endl;<br \/>\n}<\/p>\n<p>\u8f93\u51fa:<\/p>\n<p>{&#034;id&#034;:[1,2,3,4,5],&#034;msg&#034;:{&#034;liu shuo&#034;:&#034;hello china&#034;,&#034;zhang san&#034;:&#034;hello world&#034;},&#034;name&#034;:&#034;zhang san&#034;}<\/p>\n<p>\u53d1\u73b0: msg\u662f\u4e00\u4e2a\u952e, \u5176\u5185\u90e8\u8fd8\u6709\u4e24\u4e2a\u952e\u503c\u5bf9<\/p>\n<h3>\u5bb9\u5668\u5e8f\u5217\u5316\u6f14\u793a<\/h3>\n<p>void func3()<br \/>\n{<br \/>\n    json js;<br \/>\n    \/\/ \u76f4\u63a5\u5e8f\u5217\u5316\u4e00\u4e2avector\u5bb9\u5668<br \/>\n    vector&lt;int&gt; vec;<br \/>\n    vec.push_back(1);<br \/>\n    vec.push_back(2);<br \/>\n    vec.push_back(5);<br \/>\n    js[&#034;list&#034;] &#061; vec;<\/p>\n<p>    \/\/ \u76f4\u63a5\u5e8f\u5217\u5316\u4e00\u4e2amap\u5bb9\u5668<br \/>\n    map&lt;int, string&gt; m;<br \/>\n    m.insert({1, &#034;\u9ec4\u5c71&#034;});<br \/>\n    m.insert({2, &#034;\u534e\u5c71&#034;});<br \/>\n    m.insert({3, &#034;\u6cf0\u5c71&#034;});<br \/>\n    js[&#034;path&#034;] &#061; m;<\/p>\n<p>    cout &lt;&lt; js &lt;&lt; endl;<\/p>\n<p>    string sendbuf &#061; js.dump();<br \/>\n    cout&lt;&lt;sendbuf.c_str()&lt;&lt;endl;<\/p>\n<p>}<\/p>\n<p>\u8f93\u51fa:<\/p>\n<p>{&#034;list&#034;:[1,2,5],&#034;path&#034;:[[1,&#034;\u9ec4\u5c71&#034;],[2,&#034;\u534e\u5c71&#034;],[3,&#034;\u6cf0\u5c71&#034;]]}<br \/>\n{&#034;list&#034;:[1,2,5],&#034;path&#034;:[[1,&#034;\u9ec4\u5c71&#034;],[2,&#034;\u534e\u5c71&#034;],[3,&#034;\u6cf0\u5c71&#034;]]}<\/p>\n<h3>json\u53cd\u5e8f\u5217\u5316\u6f14\u793a<\/h3>\n<p>json \u5b57\u7b26\u4e32 &#8212;&gt; \u6570\u636e\u5bf9\u8c61<\/p>\n<p>\u4e3b\u8981\u51fd\u6570: json jsbuf &#061; json::parse(string); \u2014&gt; \u8fd9\u91cc\u7684string: js.dump()<\/p>\n<p>\u4f1a\u4fdd\u7559 \u539f\u6765\u7684 \u6570\u636e\u7c7b\u578b!!<\/p>\n<p>\u5c06 \u4e0a\u9762\u7684 \u51fd\u6570 \u8fd4\u56de\u503c \u4fee\u6539\u4e3a string, return js.dump()<\/p>\n<p>#include &#034;json.hpp&#034;<br \/>\nusing json &#061; nlohmann::json;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>\/\/ json\u5e8f\u5217\u5316\u793a\u4f8b1<br \/>\nstring func1()<br \/>\n{<br \/>\n    json js;<br \/>\n    js[&#034;msg_type&#034;] &#061; 2;<br \/>\n    js[&#034;from&#034;] &#061; &#034;zhangsan&#034;;<br \/>\n    js[&#034;to&#034;] &#061; &#034;li si&#034;;<br \/>\n    js[&#034;msg&#034;] &#061; &#034;hello, waht are you doing?&#034;;<\/p>\n<p>    \/\/ cout &lt;&lt; js &lt;&lt; endl;<\/p>\n<p>    \/\/ \/\/ \u8f6c\u5b57\u7b26\u4e32\u8f93\u51fa<br \/>\n    \/\/ string sendbuf &#061; js.dump();<br \/>\n    \/\/ cout &lt;&lt; sendbuf.c_str() &lt;&lt; endl; \/\/ \u7f51\u7edc\u4f20\u9001\u4e00\u822c\u90fd\u662f char*, string \u8f6c\u4e00\u4e0b<br \/>\n    return js.dump();<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<\/p>\n<p>    string recvBuf &#061; func1();<br \/>\n    json jsbuf &#061; json::parse(recvBuf);<br \/>\n    cout&lt;&lt;jsbuf[&#034;from&#034;]&lt;&lt;endl;<br \/>\n     cout&lt;&lt;jsbuf[&#034;msg_type&#034;]&lt;&lt;endl;<br \/>\n    cout&lt;&lt;jsbuf[&#034;to&#034;]&lt;&lt;endl; <\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>string func2()<br \/>\n{<br \/>\n    json js;<br \/>\n    \/\/ \u6dfb\u52a0\u6570\u7ec4<br \/>\n    js[&#034;id&#034;] &#061; {1, 2, 3, 4, 5};<br \/>\n    \/\/ \u6dfb\u52a0key-value<br \/>\n    js[&#034;name&#034;] &#061; &#034;zhang san&#034;;<br \/>\n    \/\/ \u6dfb\u52a0\u5bf9\u8c61<br \/>\n    js[&#034;msg&#034;][&#034;zhang san&#034;] &#061; &#034;hello world&#034;;<br \/>\n    js[&#034;msg&#034;][&#034;liu shuo&#034;] &#061; &#034;hello china&#034;;<br \/>\n    \/\/ \u4e0a\u9762\u7b49\u540c\u4e8e\u4e0b\u9762\u8fd9\u53e5\u4e00\u6b21\u6027\u6dfb\u52a0\u6570\u7ec4\u5bf9\u8c61<br \/>\n    js[&#034;msg&#034;] &#061; {{&#034;zhang san&#034;, &#034;hello world&#034;}, {&#034;liu shuo&#034;, &#034;hello china&#034;}};<br \/>\n    \/\/ cout &lt;&lt; js &lt;&lt; endl;<br \/>\n    return js.dump();<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<\/p>\n<p>    \/\/\u4f7f\u7528 auto \u4e0d\u5173\u6ce8 \u8fd4\u56de\u7c7b\u578b, \u5e76\u4e14\u53ef\u4ee5\u5b58\u50a8<br \/>\n    string recvBuf &#061; func2();<br \/>\n    json jsbuf &#061; json::parse(recvBuf);<br \/>\n    auto arr &#061; jsbuf[&#034;id&#034;];<br \/>\n    cout&lt;&lt;arr&lt;&lt;endl;   \/\/ [1,2,3,4,5]<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>string func3()<br \/>\n{<br \/>\n    json js;<br \/>\n    \/\/ \u76f4\u63a5\u5e8f\u5217\u5316\u4e00\u4e2avector\u5bb9\u5668<br \/>\n    vector&lt;int&gt; vec;<br \/>\n    vec.push_back(1);<br \/>\n    vec.push_back(2);<br \/>\n    vec.push_back(5);<br \/>\n    js[&#034;list&#034;] &#061; vec;<\/p>\n<p>    \/\/ \u76f4\u63a5\u5e8f\u5217\u5316\u4e00\u4e2amap\u5bb9\u5668<br \/>\n    map&lt;int, string&gt; m;<br \/>\n    m.insert({1, &#034;\u9ec4\u5c71&#034;});<br \/>\n    m.insert({2, &#034;\u534e\u5c71&#034;});<br \/>\n    m.insert({3, &#034;\u6cf0\u5c71&#034;});<br \/>\n    js[&#034;path&#034;] &#061; m;<\/p>\n<p>    \/\/ cout &lt;&lt; js &lt;&lt; endl;<\/p>\n<p>    \/\/ string sendbuf &#061; js.dump();<br \/>\n    \/\/ cout&lt;&lt;sendbuf.c_str()&lt;&lt;endl;<br \/>\n    return js.dump();<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<\/p>\n<p>    string recvBuf &#061; func3();<br \/>\n    json jsbuf &#061; json::parse(recvBuf);<br \/>\n    vector&lt;int&gt; vec &#061; jsbuf[&#034;list&#034;];<br \/>\n    for(int &amp;v:vec)<br \/>\n    {<br \/>\n        cout&lt;&lt;v&lt;&lt;&#034; &#034;;<br \/>\n    }<br \/>\n    cout&lt;&lt;endl;<\/p>\n<p>    map&lt;int, string&gt; mymap &#061; jsbuf[&#034;path&#034;];<br \/>\n    for(auto &amp;p:mymap)<br \/>\n    {<br \/>\n        cout&lt;&lt;p.first&lt;&lt;&#034; &#034;&lt;&lt;p.second&lt;&lt;&#034; &#034;;<br \/>\n    }<br \/>\n    cout&lt;&lt;endl;<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h3>\u4f7f\u7528\u603b\u7ed3<\/h3>\n<p>\u5e8f\u5217\u5316: dump<\/p>\n<p>\u53cd\u5e8f\u5217\u5316: json::parse(\u2026);<\/p>\n<h2>muduo\u7f51\u7edc\u5e93\u7b80\u4ecb<\/h2>\n<p>\u591a\u770bpdf<\/p>\n<p>\u5148\u5b66\u4f1a\u7528<\/p>\n<p>\u518d\u53bb\u770b\u6e90\u7801, \u53bb\u624b\u6495<\/p>\n<h3>muduo\u7f51\u7edc\u5e93\u662f\u4ec0\u4e48?<\/h3>\n<p>Muduo \u7f51\u7edc\u5e93\u662f\u4e00\u4e2a \u7528 C&#043;&#043; \u7f16\u5199\u7684\u9ad8\u6027\u80fd\u7f51\u7edc\u7f16\u7a0b\u5e93&#xff0c;\u5b83\u7684\u6838\u5fc3\u76ee\u6807\u662f\u8ba9\u4f60\u80fd\u7528\u73b0\u4ee3 C&#043;&#043; \u7f16\u5199\u9ad8\u5e76\u53d1\u3001\u9ad8\u6027\u80fd\u7684\u670d\u52a1\u5668\u7a0b\u5e8f&#xff0c;\u7279\u522b\u9002\u5408 Linux \u5e73\u53f0\u4e0a\u7684\u591a\u7ebf\u7a0b\u7f51\u7edc\u7f16\u7a0b\u3002<\/p>\n<p>\u7f51\u7edc\u7a0b\u5e8f \u9879\u76ee \u7528\u7684\u6700\u591a\u7684\u7b2c\u4e09\u65b9\u5e93:<\/p>\n<li>muduo\u7f51\u7edc\u5e93<\/li>\n<li>libevent\u5e93(\u9ed1\u9a6c\u7f51\u7edc\u7f16\u7a0b\u6709)<\/li>\n<p>\u4e8c\u8005\u90fd\u662f\u57fa\u4e8e \u591a\u8defIO\u590d\u7528\u7684 epool&#043;\u7ebf\u7a0b\u6c60 \u7f51\u7edc\u6a21\u578b<\/p>\n<h3>\u6838\u5fc3\u601d\u60f3<\/h3>\n<p>reactors in threads &#8211; one loop per thread<\/p>\n<p>\u6bcf\u4e2a\u7ebf\u7a0b\u53ea\u8fd0\u884c\u4e00\u4e2a EventLoop&#xff0c;\u8fd9\u4e2a EventLoop \u53ea\u5904\u7406\u81ea\u5df1\u8d1f\u8d23\u7684\u8fde\u63a5\u3002<\/p>\n<p>\u8fd9\u5c31\u53eb&#xff1a;One loop per thread&#xff08;\u4e00\u4e2a\u7ebf\u7a0b\u5bf9\u5e94\u4e00\u4e2a\u4e8b\u4ef6\u5faa\u73af&#xff09;<\/p>\n<p>\u8fd9\u4e5f\u662f\u9ad8\u5e76\u53d1\u7684\u57fa\u7840<\/p>\n<p>\u7ebf\u7a0b\u6570\u91cf\u2013&gt; \u4e00\u822c\u7531 cpu\u6838\u6570\u786e\u5b9a<\/p>\n<p>\u8fc7\u591a\u8017\u8d39 cpu io \u7684\u4efb\u52a1, \u4f1a\u88ab\u4ea4\u7ed9Threadpool \u7ebf\u7a0b\u6c60 \u4e2d, \u4e13\u95e8\u5904\u7406\u8017\u65f6 \u7684\u8ba1\u7b97\u4efb\u52a1, \u5982\u4e0b\u56fe<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250519232627-682bbe23890eb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u8865\u5145muduo\u7f51\u7edc\u5e93\u77e5\u8bc6<\/h2>\n<h3>Muduo \u7684\u7ebf\u7a0b\u6a21\u578b\u6982\u89c8&#xff1a;<\/h3>\n<p>Muduo \u7f51\u7edc\u5e93\u4e00\u822c\u5206\u4e3a\u4e24\u4e2a\u4e3b\u8981\u7684\u7ebf\u7a0b\u89d2\u8272&#xff1a;<\/p>\n<li>\u4e3b\u7ebf\u7a0b&#xff08;IO\u7ebf\u7a0b \/ Reactor\u7ebf\u7a0b \/ EventLoop\u7ebf\u7a0b&#xff09;<\/li>\n<li>\u5de5\u4f5c\u7ebf\u7a0b&#xff08;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u7ebf\u7a0b \/ \u4e1a\u52a1\u7ebf\u7a0b&#xff09;<\/li>\n<h3>\u4e3b\u7ebf\u7a0b&#xff08;EventLoop \u6240\u5728\u7ebf\u7a0b&#xff09;<\/h3>\n<ul>\n<li>\n<p>\u6bcf\u4e2a EventLoop \u5bf9\u8c61\u8fd0\u884c\u5728\u4e00\u4e2a\u7279\u5b9a\u7ebf\u7a0b\u4e2d&#xff0c;\u4e00\u822c\u79f0\u4e4b\u4e3a IO \u7ebf\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u6765\u76d1\u542c IO \u4e8b\u4ef6&#xff08;\u5982\u8fde\u63a5\u3001\u8bfb\u5199\u4e8b\u4ef6&#xff09;&#xff0c;\u5e76\u8c03\u7528\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u4e5f\u662f IO \u4e8b\u4ef6\u7684\u4e00\u79cd&#xff0c;\u66f4\u51c6\u786e\u5730\u8bf4\u662f&#xff1a;<\/p>\n<p>\u201c\u65b0\u8fde\u63a5\u5230\u6765\u201d \u662f\u76d1\u542c socket&#xff08;listen fd&#xff09;\u4e0a\u7684\u4e00\u79cd\u201c\u53ef\u8bfb\u4e8b\u4ef6&#xff08;readable event&#xff09;&#034;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5178\u578b\u7528\u9014&#xff1a;<\/p>\n<ul>\n<li>\u63a5\u53d7\u65b0\u8fde\u63a5&#xff08;\u901a\u8fc7 Acceptor&#xff09;<\/li>\n<li>\u5206\u53d1\u8bfb\u5199\u4e8b\u4ef6<\/li>\n<li>\u6267\u884c Channel \u4e0a\u7ed1\u5b9a\u7684\u56de\u8c03\u51fd\u6570&#xff08;\u5982 onMessage, onConnection&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u4e2a EventLoop \u4e0d\u80fd\u88ab\u591a\u4e2a\u7ebf\u7a0b\u8c03\u7528&#xff08;\u6709\u65ad\u8a00\u4fdd\u8bc1&#xff09;\u3002<\/li>\n<li>\u6240\u6709\u64cd\u4f5c\u5fc5\u987b\u5728\u5b83\u81ea\u5df1\u7684\u7ebf\u7a0b\u4e2d\u6267\u884c&#xff0c;\u907f\u514d\u52a0\u9501\u3002<\/li>\n<\/ul>\n<h3>\u5de5\u4f5c\u7ebf\u7a0b&#xff08;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u7ebf\u7a0b&#xff09;<\/h3>\n<ul>\n<li>Muduo \u63d0\u4f9b\u4e86 EventLoopThreadPool&#xff0c;\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u5de5\u4f5c\u7ebf\u7a0b&#xff0c;\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u62e5\u6709\u4e00\u4e2a\u72ec\u7acb\u7684 EventLoop\u3002<\/li>\n<li>\u65b0\u8fde\u63a5\u63a5\u5165\u540e&#xff0c;\u4e3b\u7ebf\u7a0b\u901a\u8fc7\u8f6e\u8be2&#xff08;round-robin&#xff09;\u65b9\u5f0f\u5c06\u8fde\u63a5\u5206\u53d1\u7ed9\u5de5\u4f5c\u7ebf\u7a0b\u3002<\/li>\n<li>\u5de5\u4f5c\u7ebf\u7a0b\u5904\u7406\u4e0e\u8be5\u8fde\u63a5\u76f8\u5173\u7684 IO \u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h3>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u8bbe\u8ba1&#xff1f;<\/h3>\n<ul>\n<li>\u4e3b\u7ebf\u7a0b\u53ea\u8d1f\u8d23\u63a5\u5165\u8fde\u63a5\u548c\u5206\u53d1&#xff0c;\u907f\u514d\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c\u590d\u6742\u903b\u8f91&#xff0c;\u4fdd\u6301\u9ad8\u54cd\u5e94\u3002<\/li>\n<li>\u5de5\u4f5c\u7ebf\u7a0b\u5904\u7406\u6570\u636e\u8bfb\u5199&#xff0c;\u7528\u6237\u53ef\u4ee5\u5728\u8fd9\u4e9b\u7ebf\u7a0b\u4e2d\u6267\u884c\u4e1a\u52a1\u903b\u8f91\u3002<\/li>\n<li>\u8fd9\u79cd\u6a21\u5f0f\u63d0\u9ad8\u4e86\u7cfb\u7edf\u7684\u5e76\u53d1\u5904\u7406\u80fd\u529b&#xff0c;\u540c\u65f6\u53c8\u80fd\u4fdd\u6301\u7ebf\u7a0b\u4e4b\u95f4\u7684\u6700\u5c0f\u540c\u6b65\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h3>\u7ebf\u7a0b\u4e4b\u95f4\u5982\u4f55\u901a\u4fe1&#xff1f;<\/h3>\n<ul>\n<li>\u4e3b\u7ebf\u7a0b\u548c\u5de5\u4f5c\u7ebf\u7a0b\u4e4b\u95f4\u901a\u8fc7**EventLoop::runInLoop() \u6216 queueInLoop()**\u673a\u5236\u5f02\u6b65\u901a\u4fe1\u3002<\/li>\n<li>\u6240\u6709\u8de8\u7ebf\u7a0b\u8c03\u7528\u6700\u7ec8\u90fd\u5728 EventLoop \u6240\u5728\u7ebf\u7a0b\u4e2d\u6267\u884c&#xff0c;\u907f\u514d\u6570\u636e\u7ade\u4e89\u3002<\/li>\n<\/ul>\n<h2>muduo\u7f51\u7edc\u5e93\u7f16\u7a0b<\/h2>\n<h3>\u5e93\u7684\u641c\u7d22\u8def\u5f84\u95ee\u9898<\/h3>\n<p>muduo\u7f51\u7edc\u5e93\u5728\u4f7f\u7528\u65f6, \u9700\u8981\u94fe\u63a5 \u4e00\u4e9b\u52a8\u6001\u5e93\u6587\u4ef6<\/p>\n<p>lmuduo_net -lmuduo_base -lpthread<\/p>\n<p>g&#043;&#043; main.cpp -o myserver -lmuduo_net -lmuduo_base -lpthread -lrt<\/p>\n<p>\u5982\u679c\u52a8\u6001\u5e93 \u5728 usr\/lib \u6216\u8005 usr\/local\/lib \u5c31\u4e0d\u9700\u8981\u914d\u7f6e\u4e86<\/p>\n<p>\u5982\u679c\u4e0d\u5728\u7cfb\u7edf\u8def\u5f84, \u5c31\u9700\u8981 \u81ea\u5df1\u914d\u7f6e\u4e86<\/p>\n<h3>muduo\u7684\u4fbf\u5229\u6027<\/h3>\n<p>muduo\u7f51\u7edc\u5e93\u7ed9\u7528\u6237\u63d0\u4f9b\u4e86\u4e24\u4e2a\u4e3b\u8981\u7684\u7c7b<\/p>\n<li>\n<p>TcpServer&#xff1a;\u7528\u4e8e\u7f16\u5199\u670d\u52a1\u5668\u7a0b\u5e8f\u7684<\/p>\n<\/li>\n<li>\n<p>TcpClient&#xff1a;\u7528\u4e8e\u7f16\u5199\u5ba2\u6237\u7aef\u7a0b\u5e8f\u7684<\/p>\n<\/li>\n<p>epoll &#043; \u7ebf\u7a0b\u6c60<\/p>\n<p>\u597d\u5904&#xff1a;\u80fd\u591f\u628a\u7f51\u7edcI\/O\u7684\u4ee3\u7801\u548c\u4e1a\u52a1\u4ee3\u7801\u533a\u5206\u5f00<\/p>\n<p>\u4e1a\u52a1\u4ee3\u7801 \u4e3b\u8981 \u66b4\u9732\u4ec5 \u4e24\u4e2a : \u7528\u6237\u7684\u8fde\u63a5\u548c\u65ad\u5f00\u7528\u6237\u53ef\u8bfb\u5199\u4e8b\u4ef6<\/p>\n<p>\u4e0d\u9700\u8981\u5173\u5fc3\u600e\u4e48\u8fde\u63a5, \u591a\u5c11\u8fde\u63a5, \u8fd9\u4e9b\u5728\u7f51\u7edcio\u6a21\u5757 \u5c31\u5b8c\u6210\u4e86<\/p>\n<h3>\u57fa\u4e8emuduo\u7684\u670d\u52a1\u5668\u7f16\u7a0b<\/h3>\n<p>\u5934\u6587\u4ef6:<\/p>\n<p>#include &lt;muduo\/net\/TcpServer.h&gt; \/\/\u670d\u52a1\u7aef<br \/>\n#include &lt;muduo\/net\/EventLoop.h&gt;<\/p>\n<p>TcpServer \u6784\u9020\u51fd\u6570\u7684\u53c2\u6570:<\/p>\n<p>  TcpServer(EventLoop* loop,<br \/>\n            const InetAddress&amp; listenAddr,<br \/>\n            const string&amp; nameArg,<br \/>\n            Option option &#061; kNoReusePort);<\/p>\n<p>\u5728\u5b9e\u9645\u4f7f\u7528muduo\u5e93 \u65f6, \u4ec5\u9700\u8981\u5173\u6ce8 &#8212;&#8212;&#8212;&#8212;&#8211;&gt; \u5176\u4f59\u7684 \u4ee3\u7801\u57fa\u672c\u662f\u6b7b\u7684, \u4e0d\u7528\u7ba1<\/p>\n<li>\u8fde\u63a5\u4e0e\u65ad\u5f00 \u7684\u56de\u8c03\u51fd\u6570&#8212;&#8211;&gt; \u4e0b\u9762\u7684 onConnection\u51fd\u6570<\/li>\n<li>\u5904\u7406\u7528\u6237 \u7684 \u8bfb\u5199\u65f6\u95f4 \u7684\u56de\u8c03\u51fd\u6570&#8212;&#8211;&gt; \u4e0b\u9762\u7684 onMessage \u51fd\u6570<\/li>\n<p>#include &lt;muduo\/net\/TcpServer.h&gt;<br \/>\n#include &lt;muduo\/net\/EventLoop.h&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<br \/>\nusing namespace muduo;<br \/>\nusing namespace muduo::net; \/\/ muduo::net::TcpServer<\/p>\n<p>#include &lt;functional&gt; \/\/ \u5185\u542b\u7ed1\u5b9a\u5668 bind<\/p>\n<p>\/*\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u5f00\u53d1\u670d\u52a1\u5668\u7a0b\u5e8f<br \/>\n1. \u7ec4\u5408TcpServer\u5bf9\u8c61<br \/>\n2. \u521b\u5efaEventLoop\u4e8b\u4ef6\u5faa\u73af\u5bf9\u8c61\u7684\u6307\u9488<br \/>\n3. \u660e\u786eTcpServer\u6784\u9020\u51fd\u6570\u9700\u8981\u4ec0\u4e48\u53c2\u6570, \u8f93\u51faChatServer\u7684\u6784\u9020\u51fd\u6570&#8212;-\u9700\u8981\u770b\u6e90\u7801<br \/>\n4. \u5728\u5f53\u524d\u670d\u52a1\u5668\u7c7b\u7684 \u6784\u9020\u51fd\u6570\u4e2d, \u6ce8\u518c \u5904\u7406\u8fde\u63a5\u7684 \u56de\u8c03\u51fd\u6570\u548c \u5904\u7406\u8bfb\u5199\u4e8b\u4ef6 \u7684\u56de\u8c03\u51fd\u6570<br \/>\n5. \u8bbe\u7f6e\u5408\u9002\u7684 \u670d\u52a1\u7aef\u7ebf\u7a0b\u6570\u91cf, muduo \u5e93\u4f1a\u81ea\u5df1\u5212\u5206 i\/o\u7ebf\u7a0b\u548c worker\u7ebf\u7a0b<br \/>\n*\/<\/p>\n<p>class ChatServer<br \/>\n{<br \/>\npublic:<br \/>\n    \/\/ \u6784\u9020\u51fd\u6570 #3<br \/>\n    ChatServer(EventLoop *loop,               \/\/ \u65f6\u95f4\u5faa\u73af&#8211;\u53cd\u5e94\u5806<br \/>\n               const InetAddress &amp;listenAddr, \/\/ \u670d\u52a1\u5668\u5730\u5740\u7ed3\u6784&#8211;IP&#043;PORT<br \/>\n               const string &amp;nameArg)         \/\/ \u670d\u52a1\u5668\u540d\u5b57<br \/>\n        : _loop(loop), _server(loop, listenAddr, nameArg)<\/p>\n<p>    {<br \/>\n        \/\/ \u7531\u4e8e\u4f7f\u7528\u4e86 \u7f51\u7edc\u5e93, \u5c31\u4ee3\u8868 \u4e0d\u9700\u8981 \u81ea\u5df1\u5199\u7f51\u7edc\u4ee3\u7801, \u53ea\u9700\u8981\u5173\u6ce8 \u4e1a\u52a1\u4ee3\u7801 \u6f0f\u51fa\u7684 \u63a5\u53e3<\/p>\n<p>        \/\/ \u7531\u4e8e\u4e0d\u77e5\u9053\u4ec0\u4e48\u65f6\u5019\u53d1\u751f, \u56e0\u6b64 \u501f\u52a9\u56de\u8c03\u51fd\u6570, \u5728\u4e8b\u4ef6\u53d1\u751f\u540e, \u53bb\u8fdb\u884c\u56de\u8c03, \u6267\u884c\u56de\u8c03\u51fd\u6570\u91cc\u7684\u4ee3\u7801\u5373\u53ef<\/p>\n<p>        \/\/ 1. \u7ed9\u670d\u52a1\u5668\u6ce8\u518c\u7528\u6237\u8fde\u63a5\u7684 \u521b\u5efa \u548c \u65ad\u5f00 \u56de\u8c03 #5<br \/>\n        \/\/ void setConnectionCallback(const ConnectionCallback&amp; cb){..}  \u51fd\u6570\u539f\u578b<br \/>\n        _server.setConnectionCallback(std::bind(&amp;ChatServer::onConnection, this, _1)); \/\/ \u4f20\u5165\u7684\u5c31\u662f \u56de\u8c03\u51fd\u6570, \u800c\u5728\u8fd9\u4e2a\u7c7b\u91cc, \u5199\u7684\u56de\u8c03\u51fd\u6570\u662f \u6210\u5458\u65b9\u6cd5, \u6709this\u6307\u9488, \u4f46\u662f\u53ea\u9700\u8981\u7b2c\u4e8c\u4e2a\u4f20\u53c2,  \u56e0\u6b64\u4f7f\u7528 \u7ed1\u5b9a\u5668: this\u56fa\u5b9a, const TcpConnectionPtr&amp; \u4ea4\u7ed9 \u4f20\u5165\u8005<\/p>\n<p>        \/\/ 2. \u7ed9\u670d\u52a1\u5668\u6ce8\u518c\u7528\u6237 \u8bfb\u5199\u65f6\u95f4\u56de\u8c03<br \/>\n        _server.setMessageCallback(std::bind(&amp;ChatServer::onMessage, this, _1, _2, _3));<\/p>\n<p>        \/\/ \u8bbe\u7f6e \u670d\u52a1\u5668\u7aef\u7684 \u7ebf\u7a0b\u6570\u91cf<br \/>\n        \/\/ \u8bbe\u5b9a\u4e3a 4, \u4e00\u4e2a IO\u7ebf\u7a0b, 3\u4e2aworker\u7ebf\u7a0b<br \/>\n        _server.setThreadNum(4); \/\/ \u5982\u679c\u4e0d\u52a0, \u9ed8\u8ba4\u662f\u4e00\u4e2a\u7ebf\u7a0b, \u65e2\u8981\u76d1\u542c, \u8fd8\u8981\u5904\u7406 \u8bfb\u5199&#8212;-&gt; \u5982\u679c\u8bbe\u7f6e\u4e3a 2, \u5219\u76d1\u542c\u5360\u7528\u4e00\u4e2a, \u5269\u4e0b\u4e00\u4e2a, \u8981\u5904\u7406\u6240\u6709\u7684\u8bfb\u5199\u4e8b\u4ef6,  \u6548\u7387\u90fd\u4e0d\u9ad8<br \/>\n    };<\/p>\n<p>    \/\/ \u5f00\u542f\u4e8b\u4ef6\u5faa\u73af #4<br \/>\n    void start()<br \/>\n    {<br \/>\n        _server.start();<br \/>\n    }<\/p>\n<p>private:<br \/>\n    \/\/ \u4e13\u95e8\u5904\u7406\u7528\u6237\u7684\u8fde\u63a5\u4e0e\u65ad\u5f00  \u4ec5\u5904\u7406\u56de\u8c03\u63a5\u53e3\u5373\u53ef #4<br \/>\n    \/\/  \u7ecf\u8fc7epoll litsenfd accept, \u5230\u8fbeaccept \u8bf4\u660e\u6709\u65b0\u7528\u6237\u8fde\u63a5\u4e86<br \/>\n    \/* \u7136\u800c \u7f51\u7edc\u5e93 \u5df2\u7ecf\u5c01\u88c5\u597d socket\u76f8\u5173\u7684\u4e86, \u4ec5\u66b4\u9732\u4e86 \u56de\u8c03\u63a5\u53e3!!!*\/<br \/>\n    void onConnection(const TcpConnectionPtr &amp;conn) \/\/ \u8981\u5b66\u4f1a \u4ece\u6e90\u7801 \u627e \u7c7b\u578b<br \/>\n    \/\/ typedef std::function&lt;void (const TcpConnectionPtr&amp;)&gt; ConnectionCallback;<br \/>\n    {<br \/>\n        if (conn-&gt;connected()) \/\/ bool\u503c<br \/>\n        {<br \/>\n            cout &lt;&lt; conn-&gt;peerAddress().toIpPort() &lt;&lt; &#034;-&gt;&#034; &lt;&lt; conn-&gt;localAddress().toIpPort() &lt;&lt; &#034;  state:online&#034; &lt;&lt; endl;<br \/>\n        }<br \/>\n        else<br \/>\n        {<br \/>\n            cout &lt;&lt; conn-&gt;peerAddress().toIpPort() &lt;&lt; &#034;-&gt;&#034; &lt;&lt; conn-&gt;localAddress().toIpPort() &lt;&lt; &#034;  state:off&#034; &lt;&lt; endl;<\/p>\n<p>            conn-&gt;shutdown();   \/\/ close(fd)<br \/>\n            \/\/ _loop-&gt;quit(); \/\/\u9000\u51fa\u6574\u4e2a\u670d\u52a1\u5668<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u4e13\u95e8\u5904\u7406\u7528\u6237\u7684 \u8bfb\u5199\u4e8b\u4ef6<br \/>\n    void onMessage(const TcpConnectionPtr &amp;conn, \/\/ \u8fde\u63a5<br \/>\n                   Buffer *buffer,               \/\/ \u7f13\u51b2\u533a<br \/>\n                   Timestamp time)               \/\/ \u65f6\u95f4<br \/>\n    {<br \/>\n        string buf &#061; buffer-&gt;retrieveAllAsString();                          \/\/ \u5c01\u88c5\u4e86 \u628a\u6570\u636e \u5168\u90e8\u653e\u5230 \u5b57\u7b26\u4e32\u4e2d<br \/>\n        cout &lt;&lt; &#034;recv data: &#034; &lt;&lt; buf &lt;&lt; &#034; time:&#034; &lt;&lt; time.toString() &lt;&lt; endl; \/\/ time \u4e5f\u662f \u5c01\u88c5\u7684, \u628a\u65f6\u95f4\u4fe1\u606f\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32<br \/>\n        conn-&gt;send(buf);                                                     \/\/ \u6536\u5230 \u5e76\u5904\u7406\u540e\u8fd4\u56de, \u8fd9\u91cc\u6d4b\u8bd5 \u4f7f\u7528 \u539f\u6570\u636e\u8fd4\u56de<br \/>\n    }<\/p>\n<p>    TcpServer _server; \/\/ #1<br \/>\n    EventLoop *_loop;  \/\/ #2 epoll\u5faa\u73af, \u53ef\u4ee5\u6ce8\u518c\u4fe1\u53f7,\u6355\u6349\u4fe1\u53f7, \u65f6\u95f4\u5faa\u73af<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    EventLoop loop;                      \/\/ \u76f8\u5f53\u4e8e \u521b\u5efaepoll      muduo::net::EventLoop<br \/>\n    InetAddress addr(&#034;127.0.0.1&#034;, 6000); \/\/  muduo::net::InetAddress<br \/>\n    ChatServer server(&amp;loop, addr, &#034;ChatServer&#034;);<\/p>\n<p>    server.start();  \/\/ listenfd &#8212; \u4f7f\u7528epoll_ctl \u6dfb\u52a0\u5230epoll\u4e0a<br \/>\n    loop.loop(); \/\/ epoll_wait \u4ee5\u963b\u585e\u65b9\u5f0f \u7b49\u5f85\u65b0\u7528\u6237\u8fde\u63a5, \u5df2\u8fde\u63a5\u7528\u6237\u7684\u8bfb\u5199\u4e8b\u4ef6\u7b49<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>InetAddress addr(&#034;127.0.0.1&#034;, 6000); \u8fd9\u884c\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a InetAddress \u5bf9\u8c61&#xff0c;\u4ee3\u8868\u670d\u52a1\u5668\u76d1\u542c\u7684 IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u5177\u4f53\u89e3\u91ca\u5982\u4e0b&#xff1a;<\/p>\n<p>\u201c127.0.0.1\u201d&#xff1a;\u662f \u672c\u5730\u56de\u73af\u5730\u5740&#xff08;localhost&#xff09;&#xff0c;\u610f\u5473\u7740\u8fd9\u4e2a\u670d\u52a1\u5668\u53ea\u63a5\u53d7\u6765\u81ea\u672c\u673a\u7684\u8fde\u63a5\u3002\u5982\u679c\u4f60\u5e0c\u671b\u63a5\u53d7\u5916\u90e8\u673a\u5668\u7684\u8fde\u63a5&#xff0c;\u53ef\u4ee5\u5c06\u5176\u6539\u6210 0.0.0.0&#xff08;\u8868\u793a\u76d1\u542c\u6240\u6709\u7f51\u7edc\u63a5\u53e3&#xff09;\u6216\u8005\u5177\u4f53\u7684\u672c\u673aIP\u3002<\/p>\n<p>6000&#xff1a;\u662f \u7aef\u53e3\u53f7&#xff0c;\u8868\u793a\u670d\u52a1\u5668\u5c06\u76d1\u542c\u8fd9\u4e2a\u7aef\u53e3&#xff0c;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5\u3002<\/p>\n<h3>\u7f16\u8bd1\u9519\u8bef\u95ee\u9898\u89e3\u51b3<\/h3>\n<p>\u76f4\u63a5run code \u4f1a\u51fa\u73b0 \u7f16\u8bd1\u9519\u8bef:<\/p>\n<p>g&#043;&#043;\u7684 ld&#8230;.. &#8212;&#8212;-&gt; \u8fd9\u662f \u94fe\u63a5\u9519\u8bef, ld \u662f link editor \u7684\u7f29\u5199<\/p>\n<p>\u89e3\u51b3\u529e\u6cd51:<\/p>\n<p>\u8fd9\u91cc\u5c31 \u7528\u5230\u4e86 \u5e93\u7684\u641c\u7d22\u8def\u5f84\u95ee\u9898<\/p>\n<p> g&#043;&#043; nuduo_server.cpp -o server -lmuduo_net -lmuduo_base -lpthread<\/p>\n<p>-lmuduo_net \u5fc5\u987b\u5728\u524d\u9762, \u540e\u9762\u7684base \u7528\u5230\u4e86 net<\/p>\n<p>\u89e3\u51b3\u529e\u6cd52:<\/p>\n<p>\u76f4\u63a5\u8bbe\u7f6e vscode<\/p>\n<p>\u6309F1 &#8212;-&gt; \u641c c&#043;&#043;\u7684json\u914d\u7f6e\u6587\u4ef6 &#8212;-&gt; c_cpp_properties.json<\/p>\n<p> \/\/\u4e00\u822c\u7684 \u7f16\u8bd1\u547d\u4ee4<br \/>\ngcc -I\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84  -L\u5e93\u6587\u4ef6\u641c\u7d22\u8def\u5f84 -l\u5e93\u540d\u79f0<\/p>\n<p> \/usr\/include    \/usr\/local\/include<br \/>\n\/\/\u4e00\u822c\u662f \u9ed8\u8ba4\u7684 \u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84, \u8fd9\u4e2a\u5c31\u4e0d\u7528\u52a0\u4e86<\/p>\n<p>\/\/\u5bf9\u5e94\u7684<br \/>\n \/usr\/lib    \/usr\/local\/lib<\/p>\n<p>\u5728\u9879\u76ee\u6587\u4ef6\u9875, ctrl&#043;shift&#043;b(build)\u2014&gt;\u5173\u95ed\u641c\u72d7\u8f93\u5165\u6cd5\u7684 \u6ca1\u7528\u7684\u5feb\u6377\u952e, \u4f1a\u51b2\u7a81, \u6253\u5f00 g&#043;&#043; \u914d\u7f6e\u6587\u4ef6 task.json<\/p>\n<p>\u5728\u7f16\u8bd1\u9009\u9879, \u6dfb\u52a0\u90a3\u51e0\u4e2a\u5373\u53ef:<\/p>\n<p> &#034;args&#034;: [<br \/>\n&#034;-fdiagnostics-color&#061;always&#034;,<br \/>\n&#034;-g&#034;,<br \/>\n&#034;${file}&#034;,<br \/>\n&#034;-o&#034;,<br \/>\n&#034;${fileDirname}\/${fileBasenameNoExtension}&#034;,<br \/>\n&#034;-lmuduo_net&#034;,<br \/>\n&#034;-lmuduo_base&#034;,<br \/>\n&#034;-lpthread&#034;<br \/>\n],<\/p>\n<p>\u7ee7\u7eed ctrl&#043;shift&#043;b(build), \u8fdb\u884c\u7f16\u8bd1!!!<\/p>\n<p>\u5373\u53ef \u770b\u5230 \u8f93\u51fa \u91cc\u5305\u542b\u4e86 \u8fd9\u4e9b\u5e93<\/p>\n<p>vscode \u4e09\u5927\u6700\u91cd\u8981\u7684 json \u6587\u4ef6:<\/p>\n<li>c_cpp_properties.json&#xff1a;\u914d\u7f6e\u7f16\u8bd1\u5668\u8def\u5f84\u548c\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84&#xff0c;\u8ba9 VSCode \u80fd\u6b63\u786e\u8bc6\u522b\u4ee3\u7801&#xff08;\u81ea\u52a8\u8865\u5168\u3001\u8df3\u8f6c\u5b9a\u4e49&#xff09;\u3002<\/li>\n<li>tasks.json&#xff1a;\u5b9a\u4e49\u4e00\u952e\u7f16\u8bd1\u547d\u4ee4&#xff08;\u5982 g&#043;&#043;&#xff09;&#xff0c;\u6309 Ctrl&#043;Shift&#043;B \u76f4\u63a5\u8fd0\u884c&#xff0c;\u7701\u53bb\u624b\u52a8\u8f93\u547d\u4ee4\u3002<\/li>\n<li>launch.json&#xff1a;\u914d\u7f6e\u8c03\u8bd5\u5668&#xff08;\u5982 GDB&#xff09;&#xff0c;\u6309 F5 \u542f\u52a8\u8c03\u8bd5&#xff0c;\u53ef\u8bbe\u65ad\u70b9\u3001\u770b\u53d8\u91cf\u3002<\/li>\n<p>\u4e09\u6587\u4ef6\u914d\u5408&#xff0c;\u5b9e\u73b0 \u5199\u4ee3\u7801 \u2192 \u7f16\u8bd1 \u2192 \u8c03\u8bd5 \u5168\u6d41\u7a0b\u81ea\u52a8\u5316&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf27\u6b21\u3002json\u7b80\u5355\u4f7f\u7528, muduo \u7b80\u5355\u4f7f\u7528 _muduo error: use of old-style cast to \u2018model*\u2019<\/p>\n","protected":false},"author":2,"featured_media":38297,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,58,2382,43,78],"topic":[],"class_list":["post-38299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-linux","tag-2382","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38299.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf27\u6b21\u3002json\u7b80\u5355\u4f7f\u7528, muduo \u7b80\u5355\u4f7f\u7528 _muduo error: use of old-style cast to \u2018model*\u2019\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38299.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T23:26:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250519232627-682bbe2371006.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38299.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38299.html\",\"name\":\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-19T23:26:28+00:00\",\"dateModified\":\"2025-05-19T23:26:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38299.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38299.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38299.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38299.html","og_locale":"zh_CN","og_type":"article","og_title":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb757\u6b21\uff0c\u70b9\u8d5e20\u6b21\uff0c\u6536\u85cf27\u6b21\u3002json\u7b80\u5355\u4f7f\u7528, muduo \u7b80\u5355\u4f7f\u7528 _muduo error: use of old-style cast to \u2018model*\u2019","og_url":"https:\/\/www.wsisp.com\/helps\/38299.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-19T23:26:28+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250519232627-682bbe2371006.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38299.html","url":"https:\/\/www.wsisp.com\/helps\/38299.html","name":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-19T23:26:28+00:00","dateModified":"2025-05-19T23:26:28+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38299.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38299.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38299.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e00)"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38299"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38299\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38297"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38299"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}