{"id":17920,"date":"2025-04-19T00:23:14","date_gmt":"2025-04-18T16:23:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/17920.html"},"modified":"2025-04-19T00:23:14","modified_gmt":"2025-04-18T16:23:14","slug":"tingwebserver%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%bb%a3%e7%a0%81%e8%a7%a3%e8%af%bb03","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/17920.html","title":{"rendered":"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03"},"content":{"rendered":"<p>\u4e0a\u4e00\u7bc7&#xff1a;TingWebServer\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb02<\/p>\n<p>TingWebServer\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb02-CSDN\u535a\u5ba2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"958\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418162313-68027c713989a.png\" width=\"1200\" \/><\/p>\n<p>\u5728\u89e3\u8bfb 02\u4e2d\u89e3\u6790\u5b8cthreadpool\u548chttp_conn\u4e24\u4e2a\u6587\u4ef6\u5939\u540e&#xff0c;\u6211\u4eec\u7ee7\u7eed\u89e3\u6790\u540e\u9762\u4e00\u884c\u7684\u6587\u4ef6&#xff0c;locker-&gt;lst_timer<\/p>\n<\/p>\n<h2 style=\"background-color:transparent\">Locker\u6587\u4ef6\u5939<\/h2>\n<h3>README<\/h3>\n<p>\u7ebf\u7a0b\u540c\u6b65\u673a\u5236\u5305\u88c5\u7c7b<\/p>\n<p>\u591a\u7ebf\u7a0b\u540c\u6b65&#xff0c;\u786e\u4fdd\u4efb\u4e00\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u8fdb\u5165\u5173\u952e\u4ee3\u7801\u6bb5.<\/p>\n<ul>\n<li>\u4fe1\u53f7\u91cf<\/li>\n<li>\u4e92\u65a5\u9501<\/li>\n<li>\u6761\u4ef6\u53d8\u91cf<\/li>\n<\/ul>\n<h3>locker.h<\/h3>\n<p>\u4e00\u4e2a\u7b80\u5355\u7684locker\u4e92\u65a5\u9501\u7684\u5934\u6587\u4ef6&#xff0c;\u4ee3\u7801\u6bd4\u8f83\u7b80\u5355&#xff0c;\u6240\u4ee5\u51fd\u6570\u5185\u5bb9\u4e5f\u5728locker.h\u4e2d\u76f4\u63a5\u7ed9\u51fa\u4e86&#xff0c;\u63a5\u4e0b\u6765\u770b\u91cc\u9762\u7684\u4ee3\u7801<\/p>\n<h4>sem \u7c7b&#xff08;\u4fe1\u53f7\u91cf&#xff09;<\/h4>\n<p>class sem<br \/>\n{<br \/>\npublic:<br \/>\n    sem() {<br \/>\n        if (sem_init(&amp;m_sem, 0, 0) !&#061; 0) { \/\/\u4fe1\u53f7\u91cf\u521d\u59cb\u5316\u4e3a0<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<br \/>\n    sem(int num) {<br \/>\n        if (sem_init(&amp;m_sem, 0, num) !&#061; 0) { \/\/\u4fe1\u53f7\u91cf\u521d\u59cb\u5316\u4e3a\u8f93\u5165\u7684num<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<br \/>\n    ~sem() { \/\/\u89e3\u6790<br \/>\n        sem_destroy(&amp;m_sem);<br \/>\n    }<br \/>\n    bool wait() {  \/\/\u7b49\u5f85\u4fe1\u53f7\u91cf&#xff0c;\u4e3a0\u5373\u4e3a\u963b\u585e<br \/>\n        return sem_wait(&amp;m_sem) &#061;&#061; 0;<br \/>\n    }<br \/>\n    bool post() { \/\/\u589e\u52a0\u4fe1\u53f7\u91cf&#xff0c;\u4e3a0\u5524\u9192\u4e00\u4e2a\u7b49\u5f85\u7ebf\u7a0b<br \/>\n        return sem_post(&amp;m_sem) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>private:<br \/>\n    sem_t m_sem; \/\/ \u5b9a\u4e49\u4e00\u4e2a\u4fe1\u53f7\u91cf<br \/>\n};<\/p>\n<h4>locker \u7c7b&#xff08;\u4e92\u65a5\u9501&#xff09;<\/h4>\n<p>class locker<br \/>\n{<br \/>\npublic:<br \/>\n    locker() { \/\/\u521d\u59cb\u5316\u4e92\u65a5\u9501&#xff0c;\u5982\u679c\u5931\u8d25\u629b\u51fa\u5f02\u5e38<br \/>\n        if (pthread_mutex_init(&amp;m_mutex, NULL) !&#061; 0) {<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<br \/>\n    ~locker() { \/\/\u6790\u6784<br \/>\n        pthread_mutex_destroy(&amp;m_mutex);<br \/>\n    }<br \/>\n    bool lock() { \/\/\u9501\u5b9a\u4e92\u65a5\u9501<br \/>\n        return pthread_mutex_lock(&amp;m_mutex) &#061;&#061; 0;<br \/>\n    }<br \/>\n    bool unlock() { \/\/\u89e3\u9501\u4e92\u65a5\u9501<br \/>\n        return pthread_mutex_unlock(&amp;m_mutex) &#061;&#061; 0;<br \/>\n    }<br \/>\n    pthread_mutex_t *get() {<br \/>\n        return &amp;m_mutex;<br \/>\n    }<\/p>\n<p>private:<br \/>\n    pthread_mutex_t m_mutex; \/\/ \u5b9a\u4e49\u4e92\u65a5\u9501<br \/>\n};<\/p>\n<h4>cond \u7c7b&#xff08;\u6761\u4ef6\u53d8\u91cf&#xff09;<\/h4>\n<p>class cond<br \/>\n{<br \/>\npublic:<br \/>\n    cond() {                  \/\/\u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5931\u8d25\u5219\u629b\u51fa\u5f02\u5e38<br \/>\n        if (pthread_cond_init(&amp;m_cond, NULL) !&#061; 0) {<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<br \/>\n    ~cond() {             \/\/\u6790\u6784<br \/>\n        pthread_cond_destroy(&amp;m_cond);<br \/>\n    }<br \/>\n    bool wait(pthread_mutex_t *m_mutex) { \/\/\u7b49\u5f85\u6761\u4ef6\u53d8\u91cf\u7684\u4fe1\u53f7<br \/>\n        return pthread_cond_wait(&amp;m_cond, m_mutex) &#061;&#061; 0;<br \/>\n    }<br \/>\n    bool timewait(pthread_mutex_t *m_mutex, struct timespec t) { \/\/\u7b49\u5f85\u6307\u5b9a\u65f6\u95f4&#xff08;\u8d85\u65f6&#xff09;\u540e\u81ea\u52a8\u8fd4\u56de<br \/>\n        return pthread_cond_timedwait(&amp;m_cond, m_mutex, &amp;t) &#061;&#061; 0;<br \/>\n    }<br \/>\n    bool signal() { \/\/\u53d1\u9001\u4fe1\u53f7\u7ed9\u4e00\u4e2a\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n        return pthread_cond_signal(&amp;m_cond) &#061;&#061; 0;<br \/>\n    }<br \/>\n    bool broadcast() { \/\/\u53d1\u9001\u4fe1\u53f7\u7ed9\u6240\u6709\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n        return pthread_cond_broadcast(&amp;m_cond) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>private:<br \/>\n    pthread_cond_t m_cond; \/\/ \u5b9a\u4e49\u6761\u4ef6\u53d8\u91cf<br \/>\n};<\/p>\n<ul>\n<li>sem \u7c7b\u5b9e\u73b0\u4e86\u4fe1\u53f7\u91cf\u7684\u57fa\u672c\u529f\u80fd&#xff0c;\u5141\u8bb8\u7ebf\u7a0b\u95f4\u540c\u6b65\u8bbf\u95ee\u3002<\/li>\n<li>locker \u7c7b\u63d0\u4f9b\u4e86\u4e92\u65a5\u9501\u7684\u5c01\u88c5&#xff0c;\u786e\u4fdd\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u72ec\u5360\u8bbf\u95ee\u3002<\/li>\n<li>cond \u7c7b\u5219\u5b9e\u73b0\u4e86\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5141\u8bb8\u7ebf\u7a0b\u6839\u636e\u67d0\u4e2a\u6761\u4ef6\u540c\u6b65\u6216\u534f\u8c03\u6267\u884c\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<h2>\u00a0CGImysql\u6587\u4ef6\u5939<\/h2>\n<h3>README<\/h3>\n<p>\u6821\u9a8c &amp; \u6570\u636e\u5e93\u8fde\u63a5\u6c60<\/p>\n<p>\u6570\u636e\u5e93\u8fde\u63a5\u6c60<\/p>\n<ul>\n<li>\u5355\u4f8b\u6a21\u5f0f&#xff0c;\u4fdd\u8bc1\u552f\u4e00<\/li>\n<li>list\u5b9e\u73b0\u8fde\u63a5\u6c60<\/li>\n<li>\u8fde\u63a5\u6c60\u4e3a\u9759\u6001\u5927\u5c0f<\/li>\n<li>\u4e92\u65a5\u9501\u5b9e\u73b0\u7ebf\u7a0b\u5b89\u5168<\/li>\n<\/ul>\n<p>\u6821\u9a8c<\/p>\n<ul>\n<li>HTTP\u8bf7\u6c42\u91c7\u7528POST\u65b9\u5f0f<\/li>\n<li>\u767b\u5f55\u7528\u6237\u540d\u548c\u5bc6\u7801\u6821\u9a8c<\/li>\n<li>\u7528\u6237\u6ce8\u518c\u53ca\u591a\u7ebf\u7a0b\u6ce8\u518c\u5b89\u5168<\/li>\n<\/ul>\n<h3>sql_connection_pool.h<\/h3>\n<p>\u5934\u6587\u4ef6\u4ee3\u7801<\/p>\n<p>#ifndef _CONNECTION_POOL_<br \/>\n#define _CONNECTION_POOL_<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;list&gt;<br \/>\n#include &lt;mysql\/mysql.h&gt;<br \/>\n#include &lt;error.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\n#include &#034;..\/lock\/locker.h&#034;<br \/>\n#include &#034;..\/log\/log.h&#034;<\/p>\n<p>using namespace std;<\/p>\n<p>class connection_pool<br \/>\n{<br \/>\npublic:<br \/>\nMYSQL *GetConnection(); \/\/\u83b7\u53d6\u6570\u636e\u5e93\u8fde\u63a5<br \/>\nbool ReleaseConnection(MYSQL *conn); \/\/\u91ca\u653e\u8fde\u63a5<br \/>\nint GetFreeConn(); \/\/\u83b7\u53d6\u8fde\u63a5<br \/>\nvoid DestroyPool(); \/\/\u9500\u6bc1\u6240\u6709\u8fde\u63a5<\/p>\n<p>\/\/\u5355\u4f8b\u6a21\u5f0f<br \/>\nstatic connection_pool *GetInstance();<\/p>\n<p>void init(string url, string User, string PassWord, string DataBaseName, int Port, int MaxConn, int close_log); <\/p>\n<p>private:<br \/>\nconnection_pool();<br \/>\n~connection_pool();<\/p>\n<p>int m_MaxConn;  \/\/\u6700\u5927\u8fde\u63a5\u6570<br \/>\nint m_CurConn;  \/\/\u5f53\u524d\u5df2\u4f7f\u7528\u7684\u8fde\u63a5\u6570<br \/>\nint m_FreeConn; \/\/\u5f53\u524d\u7a7a\u95f2\u7684\u8fde\u63a5\u6570<br \/>\nlocker lock;<br \/>\nlist&lt;MYSQL *&gt; connList; \/\/\u8fde\u63a5\u6c60<br \/>\nsem reserve;<\/p>\n<p>public:<br \/>\nstring m_url; \/\/\u4e3b\u673a\u5730\u5740<br \/>\nstring m_Port; \/\/\u6570\u636e\u5e93\u7aef\u53e3\u53f7<br \/>\nstring m_User; \/\/\u767b\u9646\u6570\u636e\u5e93\u7528\u6237\u540d<br \/>\nstring m_PassWord; \/\/\u767b\u9646\u6570\u636e\u5e93\u5bc6\u7801<br \/>\nstring m_DatabaseName; \/\/\u4f7f\u7528\u6570\u636e\u5e93\u540d<br \/>\nint m_close_log;\/\/\u65e5\u5fd7\u5f00\u5173<br \/>\n};<\/p>\n<p>class connectionRAII{<\/p>\n<p>public:<br \/>\nconnectionRAII(MYSQL **con, connection_pool *connPool);<br \/>\n~connectionRAII();<\/p>\n<p>private:<br \/>\nMYSQL *conRAII;<br \/>\nconnection_pool *poolRAII;<br \/>\n};<\/p>\n<p>#endif <\/p>\n<h3>sql_connection_pool.cpp<\/h3>\n<h4>connection_pool \u7c7b<\/h4>\n<p>connection_pool \u662f\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u7684\u6838\u5fc3\u7c7b&#xff0c;\u8d1f\u8d23\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\u7684\u521b\u5efa\u3001\u83b7\u53d6\u3001\u91ca\u653e\u548c\u9500\u6bc1<\/p>\n<h5>\u6784\u9020\u51fd\u6570&#xff1a;connection_pool<\/h5>\n<p>connection_pool::connection_pool()<br \/>\n{<br \/>\n    m_CurConn &#061; 0;\/\/\u5f53\u524d\u8fde\u63a5\u6c60\u4e2d\u6b63\u5728\u4f7f\u7528\u7684\u8fde\u63a5\u6570\u7f6e0<br \/>\n    m_FreeConn &#061; 0;\/\/\u5f53\u524d\u8fde\u63a5\u6c60\u4e2d\u7a7a\u95f2\u7684\u8fde\u63a5\u6570\u7f6e0<br \/>\n}<\/p>\n<h5>\u9759\u6001\u65b9\u6cd5&#xff1a;GetInstance<\/h5>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5355\u4f8b\u6a21\u5f0f\u7684\u65b9\u6cd5&#xff0c;\u4fdd\u8bc1\u53ea\u6709\u4e00\u4e2aconnection_pool\u5b9e\u4f8b\u5b58\u5728<\/p>\n<p>connection_pool *connection_pool::GetInstance()<br \/>\n{<br \/>\n    static connection_pool connPool;<br \/>\n    return &amp;connPool;<br \/>\n}<\/p>\n<h5>\u00a0init \u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u521d\u59cb\u5316\u6570\u636e\u5e93\u8fde\u63a5\u6c60&#xff0c;\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570&#xff08;URL\u3001\u7528\u6237\u540d\u3001\u5bc6\u7801\u3001\u6570\u636e\u5e93\u540d\u3001\u7aef\u53e3\u53f7\u7b49&#xff09;\u3002<\/li>\n<li>\u521b\u5efa\u5e76\u521d\u59cb\u5316\u6570\u636e\u5e93\u8fde\u63a5&#xff0c;\u8c03\u7528 mysql_real_connect \u4e0e\u6570\u636e\u5e93\u5efa\u7acb\u8fde\u63a5\u3002<\/li>\n<li>\u5c06\u6bcf\u4e2a\u8fde\u63a5\u52a0\u5165connList&#xff0c;\u5e76\u66f4\u65b0\u7a7a\u95f2\u8fde\u63a5\u6570m_FreeConn\u3002<\/li>\n<\/ul>\n<p>void connection_pool::init(string url, string User, string PassWord, string DBName, int Port, int MaxConn, int close_log)<br \/>\n{<br \/>\n    m_url &#061; url;<br \/>\nm_Port &#061; Port;<br \/>\nm_User &#061; User;<br \/>\nm_PassWord &#061; PassWord;<br \/>\nm_DatabaseName &#061; DBName;<br \/>\nm_close_log &#061; close_log;<\/p>\n<p>for (int i &#061; 0; i &lt; MaxConn; i&#043;&#043;)<br \/>\n{<br \/>\nMYSQL *con &#061; NULL;<br \/>\ncon &#061; mysql_init(con);<\/p>\n<p>if (con &#061;&#061; NULL)<br \/>\n{<br \/>\nLOG_ERROR(&#034;MySQL Error&#034;);<br \/>\nexit(1);<br \/>\n}<br \/>\n        \/\/\u8c03\u7528 mysql_real_connect \u4e0e\u6570\u636e\u5e93\u5efa\u7acb\u8fde\u63a5<br \/>\ncon &#061; mysql_real_connect(con, url.c_str(), User.c_str(), PassWord.c_str(), DBName.c_str(), Port, NULL, 0);<\/p>\n<p>if (con &#061;&#061; NULL)<br \/>\n{<br \/>\nLOG_ERROR(&#034;MySQL Error&#034;);<br \/>\nexit(1);<br \/>\n}<br \/>\nconnList.push_back(con);\/\/\u5c06\u6bcf\u4e2a\u8fde\u63a5\u52a0\u5165connList<br \/>\n&#043;&#043;m_FreeConn;<br \/>\n}<\/p>\n<p>reserve &#061; sem(m_FreeConn);<\/p>\n<p>m_MaxConn &#061; m_FreeConn;<br \/>\n} <\/p>\n<h5>\u00a0GetConnection \u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u8be5\u65b9\u6cd5\u7528\u4e8e\u83b7\u53d6\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u8fde\u63a5\u6c60\u4e2d\u6ca1\u6709\u7a7a\u95f2\u8fde\u63a5&#xff0c;\u8fd4\u56deNULL\u3002<\/li>\n<li>\u5426\u5219&#xff0c;\u4f7f\u7528\u4fe1\u53f7\u91cfreserve.wait()\u786e\u4fdd\u5f53\u524d\u7a7a\u95f2\u8fde\u63a5\u6570\u4e0d\u4f1a\u8d85\u8fc7\u6700\u5927\u9650\u5236\u3002<\/li>\n<li>\u4f7f\u7528\u4e92\u65a5\u9501lock.lock()\u6765\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168\u3002<\/li>\n<li>\u4ece\u8fde\u63a5\u6c60\u4e2d\u83b7\u53d6\u4e00\u4e2a\u8fde\u63a5&#xff0c;\u5c06\u5176\u4ececonnList\u4e2d\u79fb\u9664&#xff0c;\u66f4\u65b0m_FreeConn\u548cm_CurConn\u3002<\/li>\n<li>\u8fd4\u56de\u53ef\u7528\u7684\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p>\/\/\u5f53\u6709\u8bf7\u6c42\u65f6&#xff0c;\u4ece\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u4e2d\u8fd4\u56de\u4e00\u4e2a\u53ef\u7528\u8fde\u63a5&#xff0c;\u66f4\u65b0\u4f7f\u7528\u548c\u7a7a\u95f2\u8fde\u63a5\u6570<br \/>\nMYSQL *connection_pool::GetConnection()<br \/>\n{<br \/>\nMYSQL *con &#061; NULL;<\/p>\n<p>if (0 &#061;&#061; connList.size())\/\/\u6ca1\u6709\u7a7a\u95f2\u8fde\u63a5<br \/>\nreturn NULL;<\/p>\n<p>reserve.wait();\/\/\u4f7f\u7528\u4fe1\u53f7\u91cfreserve.wait()\u786e\u4fdd\u5f53\u524d\u7a7a\u95f2\u8fde\u63a5\u6570\u4e0d\u4f1a\u8d85\u8fc7\u6700\u5927\u9650\u5236<\/p>\n<p>lock.lock();\/\/\u4e0a\u9501<\/p>\n<p>    \/\/\u83b7\u53d6\u8fde\u63a5<br \/>\ncon &#061; connList.front();<br \/>\nconnList.pop_front();        <\/p>\n<p>    \/\/\u66f4\u65b0<br \/>\n&#8211;m_FreeConn;<br \/>\n&#043;&#043;m_CurConn;<\/p>\n<p>lock.unlock();\/\/\u89e3\u9501<br \/>\nreturn con;\/\/\u8fd4\u56de\u53ef\u7528\u8fde\u63a5<br \/>\n}<\/p>\n<h5>ReleaseConnection \u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u8be5\u65b9\u6cd5\u7528\u4e8e\u91ca\u653e\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5&#xff1a;<\/p>\n<ul>\n<li>\u5c06\u8fde\u63a5\u91cd\u65b0\u52a0\u5165connList&#xff0c;\u66f4\u65b0\u7a7a\u95f2\u8fde\u63a5\u6570m_FreeConn\u548c\u4f7f\u7528\u4e2d\u7684\u8fde\u63a5\u6570m_CurConn\u3002<\/li>\n<li>\u4f7f\u7528\u4fe1\u53f7\u91cfreserve.post()\u901a\u77e5\u6709\u7a7a\u95f2\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p>\/\/\u91ca\u653e\u5f53\u524d\u4f7f\u7528\u7684\u8fde\u63a5<br \/>\nbool connection_pool::ReleaseConnection(MYSQL *con)<br \/>\n{<br \/>\nif (NULL &#061;&#061; con)<br \/>\nreturn false;<\/p>\n<p>lock.lock();\/\/\u4e0a\u9501<\/p>\n<p>    \/\/\u5c06\u8fde\u63a5\u91cd\u65b0\u52a0\u5165connList<br \/>\nconnList.push_back(con);<\/p>\n<p>    \/\/\u66f4\u65b0\u7a7a\u95f2\u8fde\u63a5\u6570m_FreeConn\u548c\u4f7f\u7528\u4e2d\u7684\u8fde\u63a5\u6570m_CurConn<br \/>\n&#043;&#043;m_FreeConn;<br \/>\n&#8211;m_CurConn;<\/p>\n<p>lock.unlock();\/\/\u89e3\u9501<\/p>\n<p>    \/\/\u4f7f\u7528\u4fe1\u53f7\u91cfreserve.post()\u901a\u77e5\u6709\u7a7a\u95f2\u8fde\u63a5<br \/>\nreserve.post();<br \/>\nreturn true;<br \/>\n} <\/p>\n<h5>DestroyPool \u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u9500\u6bc1\u8fde\u63a5\u6c60&#xff0c;\u5173\u95ed\u6240\u6709\u6570\u636e\u5e93\u8fde\u63a5&#xff0c;\u5e76\u6e05\u7a7aconnList\u3002\u00a0<\/p>\n<h5><\/h5>\n<p>\/\/\u9500\u6bc1\u6570\u636e\u5e93\u8fde\u63a5\u6c60<br \/>\nvoid connection_pool::DestroyPool()<br \/>\n{<\/p>\n<p>lock.lock();\/\/\u4e0a\u9501<br \/>\nif (connList.size() &gt; 0)<br \/>\n{<br \/>\nlist&lt;MYSQL *&gt;::iterator it;\/\/\u8fed\u4ee3\u5668\u5faa\u73af<br \/>\nfor (it &#061; connList.begin(); it !&#061; connList.end(); &#043;&#043;it)<br \/>\n{<br \/>\nMYSQL *con &#061; *it;<br \/>\nmysql_close(con);\/\/\u5173\u95ed\u8fde\u63a5<br \/>\n}<br \/>\n        \/\/\u6e05\u96f6<br \/>\nm_CurConn &#061; 0;<br \/>\nm_FreeConn &#061; 0;<br \/>\nconnList.clear();<br \/>\n}<\/p>\n<p>lock.unlock();\/\/\u89e3\u9501<br \/>\n} <\/p>\n<h5>GetFreeConn \u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u8fd4\u56de\u5f53\u524d\u7a7a\u95f2\u7684\u6570\u636e\u5e93\u8fde\u63a5\u6570\u00a0<\/p>\n<p>\/\/\u5f53\u524d\u7a7a\u95f2\u7684\u8fde\u63a5\u6570<br \/>\nint connection_pool::GetFreeConn()<br \/>\n{<br \/>\nreturn this-&gt;m_FreeConn;<br \/>\n} <\/p>\n<h5>\u6790\u6784\u51fd\u6570&#xff1a;<\/h5>\n<p>connection_pool::~connection_pool()<br \/>\n{<br \/>\n    DestroyPool();\/\/\u5728\u9500\u6bc1connection_pool\u5bf9\u8c61\u65f6&#xff0c;\u8c03\u7528DestroyPool\u9500\u6bc1\u8fde\u63a5\u6c60<br \/>\n}<\/p>\n<h4>connectionRAII \u7c7b\u00a0<\/h4>\n<p>onnectionRAII \u7c7b\u662f\u4e00\u4e2aRAII&#xff08;Resource Acquisition Is Initialization&#xff09;\u7ba1\u7406\u7c7b&#xff0c;\u7528\u4e8e\u81ea\u52a8\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\u7684\u83b7\u53d6\u4e0e\u91ca\u653e\u3002<\/p>\n<h5>\u6784\u9020\u51fd\u6570&#xff1a;connectionRAII<\/h5>\n<p>\u6784\u9020\u51fd\u6570\u901a\u8fc7connPool-&gt;GetConnection()\u83b7\u53d6\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5&#xff0c;\u5e76\u5c06\u5176\u8d4b\u7ed9SQL\u6307\u9488\u3002conRAII\u548cpoolRAII\u6210\u5458\u53d8\u91cf\u4fdd\u5b58\u5f53\u524d\u8fde\u63a5\u548c\u8fde\u63a5\u6c60\u7684\u5f15\u7528&#xff0c;\u786e\u4fdd\u5728connectionRAII\u5bf9\u8c61\u9500\u6bc1\u65f6&#xff0c;\u81ea\u52a8\u91ca\u653e\u8fde\u63a5<\/p>\n<p>connectionRAII::connectionRAII(MYSQL **SQL, connection_pool *connPool)<br \/>\n{<br \/>\n    *SQL &#061; connPool-&gt;GetConnection();<br \/>\n    conRAII &#061; *SQL;<br \/>\n    poolRAII &#061; connPool;<br \/>\n}<\/p>\n<h5>\u6790\u6784\u51fd\u6570&#xff1a;<\/h5>\n<p>\u6790\u6784\u51fd\u6570\u5728\u5bf9\u8c61\u9500\u6bc1\u65f6&#xff0c;\u8c03\u7528connPool-&gt;ReleaseConnection(conRAII)\u91ca\u653e\u6570\u636e\u5e93\u8fde\u63a5<\/p>\n<p>connectionRAII::~connectionRAII()<br \/>\n{<br \/>\n    poolRAII-&gt;ReleaseConnection(conRAII);<br \/>\n}<\/p>\n<h2>\u00a0log\u6587\u4ef6\u5939<\/h2>\n<h3>README<\/h3>\n<p>\u540c\u6b65\/\u5f02\u6b65\u65e5\u5fd7\u7cfb\u7edf<\/p>\n<p>\u540c\u6b65\/\u5f02\u6b65\u65e5\u5fd7\u7cfb\u7edf\u4e3b\u8981\u6d89\u53ca\u4e86\u4e24\u4e2a\u6a21\u5757&#xff0c;\u4e00\u4e2a\u662f\u65e5\u5fd7\u6a21\u5757&#xff0c;\u4e00\u4e2a\u662f\u963b\u585e\u961f\u5217\u6a21\u5757,\u5176\u4e2d\u52a0\u5165\u963b\u585e\u961f\u5217\u6a21\u5757\u4e3b\u8981\u662f\u89e3\u51b3\u5f02\u6b65\u5199\u5165\u65e5\u5fd7\u505a\u51c6\u5907.<\/p>\n<ul>\n<li>\u81ea\u5b9a\u4e49\u963b\u585e\u961f\u5217<\/li>\n<li>\u5355\u4f8b\u6a21\u5f0f\u521b\u5efa\u65e5\u5fd7<\/li>\n<li>\u540c\u6b65\u65e5\u5fd7<\/li>\n<li>\u5f02\u6b65\u65e5\u5fd7<\/li>\n<li>\u5b9e\u73b0\u6309\u5929\u3001\u8d85\u884c\u5206\u7c7b<\/li>\n<\/ul>\n<h3>log.h<\/h3>\n<p>\/\/\u5934\u6587\u4ef6\u90e8\u5206<br \/>\n#ifndef LOG_H<br \/>\n#define LOG_H<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\n#include &lt;stdarg.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &#034;block_queue.h&#034;<br \/>\n\/\/log\u7c7b\u5b9a\u4e49<br \/>\nclass Log<br \/>\n{<br \/>\npublic:<br \/>\n    \/\/ C&#043;&#043;11\u4ee5\u540e,\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u61d2\u6c49\u4e0d\u7528\u52a0\u9501<br \/>\n    static Log *get_instance()<br \/>\n    {<br \/>\n        static Log instance; \/\/ \u5c40\u90e8\u9759\u6001\u53d8\u91cf\u5b9e\u4f8b\u5316&#xff08;\u61d2\u6c49\u5f0f\u5355\u4f8b\u6a21\u5f0f&#xff09;<br \/>\n        return &amp;instance;<br \/>\n    }<br \/>\n    static void *flush_log_thread(void *args)<br \/>\n    {<br \/>\n        Log::get_instance()-&gt;async_write_log();  \/\/ \u8c03\u7528 Log \u7c7b\u7684\u5f02\u6b65\u65e5\u5fd7\u5199\u5165\u51fd\u6570<br \/>\n    }<br \/>\n    \/\/init() \u65b9\u6cd5<br \/>\n    bool init(const char *file_name, int close_log, int log_buf_size &#061; 8192, int split_lines &#061; 5000000, int max_queue_size &#061; 0);<br \/>\n    \/\/write_log() \u65b9\u6cd5<br \/>\n    void write_log(int level, const char *format, &#8230;);<br \/>\n    \/\/flush() \u65b9\u6cd5<br \/>\n    void flush(void);<br \/>\nprivate:<br \/>\n    Log();<br \/>\n    virtual ~Log();<br \/>\n    void *async_write_log()<br \/>\n    {<br \/>\n        string single_log;<br \/>\n        \/\/\u4ece\u963b\u585e\u961f\u5217\u4e2d\u53d6\u51fa\u4e00\u4e2a\u65e5\u5fd7string&#xff0c;\u5199\u5165\u6587\u4ef6<br \/>\n        while (m_log_queue-&gt;pop(single_log))<br \/>\n        {<br \/>\n            m_mutex.lock();<br \/>\n            fputs(single_log.c_str(), m_fp);<br \/>\n            m_mutex.unlock();<br \/>\n        }<br \/>\n    }<br \/>\nprivate:<br \/>\n    char dir_name[128]; \/\/\u8def\u5f84\u540d<br \/>\n    char log_name[128]; \/\/log\u6587\u4ef6\u540d<br \/>\n    int m_split_lines;  \/\/\u65e5\u5fd7\u6700\u5927\u884c\u6570<br \/>\n    int m_log_buf_size; \/\/\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f<br \/>\n    long long m_count;  \/\/\u65e5\u5fd7\u884c\u6570\u8bb0\u5f55<br \/>\n    int m_today;        \/\/\u56e0\u4e3a\u6309\u5929\u5206\u7c7b,\u8bb0\u5f55\u5f53\u524d\u65f6\u95f4\u662f\u90a3\u4e00\u5929<br \/>\n    FILE *m_fp;         \/\/\u6253\u5f00log\u7684\u6587\u4ef6\u6307\u9488<br \/>\n    char *m_buf;<br \/>\n    block_queue&lt;string&gt; *m_log_queue; \/\/\u963b\u585e\u961f\u5217<br \/>\n    bool m_is_async;                  \/\/\u662f\u5426\u540c\u6b65\u6807\u5fd7\u4f4d<br \/>\n    locker m_mutex;<br \/>\n    int m_close_log; \/\/\u5173\u95ed\u65e5\u5fd7<br \/>\n};<br \/>\n\/\/\u5b8f\u5b9a\u4e49\u90e8\u5206<br \/>\n#define LOG_DEBUG(format, &#8230;) if(0 &#061;&#061; m_close_log) {Log::get_instance()-&gt;write_log(0, format, ##__VA_ARGS__); Log::get_instance()-&gt;flush();}<br \/>\n#define LOG_INFO(format, &#8230;) if(0 &#061;&#061; m_close_log) {Log::get_instance()-&gt;write_log(1, format, ##__VA_ARGS__); Log::get_instance()-&gt;flush();}<br \/>\n#define LOG_WARN(format, &#8230;) if(0 &#061;&#061; m_close_log) {Log::get_instance()-&gt;write_log(2, format, ##__VA_ARGS__); Log::get_instance()-&gt;flush();}<br \/>\n#define LOG_ERROR(format, &#8230;) if(0 &#061;&#061; m_close_log) {Log::get_instance()-&gt;write_log(3, format, ##__VA_ARGS__); Log::get_instance()-&gt;flush();}<\/p>\n<p>#endif <\/p>\n<h3>log.cpp<\/h3>\n<ul>\n<li>\u540c\u6b65\u4e0e\u5f02\u6b65\u6a21\u5f0f&#xff1a;\u65e5\u5fd7\u7cfb\u7edf\u652f\u6301\u4e24\u79cd\u6a21\u5f0f\u3002\u5f02\u6b65\u6a21\u5f0f\u901a\u8fc7\u521b\u5efa\u7ebf\u7a0b\u548c\u4f7f\u7528\u963b\u585e\u961f\u5217\u5c06\u65e5\u5fd7\u5199\u5165\u6587\u4ef6&#xff0c;\u51cf\u5c11\u4e86\u963b\u585e\u64cd\u4f5c&#xff0c;\u63d0\u9ad8\u4e86\u6027\u80fd\u3002\u540c\u6b65\u6a21\u5f0f\u5219\u662f\u76f4\u63a5\u5728\u65e5\u5fd7\u51fd\u6570\u4e2d\u5199\u5165\u6587\u4ef6\u3002<\/li>\n<li>\u6309\u5929\u6216\u6309\u884c\u5206\u5272\u65e5\u5fd7&#xff1a;\u65e5\u5fd7\u4f1a\u6839\u636e\u65f6\u95f4\u6216\u8005\u884c\u6570\u8fdb\u884c\u5207\u5272\u3002\u6bcf\u5929\u751f\u6210\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6&#xff0c;\u6216\u8005\u5f53\u65e5\u5fd7\u884c\u6570\u8fbe\u5230\u6307\u5b9a\u4e0a\u9650\u65f6\u521b\u5efa\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<li>\u7ebf\u7a0b\u5b89\u5168&#xff1a;\u901a\u8fc7 m_mutex \u4e92\u65a5\u9501\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90&#xff0c;\u786e\u4fdd\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u65e5\u5fd7\u5199\u5165\u4e0d\u4f1a\u53d1\u751f\u51b2\u7a81<\/li>\n<\/ul>\n<h4>\u7c7b\u6210\u5458\u53d8\u91cf\u53ca\u6784\u9020\u51fd\u6570&#xff1a;log<\/h4>\n<p>Log::Log()<br \/>\n{<br \/>\n    m_count &#061; 0;\/\/\u521d\u59cb\u5316\u65e5\u5fd7\u884c\u6570\u8ba1\u6570\u5668<br \/>\n    m_is_async &#061; false;\/\/\u9ed8\u8ba4\u4e3a\u540c\u6b65\u6a21\u5f0f&#xff0c;\u4e0d\u542f\u7528\u5f02\u6b65\u65e5\u5fd7\u8bb0\u5f55<br \/>\n}<\/p>\n<h4>\u6790\u6784\u51fd\u6570 &#xff1a;~Log()<\/h4>\n<p>Log::~Log()<br \/>\n{<br \/>\n    if (m_fp !&#061; NULL)<br \/>\n    {<br \/>\n        fclose(m_fp);  \/\/ \u5982\u679c\u6587\u4ef6\u6307\u9488 &#096;m_fp&#096; \u4e0d\u4e3a NULL&#xff0c;\u5173\u95ed\u6587\u4ef6<br \/>\n    }<br \/>\n}<\/p>\n<h4>\u521d\u59cb\u5316\u51fd\u6570&#xff1a;init()<\/h4>\n<p>init()&#xff1a;\u7528\u4e8e\u521d\u59cb\u5316\u65e5\u5fd7\u7cfb\u7edf&#xff0c;\u5305\u62ec\u8bbe\u7f6e\u65e5\u5fd7\u6587\u4ef6\u540d\u3001\u8def\u5f84\u3001\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f\u3001\u5206\u5272\u884c\u6570\u7b49\u3002<\/p>\n<ul>\n<li>\u5982\u679c max_queue_size &gt;&#061; 1&#xff0c;\u5219\u542f\u7528\u5f02\u6b65\u65e5\u5fd7\u8bb0\u5f55\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7ebf\u7a0b\u6765\u6267\u884c\u65e5\u5fd7\u5199\u5165\u3002<\/li>\n<li>\u6839\u636e\u4f20\u5165\u7684\u6587\u4ef6\u540d\u548c\u5f53\u524d\u65f6\u95f4&#xff0c;\u751f\u6210\u65e5\u5fd7\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u548c\u6587\u4ef6\u540d\u3002<\/li>\n<li>\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6\u5e76\u51c6\u5907\u5199\u5165\u3002<\/li>\n<\/ul>\n<p>bool Log::init(const char *file_name, int close_log, int log_buf_size, int split_lines, int max_queue_size)<br \/>\n{<br \/>\n    \/\/ \u5982\u679c\u8bbe\u7f6e\u4e86max_queue_size, \u5219\u8bbe\u7f6e\u4e3a\u5f02\u6b65<br \/>\n    if (max_queue_size &gt;&#061; 1)<br \/>\n    {<br \/>\n        m_is_async &#061; true;  \/\/ \u542f\u7528\u5f02\u6b65\u65e5\u5fd7\u5199\u5165<br \/>\n        m_log_queue &#061; new block_queue&lt;string&gt;(max_queue_size);  \/\/ \u521b\u5efa\u4e00\u4e2a\u963b\u585e\u961f\u5217\u7528\u4e8e\u5b58\u653e\u65e5\u5fd7<br \/>\n        pthread_t tid;<br \/>\n        \/\/ \u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6765\u6267\u884c\u65e5\u5fd7\u7684\u5f02\u6b65\u5199\u5165<br \/>\n        pthread_create(&amp;tid, NULL, flush_log_thread, NULL);<br \/>\n    }<\/p>\n<p>    m_close_log &#061; close_log;  \/\/ \u8bbe\u7f6e\u65e5\u5fd7\u662f\u5426\u5173\u95ed\u7684\u6807\u5fd7<br \/>\n    m_log_buf_size &#061; log_buf_size;  \/\/ \u8bbe\u7f6e\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f<br \/>\n    m_buf &#061; new char[m_log_buf_size];  \/\/ \u521b\u5efa\u65e5\u5fd7\u7f13\u51b2\u533a<br \/>\n    memset(m_buf, &#039;\\\\0&#039;, m_log_buf_size);  \/\/ \u521d\u59cb\u5316\u7f13\u51b2\u533a\u4e3a 0<br \/>\n    m_split_lines &#061; split_lines;  \/\/ \u8bbe\u7f6e\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u5927\u884c\u6570<\/p>\n<p>    \/\/ \u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4<br \/>\n    time_t t &#061; time(NULL);<br \/>\n    struct tm *sys_tm &#061; localtime(&amp;t);<br \/>\n    struct tm my_tm &#061; *sys_tm;<\/p>\n<p>    const char *p &#061; strrchr(file_name, &#039;\/&#039;);<br \/>\n    char log_full_name[256] &#061; {0};<\/p>\n<p>    if (p &#061;&#061; NULL)<br \/>\n    {<br \/>\n        snprintf(log_full_name, 255, &#034;%d_%02d_%02d_%s&#034;, my_tm.tm_year &#043; 1900, my_tm.tm_mon &#043; 1, my_tm.tm_mday, file_name);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        strcpy(log_name, p &#043; 1);  \/\/ \u590d\u5236\u6587\u4ef6\u540d<br \/>\n        strncpy(dir_name, file_name, p &#8211; file_name &#043; 1);  \/\/ \u590d\u5236\u8def\u5f84\u540d<br \/>\n        snprintf(log_full_name, 255, &#034;%s%d_%02d_%02d_%s&#034;, dir_name, my_tm.tm_year &#043; 1900, my_tm.tm_mon &#043; 1, my_tm.tm_mday, log_name);<br \/>\n    }<\/p>\n<p>    m_today &#061; my_tm.tm_mday;  \/\/ \u8bbe\u7f6e\u5f53\u524d\u65e5\u671f<br \/>\n    m_fp &#061; fopen(log_full_name, &#034;a&#034;);  \/\/ \u6253\u5f00\u65e5\u5fd7\u6587\u4ef6&#xff08;\u4ee5\u8ffd\u52a0\u6a21\u5f0f&#xff09;<br \/>\n    if (m_fp &#061;&#061; NULL)<br \/>\n    {<br \/>\n        return false;  \/\/ \u5982\u679c\u6587\u4ef6\u6253\u5f00\u5931\u8d25&#xff0c;\u8fd4\u56de false<br \/>\n    }<\/p>\n<p>    return true;<br \/>\n}<\/p>\n<h4>\u65e5\u5fd7\u5199\u5165\u51fd\u6570 &#xff1a;write_log()<\/h4>\n<p>write_log()&#xff1a;\u8fd9\u662f\u65e5\u5fd7\u8bb0\u5f55\u7684\u6838\u5fc3\u65b9\u6cd5&#xff0c;\u5b83\u9996\u5148\u683c\u5f0f\u5316\u65e5\u5fd7\u4fe1\u606f\u5e76\u786e\u5b9a\u65e5\u5fd7\u7ea7\u522b&#xff08;\u5982 debug\u3001info\u3001warn\u3001error&#xff09;\u3002\u7136\u540e\u5224\u65ad\u662f\u5426\u9700\u8981\u5207\u6362\u65e5\u5fd7\u6587\u4ef6&#xff08;\u6309\u5929\u6216\u6309\u884c\u5206\u5272&#xff09;&#xff0c;\u5e76\u5728\u9700\u8981\u65f6\u521b\u5efa\u65b0\u6587\u4ef6\u3002\u6700\u540e&#xff0c;\u65e5\u5fd7\u4fe1\u606f\u4f1a\u6839\u636e\u662f\u5426\u542f\u7528\u5f02\u6b65\u6a21\u5f0f&#xff0c;\u5199\u5165\u5230\u6587\u4ef6\u6216\u8005\u963b\u585e\u961f\u5217\u4e2d\u3002<\/p>\n<p>void Log::write_log(int level, const char *format, &#8230;)<br \/>\n{<br \/>\n    struct timeval now &#061; {0, 0};<br \/>\n    gettimeofday(&amp;now, NULL);  \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4&#xff08;\u79d2\u548c\u5fae\u79d2&#xff09;<br \/>\n    time_t t &#061; now.tv_sec;<br \/>\n    struct tm *sys_tm &#061; localtime(&amp;t);  \/\/ \u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4<br \/>\n    struct tm my_tm &#061; *sys_tm;<br \/>\n    char s[16] &#061; {0};<\/p>\n<p>    switch (level)<br \/>\n    {<br \/>\n    case 0: strcpy(s, &#034;[debug]:&#034;); break;<br \/>\n    case 1: strcpy(s, &#034;[info]:&#034;); break;<br \/>\n    case 2: strcpy(s, &#034;[warn]:&#034;); break;<br \/>\n    case 3: strcpy(s, &#034;[erro]:&#034;); break;<br \/>\n    default: strcpy(s, &#034;[info]:&#034;); break;<br \/>\n    }<\/p>\n<p>    m_mutex.lock();  \/\/ \u9501\u4f4f\u65e5\u5fd7\u7cfb\u7edf&#xff0c;\u9632\u6b62\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u5199\u65e5\u5fd7<br \/>\n    m_count&#043;&#043;;  \/\/ \u589e\u52a0\u65e5\u5fd7\u884c\u6570\u8ba1\u6570\u5668<\/p>\n<p>    \/\/ \u5982\u679c\u5f53\u524d\u65e5\u671f\u4e0e\u65e5\u5fd7\u6587\u4ef6\u65e5\u671f\u4e0d\u4e00\u81f4&#xff0c;\u6216\u8005\u65e5\u5fd7\u884c\u6570\u8fbe\u5230\u6700\u5927\u884c\u6570&#xff0c;\u5207\u6362\u65e5\u5fd7\u6587\u4ef6<br \/>\n    if (m_today !&#061; my_tm.tm_mday || m_count % m_split_lines &#061;&#061; 0)<br \/>\n    {<br \/>\n        char new_log[256] &#061; {0};<br \/>\n        fflush(m_fp);  \/\/ \u5237\u65b0\u6587\u4ef6\u7f13\u51b2\u533a<br \/>\n        fclose(m_fp);  \/\/ \u5173\u95ed\u5f53\u524d\u65e5\u5fd7\u6587\u4ef6<br \/>\n        char tail[16] &#061; {0};<br \/>\n        snprintf(tail, 16, &#034;%d_%02d_%02d_&#034;, my_tm.tm_year &#043; 1900, my_tm.tm_mon &#043; 1, my_tm.tm_mday);<\/p>\n<p>        \/\/ \u5982\u679c\u65e5\u671f\u53d1\u751f\u53d8\u5316&#xff0c;\u5207\u6362\u5230\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6<br \/>\n        if (m_today !&#061; my_tm.tm_mday)<br \/>\n        {<br \/>\n            snprintf(new_log, 255, &#034;%s%s%s&#034;, dir_name, tail, log_name);<br \/>\n            m_today &#061; my_tm.tm_mday;<br \/>\n            m_count &#061; 0;  \/\/ \u91cd\u7f6e\u65e5\u5fd7\u884c\u6570<br \/>\n        }<br \/>\n        else<br \/>\n        {<br \/>\n            snprintf(new_log, 255, &#034;%s%s%s.%lld&#034;, dir_name, tail, log_name, m_count \/ m_split_lines);<br \/>\n        }<br \/>\n        m_fp &#061; fopen(new_log, &#034;a&#034;);  \/\/ \u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6<br \/>\n    }<br \/>\n    m_mutex.unlock();  \/\/ \u89e3\u9501\u65e5\u5fd7\u7cfb\u7edf<\/p>\n<p>    va_list valst;<br \/>\n    va_start(valst, format);  \/\/ \u5f00\u59cb\u5904\u7406\u53ef\u53d8\u53c2\u6570<\/p>\n<p>    string log_str;<br \/>\n    m_mutex.lock();<\/p>\n<p>    \/\/ \u5199\u5165\u65e5\u5fd7\u7684\u5177\u4f53\u65f6\u95f4<br \/>\n    int n &#061; snprintf(m_buf, 48, &#034;%d-%02d-%02d %02d:%02d:%02d.%06ld %s &#034;,<br \/>\n                     my_tm.tm_year &#043; 1900, my_tm.tm_mon &#043; 1, my_tm.tm_mday,<br \/>\n                     my_tm.tm_hour, my_tm.tm_min, my_tm.tm_sec, now.tv_usec, s);<\/p>\n<p>    \/\/ \u5199\u5165\u683c\u5f0f\u5316\u7684\u65e5\u5fd7\u4fe1\u606f<br \/>\n    int m &#061; vsnprintf(m_buf &#043; n, m_log_buf_size &#8211; n &#8211; 1, format, valst);<br \/>\n    m_buf[n &#043; m] &#061; &#039;\\\\n&#039;;  \/\/ \u6dfb\u52a0\u6362\u884c\u7b26<br \/>\n    m_buf[n &#043; m &#043; 1] &#061; &#039;\\\\0&#039;;<br \/>\n    log_str &#061; m_buf;  \/\/ \u5c06\u65e5\u5fd7\u5185\u5bb9\u5b58\u5165\u5b57\u7b26\u4e32<\/p>\n<p>    m_mutex.unlock();  \/\/ \u89e3\u9501<\/p>\n<p>    \/\/ \u5982\u679c\u662f\u5f02\u6b65\u6a21\u5f0f&#xff0c;\u65e5\u5fd7\u5199\u5165\u961f\u5217&#xff1b;\u5426\u5219\u76f4\u63a5\u5199\u5165\u6587\u4ef6<br \/>\n    if (m_is_async &amp;&amp; !m_log_queue-&gt;full())<br \/>\n    {<br \/>\n        m_log_queue-&gt;push(log_str);  \/\/ \u5c06\u65e5\u5fd7\u63a8\u5165\u963b\u585e\u961f\u5217<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        fputs(log_str.c_str(), m_fp);  \/\/ \u5199\u5165\u65e5\u5fd7\u6587\u4ef6<br \/>\n        m_mutex.unlock();<br \/>\n    }<\/p>\n<p>    va_end(valst);  \/\/ \u7ed3\u675f\u53ef\u53d8\u53c2\u6570\u5904\u7406<br \/>\n}<\/p>\n<h4>\u5237\u65b0\u65e5\u5fd7\u6587\u4ef6\u51fd\u6570&#xff1a;flush()<\/h4>\n<p>void Log::flush(void)<br \/>\n{<br \/>\n    m_mutex.lock();<br \/>\n    fflush(m_fp);  \/\/ \u5f3a\u5236\u5237\u65b0\u6587\u4ef6\u6d41\u7f13\u51b2\u533a<br \/>\n    m_mutex.unlock();<br \/>\n}<\/p>\n<h3>block_quene.h<\/h3>\n<p>block_queue \u7c7b\u662f\u4e00\u4e2a\u57fa\u4e8e\u5faa\u73af\u6570\u7ec4\u5b9e\u73b0\u7684\u963b\u585e\u961f\u5217&#xff0c;\u5177\u6709\u7ebf\u7a0b\u5b89\u5168\u7684\u7279\u6027&#xff0c;\u652f\u6301\u540c\u6b65\u548c\u8d85\u65f6\u7b49\u5f85\u7684 pop \u64cd\u4f5c\u3002\u5b83\u5728\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u6a21\u5f0f\u4e2d\u975e\u5e38\u5e38\u89c1&#xff0c;\u4e3b\u8981\u7528\u4e8e\u591a\u7ebf\u7a0b\u65e5\u5fd7\u7cfb\u7edf\u7b49\u573a\u666f<\/p>\n<h4>block_queue\u7c7b<\/h4>\n<h5>\u521d\u59cb\u5316block_queue<\/h5>\n<p>\u521d\u59cb\u5316\u4e00\u4e2a\u6700\u5927\u5bb9\u91cf\u4e3a max_size \u7684\u961f\u5217&#xff0c;\u9ed8\u8ba4\u503c\u662f 1000<\/p>\n<p>  block_queue(int max_size &#061; 1000)<br \/>\n    {<br \/>\n        if (max_size &lt;&#061; 0)\/\/\u5224\u65ad\u5927\u5c0f<br \/>\n        {<br \/>\n            exit(-1);<br \/>\n        }<\/p>\n<p>        m_max_size &#061; max_size;<br \/>\n        m_array &#061; new T[max_size];<br \/>\n        m_size &#061; 0;<br \/>\n        m_front &#061; -1;<br \/>\n        m_back &#061; -1;<br \/>\n    } <\/p>\n<h5>\u00a0\u6e05\u7a7a\u961f\u5217\u51fd\u6570&#xff1a;clear<\/h5>\n<p>  void clear()<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        m_size &#061; 0;<br \/>\n        m_front &#061; -1;<br \/>\n        m_back &#061; -1;<br \/>\n        m_mutex.unlock();<br \/>\n    } <\/p>\n<h5>\u6790\u6784\u51fd\u6570<\/h5>\n<p>\u91ca\u653e\u52a8\u6001\u5206\u914d\u7684\u6570\u7ec4 m_array \u8d44\u6e90<\/p>\n<p>    ~block_queue()<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        if (m_array !&#061; NULL)<br \/>\n            delete [] m_array;<\/p>\n<p>        m_mutex.unlock();<br \/>\n    } <\/p>\n<h5>\u5224\u65ad\u961f\u5217\u662f\u5426\u6ee1&#xff1a;full<\/h5>\n<p> bool full()<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        if (m_size &gt;&#061; m_max_size)\/\/\u5224\u65ad\u6761\u4ef6<br \/>\n        {<\/p>\n<p>            m_mutex.unlock();<br \/>\n            return true;<br \/>\n        }<br \/>\n        m_mutex.unlock();<br \/>\n        return false;<br \/>\n    } <\/p>\n<h5>\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a&#xff1a;empty<\/h5>\n<p>  bool empty()<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        if (0 &#061;&#061; m_size)<br \/>\n        {<br \/>\n            m_mutex.unlock();<br \/>\n            return true;<br \/>\n        }<br \/>\n        m_mutex.unlock();<br \/>\n        return false;<br \/>\n    } <\/p>\n<h5>\u00a0\u8fd4\u56de\u961f\u9996\u5143\u7d20&#xff1a;front<\/h5>\n<p>  bool front(T &amp;value)<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        if (0 &#061;&#061; m_size)<br \/>\n        {<br \/>\n            m_mutex.unlock();<br \/>\n            return false;<br \/>\n        }<br \/>\n        value &#061; m_array[m_front];<br \/>\n        m_mutex.unlock();<br \/>\n        return true;<br \/>\n    } <\/p>\n<h5>\u00a0\u8fd4\u56de\u961f\u5c3e\u5143\u7d20&#xff1a;back<\/h5>\n<p> bool back(T &amp;value)<br \/>\n    {<br \/>\n        m_mutex.lock();<br \/>\n        if (0 &#061;&#061; m_size)<br \/>\n        {<br \/>\n            m_mutex.unlock();<br \/>\n            return false;<br \/>\n        }<br \/>\n        value &#061; m_array[m_back];<br \/>\n        m_mutex.unlock();<br \/>\n        return true;<br \/>\n    } <\/p>\n<h5>\u6c42\u961f\u5217\u957f\u5ea6&#xff1a;size<\/h5>\n<p> int size()<br \/>\n    {<br \/>\n        int tmp &#061; 0;<\/p>\n<p>        m_mutex.lock();<br \/>\n        tmp &#061; m_size;<\/p>\n<p>        m_mutex.unlock();<br \/>\n        return tmp;<br \/>\n    }<\/p>\n<h5>\u6c42\u6700\u5927\u957f\u5ea6&#xff1a;max_size\u00a0<\/h5>\n<p>int max_size()<br \/>\n    {<br \/>\n        int tmp &#061; 0;<\/p>\n<p>        m_mutex.lock();<br \/>\n        tmp &#061; m_max_size;<\/p>\n<p>        m_mutex.unlock();<br \/>\n        return tmp;<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u4ee5\u4e0a\u90fd\u662f\u4e00\u4e9b\u5f88\u7b80\u5355\u7684\u51fd\u6570&#xff0c;\u5b9e\u73b0\u8bed\u53e5\u5c31\u4e00\u4e24\u53e5\u8bdd&#xff0c;\u4e3b\u8981\u8fd8\u662f\u4e3a\u4e86\u6a21\u5757\u5316\u8fd0\u884c\u8003\u8651&#xff0c;\u628a\u7b80\u5355\u529f\u80fd\u5c01\u88c5<\/span><\/p>\n<h5>\u5165\u961f (push)<\/h5>\n<ul>\n<li>\u5148\u68c0\u67e5\u662f\u5426\u961f\u5217\u6ee1\u4e86&#xff0c;\u6ee1\u4e86\u5c31\u8fd4\u56de false\u3002<\/li>\n<li>\u8ba1\u7b97 m_back \u7684\u65b0\u4f4d\u7f6e (m_back &#043; 1) % m_max_size&#xff0c;\u5b9e\u73b0\u5faa\u73af\u6570\u7ec4\u7ed3\u6784\u3002<\/li>\n<li>\u5b58\u5165\u6570\u636e&#xff0c;\u589e\u52a0 m_size\u3002<\/li>\n<li>\u901a\u8fc7 m_cond.broadcast() \u5524\u9192\u6240\u6709\u53ef\u80fd\u7b49\u5f85 pop \u7684\u7ebf\u7a0b<\/li>\n<\/ul>\n<h5><\/h5>\n<p> bool push(const T &amp;item)<br \/>\n    {<\/p>\n<p>        m_mutex.lock();<br \/>\n        if (m_size &gt;&#061; m_max_size)\/\/\u68c0\u67e5\u961f\u5217\u957f\u5ea6<br \/>\n        {<\/p>\n<p>            m_cond.broadcast();<br \/>\n            m_mutex.unlock();<br \/>\n            return false;<br \/>\n        }<\/p>\n<p>        m_back &#061; (m_back &#043; 1) % m_max_size;\/\/\u8ba1\u7b97\u65b0\u4f4d\u7f6e<br \/>\n        m_array[m_back] &#061; item;<\/p>\n<p>        m_size&#043;&#043;;<\/p>\n<p>        m_cond.broadcast();\/\/\u5524\u9192\u7ebf\u7a0b<br \/>\n        m_mutex.unlock();<br \/>\n        return true;<br \/>\n    } <\/p>\n<h5>\u51fa\u961f (pop)\u00a0<\/h5>\n<ul>\n<li>\u5982\u679c\u961f\u5217\u4e3a\u7a7a&#xff0c;\u5219\u8c03\u7528 m_cond.wait(m_mutex.get())&#xff0c;\u963b\u585e\u7b49\u5f85\u751f\u4ea7\u8005\u653e\u5165\u65b0\u5143\u7d20\u3002<\/li>\n<li>\u53d6\u51fa m_front &#043; 1 \u4f4d\u7f6e\u7684\u5143\u7d20&#xff0c;\u5e76\u66f4\u65b0 m_front&#xff0c;\u5b9e\u73b0\u5faa\u73af\u6570\u7ec4\u7ed3\u6784\u3002<\/li>\n<li>m_size&#8211;&#xff0c;\u91ca\u653e\u961f\u5217\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p>bool pop(T &amp;item)<br \/>\n    {<\/p>\n<p>        m_mutex.lock();<br \/>\n        while (m_size &lt;&#061; 0)<br \/>\n        {<\/p>\n<p>            if (!m_cond.wait(m_mutex.get()))<br \/>\n            {<br \/>\n                m_mutex.unlock();<br \/>\n                return false;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        m_front &#061; (m_front &#043; 1) % m_max_size;<br \/>\n        item &#061; m_array[m_front];<br \/>\n        m_size&#8211;;<br \/>\n        m_mutex.unlock();<br \/>\n        return true;<br \/>\n    } <\/p>\n<h5>\u8d85\u65f6\u51fa\u961f (pop with timeout)<\/h5>\n<ul>\n<li>\u5982\u679c\u961f\u5217\u4e3a\u7a7a&#xff0c;\u5148\u8ba1\u7b97\u8d85\u65f6\u65f6\u95f4 t&#xff08;\u57fa\u4e8e gettimeofday()&#xff09;\u3002<\/li>\n<li>\u8c03\u7528 m_cond.timewait(m_mutex.get(), t)&#xff0c;\u5982\u679c\u8d85\u65f6\u4ecd\u7136\u4e3a\u7a7a&#xff0c;\u8fd4\u56de false\u3002<\/li>\n<li>\u5426\u5219\u6267\u884c\u6b63\u5e38\u7684 pop \u903b\u8f91\u3002<\/li>\n<\/ul>\n<p>bool pop(T &amp;item, int ms_timeout)<br \/>\n    {<br \/>\n        struct timespec t &#061; {0, 0};<br \/>\n        struct timeval now &#061; {0, 0};<br \/>\n        gettimeofday(&amp;now, NULL);<br \/>\n        m_mutex.lock();<br \/>\n        if (m_size &lt;&#061; 0)<br \/>\n        {<br \/>\n            t.tv_sec &#061; now.tv_sec &#043; ms_timeout \/ 1000;<br \/>\n            t.tv_nsec &#061; (ms_timeout % 1000) * 1000;<br \/>\n            if (!m_cond.timewait(m_mutex.get(), t))<br \/>\n            {<br \/>\n                m_mutex.unlock();<br \/>\n                return false;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        if (m_size &lt;&#061; 0)<br \/>\n        {<br \/>\n            m_mutex.unlock();<br \/>\n            return false;<br \/>\n        }<\/p>\n<p>        m_front &#061; (m_front &#043; 1) % m_max_size;<br \/>\n        item &#061; m_array[m_front];<br \/>\n        m_size&#8211;;<br \/>\n        m_mutex.unlock();<br \/>\n        return true;<br \/>\n    }<\/p>\n<h2>\u00a0Timer\u6587\u4ef6\u5939<\/h2>\n<h3>README<\/h3>\n<p>\u5b9a\u65f6\u5668\u5904\u7406\u975e\u6d3b\u52a8\u8fde\u63a5<\/p>\n<p>\u7531\u4e8e\u975e\u6d3b\u8dc3\u8fde\u63a5\u5360\u7528\u4e86\u8fde\u63a5\u8d44\u6e90&#xff0c;\u4e25\u91cd\u5f71\u54cd\u670d\u52a1\u5668\u7684\u6027\u80fd&#xff0c;\u901a\u8fc7\u5b9e\u73b0\u4e00\u4e2a\u670d\u52a1\u5668\u5b9a\u65f6\u5668&#xff0c;\u5904\u7406\u8fd9\u79cd\u975e\u6d3b\u8dc3\u8fde\u63a5&#xff0c;\u91ca\u653e\u8fde\u63a5\u8d44\u6e90\u3002\u5229\u7528alarm\u51fd\u6570\u5468\u671f\u6027\u5730\u89e6\u53d1SIGALRM\u4fe1\u53f7,\u8be5\u4fe1\u53f7\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u5229\u7528\u7ba1\u9053\u901a\u77e5\u4e3b\u5faa\u73af\u6267\u884c\u5b9a\u65f6\u5668\u94fe\u8868\u4e0a\u7684\u5b9a\u65f6\u4efb\u52a1.<\/p>\n<ul>\n<li>\u7edf\u4e00\u4e8b\u4ef6\u6e90<\/li>\n<li>\u57fa\u4e8e\u5347\u5e8f\u94fe\u8868\u7684\u5b9a\u65f6\u5668<\/li>\n<li>\u5904\u7406\u975e\u6d3b\u52a8\u8fde\u63a5<\/li>\n<\/ul>\n<h3>lst_timer.h<\/h3>\n<p>\u5934\u6587\u4ef6\u5b9a\u4e49&#xff0c;\u6ca1\u6709\u591a\u5c11\u5185\u5bb9&#xff0c;\u8be6\u60c5\u770b\u63a5\u4e0b\u6765\u7684lst_timer.cpp\u6587\u4ef6<\/p>\n<p>#ifndef LST_TIMER<br \/>\n#define LST_TIMER<\/p>\n<p>#include &lt;unistd.h&gt;<br \/>\n#include &lt;signal.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/epoll.h&gt;<br \/>\n#include &lt;fcntl.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;netinet\/in.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<br \/>\n#include &lt;assert.h&gt;<br \/>\n#include &lt;sys\/stat.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/mman.h&gt;<br \/>\n#include &lt;stdarg.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;sys\/uio.h&gt;<\/p>\n<p>#include &lt;time.h&gt;<br \/>\n#include &#034;..\/log\/log.h&#034;<\/p>\n<p>class util_timer;<\/p>\n<p>struct client_data<br \/>\n{<br \/>\n    sockaddr_in address;<br \/>\n    int sockfd;<br \/>\n    util_timer *timer;<br \/>\n};<\/p>\n<p>class util_timer<br \/>\n{<br \/>\npublic:<br \/>\n    util_timer() : prev(NULL), next(NULL) {}<\/p>\n<p>public:<br \/>\n    time_t expire;<\/p>\n<p>    void (* cb_func)(client_data *);<br \/>\n    client_data *user_data;<br \/>\n    util_timer *prev;<br \/>\n    util_timer *next;<br \/>\n};<\/p>\n<p>class sort_timer_lst<br \/>\n{<br \/>\npublic:<br \/>\n    sort_timer_lst();<br \/>\n    ~sort_timer_lst();<\/p>\n<p>    void add_timer(util_timer *timer);<br \/>\n    void adjust_timer(util_timer *timer);<br \/>\n    void del_timer(util_timer *timer);<br \/>\n    void tick();<\/p>\n<p>private:<br \/>\n    void add_timer(util_timer *timer, util_timer *lst_head);<\/p>\n<p>    util_timer *head;<br \/>\n    util_timer *tail;<br \/>\n};<\/p>\n<p>class Utils<br \/>\n{<br \/>\npublic:<br \/>\n    Utils() {}<br \/>\n    ~Utils() {}<\/p>\n<p>    void init(int timeslot);<\/p>\n<p>    \/\/\u5bf9\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bbe\u7f6e\u975e\u963b\u585e<br \/>\n    int setnonblocking(int fd);<\/p>\n<p>    \/\/\u5c06\u5185\u6838\u4e8b\u4ef6\u8868\u6ce8\u518c\u8bfb\u4e8b\u4ef6&#xff0c;ET\u6a21\u5f0f&#xff0c;\u9009\u62e9\u5f00\u542fEPOLLONESHOT<br \/>\n    void addfd(int epollfd, int fd, bool one_shot, int TRIGMode);<\/p>\n<p>    \/\/\u4fe1\u53f7\u5904\u7406\u51fd\u6570<br \/>\n    static void sig_handler(int sig);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u4fe1\u53f7\u51fd\u6570<br \/>\n    void addsig(int sig, void(handler)(int), bool restart &#061; true);<\/p>\n<p>    \/\/\u5b9a\u65f6\u5904\u7406\u4efb\u52a1&#xff0c;\u91cd\u65b0\u5b9a\u65f6\u4ee5\u4e0d\u65ad\u89e6\u53d1SIGALRM\u4fe1\u53f7<br \/>\n    void timer_handler();<\/p>\n<p>    void show_error(int connfd, const char *info);<\/p>\n<p>public:<br \/>\n    static int *u_pipefd;<br \/>\n    sort_timer_lst m_timer_lst;<br \/>\n    static int u_epollfd;<br \/>\n    int m_TIMESLOT;<br \/>\n};<\/p>\n<p>void cb_func(client_data *user_data);<\/p>\n<p>#endif <\/p>\n<h3 style=\"background-color:transparent\">lst_timer.cpp<\/h3>\n<h4>\u00a0\u6784\u9020\u51fd\u6570<\/h4>\n<p>sort_timer_lst::sort_timer_lst()\/\/\u628a\u961f\u5217\u5934\u5c3e\u6e05\u96f6<br \/>\n{<br \/>\n    head &#061; NULL;<br \/>\n    tail &#061; NULL;<br \/>\n} <\/p>\n<h4>\u6790\u6784\u51fd\u6570<\/h4>\n<p>\u5faa\u73af\u91ca\u653e\u961f\u5217<\/p>\n<p>sort_timer_lst::~sort_timer_lst()<br \/>\n{<br \/>\n    util_timer *tmp &#061; head;<br \/>\n    while (tmp)<br \/>\n    {<br \/>\n        head &#061; tmp-&gt;next;<br \/>\n        delete tmp;<br \/>\n        tmp &#061; head;<br \/>\n    }<br \/>\n} <\/p>\n<h4>\u6dfb\u52a0\u8ba1\u65f6\u5668&#xff1a;add_timer\u00a0<\/h4>\n<p>\/ \u5411\u5b9a\u65f6\u5668\u94fe\u8868\u6dfb\u52a0\u5b9a\u65f6\u5668<br \/>\nvoid sort_timer_lst::add_timer(util_timer *timer)<br \/>\n{<br \/>\n    if (!timer) \/\/ \u5982\u679c\u5b9a\u65f6\u5668\u4e3a\u7a7a&#xff0c;\u76f4\u63a5\u8fd4\u56de<br \/>\n    {<br \/>\n        return;<br \/>\n    }<br \/>\n    if (!head) \/\/ \u5982\u679c\u94fe\u8868\u4e3a\u7a7a&#xff0c;\u5c06\u5b9a\u65f6\u5668\u8bbe\u4e3a\u5934\u5c3e<br \/>\n    {<br \/>\n        head &#061; tail &#061; timer;<br \/>\n        return;<br \/>\n    }<br \/>\n    \/\/ \u5982\u679c\u65b0\u5b9a\u65f6\u5668\u7684\u8fc7\u671f\u65f6\u95f4\u5c0f\u4e8e\u5f53\u524d\u5934\u8282\u70b9\u7684\u8fc7\u671f\u65f6\u95f4<br \/>\n    if (timer-&gt;expire &lt; head-&gt;expire)<br \/>\n    {<br \/>\n        timer-&gt;next &#061; head; \/\/ \u65b0\u5b9a\u65f6\u5668\u6210\u4e3a\u65b0\u7684\u5934\u8282\u70b9<br \/>\n        head-&gt;prev &#061; timer; \/\/ \u65e7\u5934\u8282\u70b9\u7684\u524d\u6307\u9488\u6307\u5411\u65b0\u5b9a\u65f6\u5668<br \/>\n        head &#061; timer; \/\/ \u66f4\u65b0\u5934\u6307\u9488<br \/>\n        return;<br \/>\n    }<br \/>\n    add_timer(timer, head); \/\/ \u5426\u5219&#xff0c;\u5c06\u5b9a\u65f6\u5668\u63d2\u5165\u5230\u5408\u9002\u7684\u4f4d\u7f6e<br \/>\n}  <\/p>\n<h4>\u8c03\u6574\u5b9a\u65f6\u5668\u7684\u4f4d\u7f6e&#xff1a;adjust_timer<\/h4>\n<p>\/\/ \u8c03\u6574\u5b9a\u65f6\u5668\u7684\u4f4d\u7f6e<br \/>\nvoid sort_timer_lst::adjust_timer(util_timer *timer)<br \/>\n{<br \/>\n    if (!timer) \/\/ \u5982\u679c\u5b9a\u65f6\u5668\u4e3a\u7a7a&#xff0c;\u8fd4\u56de<br \/>\n    {<br \/>\n        return;<br \/>\n    }<br \/>\n    util_timer *tmp &#061; timer-&gt;next; \/\/ \u83b7\u53d6\u4e0b\u4e00\u4e2a\u5b9a\u65f6\u5668<br \/>\n    \/\/ \u5982\u679c\u5b9a\u65f6\u5668\u672c\u8eab\u5df2\u7ecf\u5728\u6b63\u786e\u7684\u4f4d\u7f6e&#xff0c;\u8fd4\u56de<br \/>\n    if (!tmp || (timer-&gt;expire &lt; tmp-&gt;expire))<br \/>\n    {<br \/>\n        return;<br \/>\n    }<br \/>\n    \/\/ \u5982\u679c\u662f\u5934\u5b9a\u65f6\u5668&#xff0c;\u79fb\u52a8\u5934\u6307\u9488\u5e76\u91cd\u65b0\u63d2\u5165<br \/>\n    if (timer &#061;&#061; head)<br \/>\n    {<br \/>\n        head &#061; head-&gt;next; \/\/ \u79fb\u52a8\u5934\u6307\u9488<br \/>\n        head-&gt;prev &#061; NULL; \/\/ \u66f4\u65b0\u5934\u6307\u9488\u7684\u524d\u6307\u9488<br \/>\n        timer-&gt;next &#061; NULL; \/\/ \u5c06\u5b9a\u65f6\u5668\u7684\u4e0b\u4e00\u4e2a\u6307\u9488\u7f6e\u4e3a\u7a7a<br \/>\n        add_timer(timer, head); \/\/ \u91cd\u65b0\u63d2\u5165<br \/>\n    }<br \/>\n    else \/\/ \u5426\u5219&#xff0c;\u94fe\u8868\u4e2d\u95f4\u6216\u5c3e\u90e8\u7684\u5b9a\u65f6\u5668<br \/>\n    {<br \/>\n        timer-&gt;prev-&gt;next &#061; timer-&gt;next; \/\/ \u65ad\u5f00\u5f53\u524d\u5b9a\u65f6\u5668<br \/>\n        timer-&gt;next-&gt;prev &#061; timer-&gt;prev; \/\/ \u4ece\u94fe\u8868\u4e2d\u79fb\u9664<br \/>\n        add_timer(timer, timer-&gt;next); \/\/ \u91cd\u65b0\u63d2\u5165<br \/>\n    }<br \/>\n}   <\/p>\n<h4>\u5b9a\u65f6\u5668\u68c0\u6d4b\u51fd\u6570&#xff1a;tick<\/h4>\n<p>\u904d\u5386\u5217\u8868\u68c0\u6d4b\u8ba1\u65f6\u5668\u662f\u5426\u8fc7\u671f&#xff0c;\u8c03\u7528\u56de\u8c03\u51fd\u6570&#xff0c;\u5220\u9664\u5df2\u8fc7\u671f\u8ba1\u65f6\u5668<\/p>\n<p>\/\/ \u5b9a\u65f6\u5668\u68c0\u6d4b&#xff0c;\u5904\u7406\u5230\u671f\u7684\u5b9a\u65f6\u5668<br \/>\nvoid sort_timer_lst::tick()<br \/>\n{<br \/>\n    if (!head) \/\/ \u5982\u679c\u94fe\u8868\u4e3a\u7a7a&#xff0c;\u8fd4\u56de<br \/>\n    {<br \/>\n        return;<br \/>\n    }  <\/p>\n<p>    time_t cur &#061; time(NULL); \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4<br \/>\n    util_timer *tmp &#061; head; \/\/ \u4ece\u5934\u8282\u70b9\u5f00\u59cb\u68c0\u67e5<br \/>\n    while (tmp) \/\/ \u904d\u5386\u94fe\u8868<br \/>\n    {<br \/>\n        if (cur &lt; tmp-&gt;expire) \/\/ \u5982\u679c\u5f53\u524d\u65f6\u95f4\u8fd8\u672a\u5230\u671f<br \/>\n        {<br \/>\n            break; \/\/ \u4e0d\u518d\u68c0\u67e5\u540e\u9762\u7684\u5b9a\u65f6\u5668<br \/>\n        }<br \/>\n        tmp-&gt;cb_func(tmp-&gt;user_data); \/\/ \u6267\u884c\u56de\u8c03\u51fd\u6570<br \/>\n        head &#061; tmp-&gt;next; \/\/ \u66f4\u65b0\u5934\u6307\u9488<br \/>\n        if (head) \/\/ \u5982\u679c\u5934\u6307\u9488\u4e0d\u4e3a\u7a7a<br \/>\n        {<br \/>\n            head-&gt;prev &#061; NULL; \/\/ \u66f4\u65b0\u5934\u8282\u70b9\u7684\u524d\u6307\u9488<br \/>\n        }<br \/>\n        delete tmp; \/\/ \u5220\u9664\u5df2\u5230\u671f\u7684\u5b9a\u65f6\u5668<br \/>\n        tmp &#061; head; \/\/ \u7ee7\u7eed\u904d\u5386<br \/>\n    }<br \/>\n}  <\/p>\n<h4>\u00a0\u5411\u5df2\u6392\u5e8f\u7684\u94fe\u8868\u4e2d\u63d2\u5165\u5b9a\u65f6\u5668\u51fd\u6570&#xff1a;add_timer<\/h4>\n<p>\u904d\u5386\u5217\u8868\u5bfb\u627e\u5408\u9002\u4f4d\u7f6e&#xff0c;\u63d2\u5165\u4f4d\u7f6e&#xff0c;\u66f4\u65b0\u5217\u8868<\/p>\n<p>\/\/ \u5411\u5df2\u6392\u5e8f\u7684\u94fe\u8868\u4e2d\u63d2\u5165\u5b9a\u65f6\u5668<br \/>\nvoid sort_timer_lst::add_timer(util_timer *timer, util_timer *lst_head)<br \/>\n{<br \/>\n    util_timer *prev &#061; lst_head; \/\/ \u8bb0\u5f55\u524d\u4e00\u4e2a\u8282\u70b9<br \/>\n    util_timer *tmp &#061; prev-&gt;next; \/\/ \u8bb0\u5f55\u5f53\u524d\u8282\u70b9<br \/>\n    \/\/ \u904d\u5386\u5bfb\u627e\u5408\u9002\u7684\u63d2\u5165\u4f4d\u7f6e<br \/>\n    while (tmp)<br \/>\n    {<br \/>\n        if (timer-&gt;expire &lt; tmp-&gt;expire) \/\/ \u5982\u679c\u65b0\u5b9a\u65f6\u5668\u8fc7\u671f\u65f6\u95f4\u66f4\u65e9<br \/>\n        {<br \/>\n            prev-&gt;next &#061; timer; \/\/ \u63d2\u5165\u65b0\u5b9a\u65f6\u5668<br \/>\n            timer-&gt;next &#061; tmp; \/\/ \u66f4\u65b0\u65b0\u5b9a\u65f6\u5668\u7684\u4e0b\u4e00\u4e2a\u6307\u9488<br \/>\n            tmp-&gt;prev &#061; timer; \/\/ \u66f4\u65b0\u5f53\u524d\u8282\u70b9\u7684\u524d\u6307\u9488<br \/>\n            timer-&gt;prev &#061; prev; \/\/ \u66f4\u65b0\u524d\u4e00\u4e2a\u8282\u70b9\u7684\u540e\u6307\u9488<br \/>\n            break; \/\/ \u9000\u51fa\u5faa\u73af<br \/>\n        }<br \/>\n        prev &#061; tmp; \/\/ \u66f4\u65b0\u524d\u4e00\u4e2a\u8282\u70b9<br \/>\n        tmp &#061; tmp-&gt;next; \/\/ \u66f4\u65b0\u5f53\u524d\u8282\u70b9<br \/>\n    }<br \/>\n    \/\/ \u5982\u679c\u6ca1\u6709\u627e\u5230\u5408\u9002\u7684\u4f4d\u7f6e&#xff0c;\u63d2\u5165\u5230\u5c3e\u90e8<br \/>\n    if (!tmp)<br \/>\n    {<br \/>\n        prev-&gt;next &#061; timer; \/\/ \u66f4\u65b0\u524d\u4e00\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u6307\u9488<br \/>\n        timer-&gt;prev &#061; prev; \/\/ \u7ef4\u6301\u53cc\u5411\u94fe\u63a5<br \/>\n        timer-&gt;next &#061; NULL; \/\/ \u66f4\u65b0\u65b0\u5b9a\u65f6\u5668\u7684\u4e0b\u4e00\u4e2a\u6307\u9488<br \/>\n        tail &#061; timer; \/\/ \u66f4\u65b0\u5c3e\u6307\u9488<br \/>\n    }<br \/>\n}   <\/p>\n<h4>\u00a0Utils \u7c7b\u7684\u5b9a\u4e49\u4e0e\u5b9e\u73b0\u00a0\u00a0<\/h4>\n<h5>\u5b9a\u4e49\u51fd\u6570&#xff1a;init<\/h5>\n<p>void Utils::init(int timeslot)<br \/>\n{<br \/>\n    m_TIMESLOT &#061; timeslot; \/\/ \u521d\u59cb\u5316\u65f6\u95f4\u69fd<br \/>\n}   <\/p>\n<h5>\u00a0\u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e\u51fd\u6570&#xff1a;\u00a0setnonblocking<\/h5>\n<p>\/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e<br \/>\nint Utils::setnonblocking(int fd)<br \/>\n{<br \/>\n    int old_option &#061; fcntl(fd, F_GETFL); \/\/ \u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u9009\u9879<br \/>\n    int new_option &#061; old_option | O_NONBLOCK; \/\/ \u8bbe\u7f6e\u975e\u963b\u585e\u6807\u5fd7<br \/>\n    fcntl(fd, F_SETFL, new_option); \/\/ \u5e94\u7528\u65b0\u7684\u6807\u5fd7<br \/>\n    return old_option; \/\/ \u8fd4\u56de\u539f\u6765\u7684\u9009\u9879<br \/>\n}   <\/p>\n<h5>\u00a0\u5411\u5185\u6838\u4e8b\u4ef6\u8868\u6ce8\u518c\u8bfb\u4e8b\u4ef6\u51fd\u6570&#xff1a;addfd<\/h5>\n<p>\/\/ \u5411\u5185\u6838\u4e8b\u4ef6\u8868\u6ce8\u518c\u8bfb\u4e8b\u4ef6&#xff0c;ET\u6a21\u5f0f&#xff0c;\u9009\u62e9\u5f00\u542fEPOLLONESHOT<br \/>\nvoid Utils::addfd(int epollfd, int fd, bool one_shot, int TRIGMode)<br \/>\n{<br \/>\n    epoll_event event;<br \/>\n    event.data.fd &#061; fd; \/\/ \u8bbe\u7f6e\u4e8b\u4ef6\u6570\u636e\u4e3a\u6587\u4ef6\u63cf\u8ff0\u7b26  <\/p>\n<p>    \/\/ \u6839\u636e\u89e6\u53d1\u6a21\u5f0f\u9009\u62e9\u4e8b\u4ef6\u7c7b\u578b<br \/>\n    if (1 &#061;&#061; TRIGMode)<br \/>\n        event.events &#061; EPOLLIN | EPOLLET | EPOLLRDHUP; \/\/ \u8fb9\u7f18\u89e6\u53d1<br \/>\n    else<br \/>\n        event.events &#061; EPOLLIN | EPOLLRDHUP; \/\/ \u6c34\u5e73\u89e6\u53d1  <\/p>\n<p>    if (one_shot) \/\/ \u5982\u679c\u542f\u7528\u5355\u6b21\u89e6\u53d1<br \/>\n        event.events |&#061; EPOLLONESHOT; \/\/ \u8bbe\u7f6e\u5355\u6b21\u89e6\u53d1\u6807\u5fd7  <\/p>\n<p>    epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &amp;event); \/\/ \u6ce8\u518c\u4e8b\u4ef6<br \/>\n    setnonblocking(fd); \/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e<br \/>\n}  <\/p>\n<h5>\u00a0\u4fe1\u53f7\u5904\u7406\u51fd\u6570&#xff1a;sig_handler<\/h5>\n<p>\/\/ \u4fe1\u53f7\u5904\u7406\u51fd\u6570<br \/>\nvoid Utils::sig_handler(int sig)<br \/>\n{<br \/>\n    \/\/ \u4e3a\u4fdd\u8bc1\u51fd\u6570\u53ef\u91cd\u5165&#xff0c;\u4fdd\u7559\u539f\u6765\u7684 errno<br \/>\n    int save_errno &#061; errno;<br \/>\n    int msg &#061; sig;<br \/>\n    send(u_pipefd[1], (char *)&amp;msg, 1, 0); \/\/ \u53d1\u9001\u4fe1\u53f7\u4fe1\u606f\u5230\u7ba1\u9053<br \/>\n    errno &#061; save_errno; \/\/ \u8fd8\u539f errno<br \/>\n}   <\/p>\n<h5>\u8bbe\u7f6e\u4fe1\u53f7\u51fd\u6570&#xff1a;addsig\u00a0<\/h5>\n<p>\/\/ \u8bbe\u7f6e\u4fe1\u53f7\u51fd\u6570<br \/>\nvoid Utils::addsig(int sig, void(handler)(int), bool restart)<br \/>\n{<br \/>\n    struct sigaction sa;<br \/>\n    memset(&amp;sa, &#039;\\\\0&#039;, sizeof(sa)); \/\/ \u6e05\u96f6\u4fe1\u53f7\u96c6<br \/>\n    sa.sa_handler &#061; handler; \/\/ \u8bbe\u7f6e\u5904\u7406\u51fd\u6570<br \/>\n    if (restart)<br \/>\n        sa.sa_flags |&#061; SA_RESTART; \/\/ \u8bbe\u7f6e\u91cd\u542f\u6807\u5fd7<br \/>\n    sigfillset(&amp;sa.sa_mask); \/\/ \u586b\u5145\u4fe1\u53f7\u96c6<br \/>\n    assert(sigaction(sig, &amp;sa, NULL) !&#061; -1); \/\/ \u6ce8\u518c\u4fe1\u53f7\u5904\u7406\u51fd\u6570<br \/>\n}   <\/p>\n<h5>\u5b9a\u65f6\u5904\u7406\u4efb\u52a1\u51fd\u6570&#xff1a;timer_handler\u00a0<\/h5>\n<p>\/\/ \u5b9a\u65f6\u5904\u7406\u4efb\u52a1&#xff0c;\u89e6\u53d1 SIGALRM \u4fe1\u53f7<br \/>\nvoid Utils::timer_handler()<br \/>\n{<br \/>\n    m_timer_lst.tick(); \/\/ \u5904\u7406\u5b9a\u65f6\u5668<br \/>\n    alarm(m_TIMESLOT); \/\/ \u91cd\u65b0\u8bbe\u5b9a\u5b9a\u65f6\u5668<br \/>\n}   <\/p>\n<h5>\u00a0\u53d1\u9001\u9519\u8bef\u4fe1\u606f\u5e76\u5173\u95ed\u8fde\u63a5\u51fd\u6570&#xff1a;show_error<\/h5>\n<p>\/\/ \u53d1\u9001\u9519\u8bef\u4fe1\u606f\u5e76\u5173\u95ed\u8fde\u63a5<br \/>\nvoid Utils::show_error(int connfd, const char *info)<br \/>\n{<br \/>\n    send(connfd, info, strlen(info), 0); \/\/ \u53d1\u9001\u9519\u8bef\u4fe1\u606f<br \/>\n    close(connfd); \/\/ \u5173\u95ed\u8fde\u63a5<br \/>\n}   <\/p>\n<h5 style=\"background-color:transparent\">\u00a0\u5ba2\u6237\u7aef\u6570\u636e\u7684\u56de\u8c03\u51fd\u6570 :cb_func<\/h5>\n<p>\/\/ \u9759\u6001\u6210\u5458\u53d8\u91cf\u7684\u521d\u59cb\u5316<br \/>\nint *Utils::u_pipefd &#061; 0; \/\/ \u7528\u4e8e\u5904\u7406\u4fe1\u53f7\u7684\u7ba1\u9053<br \/>\nint Utils::u_epollfd &#061; 0; \/\/ epoll \u6587\u4ef6\u63cf\u8ff0\u7b26  <\/p>\n<p>\/\/ \u5ba2\u6237\u7aef\u6570\u636e\u7684\u56de\u8c03\u51fd\u6570<br \/>\nvoid cb_func(client_data *user_data)<br \/>\n{<br \/>\n    epoll_ctl(Utils::u_epollfd, EPOLL_CTL_DEL, user_data-&gt;sockfd, 0); \/\/ \u4ece\u4e8b\u4ef6\u8868\u4e2d\u5220\u9664\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n    assert(user_data); \/\/ \u786e\u4fdd\u7528\u6237\u6570\u636e\u5b58\u5728<br \/>\n    close(user_data-&gt;sockfd); \/\/ \u5173\u95ed\u5957\u63a5\u5b57<br \/>\n    http_conn::m_user_count&#8211;; \/\/ \u51cf\u5c11\u6d3b\u52a8\u7528\u6237\u8ba1\u6570<br \/>\n}   <\/p>\n<h2>\u603b\u7ed3&#xff1a;<\/h2>\n<p>\u81f3\u6b64&#xff0c;TingWebServer\u7684\u6240\u6709\u4ee3\u7801\u90fd\u7559\u51fa\u4e86\u6ce8\u91ca\u548c\u51fd\u6570\u89e3\u91ca&#xff0c;\u4e0b\u4e00\u7bc7\u5c06\u4f1a\u4ece\u670d\u52a1\u5668\u5f00\u59cb\u8fd0\u884c\u5230\u53d1\u9001\u8bf7\u6c42\u5230\u6700\u540e\u7684\u670d\u52a1\u5668\u5173\u95ed&#xff0c;\u5e26\u7740\u6240\u6709\u51fd\u6570\u540d\u8fc7\u4e00\u904d\u5177\u4f53\u7684\u670d\u52a1\u5668\u8fd0\u884c\u6d41\u7a0b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e49\u6b21\uff0c\u6536\u85cf45\u6b21\u3002\/ \u521d\u59cb\u5316\u65f6\u95f4\u69fd\u81f3\u6b64\uff0cTingWebServer\u7684\u6240\u6709\u4ee3\u7801\u90fd\u7559\u51fa\u4e86\u6ce8\u91ca\u548c\u51fd\u6570\u89e3\u91ca\uff0c\u4e0b\u4e00\u7bc7\u5c06\u4f1a\u4ece\u670d\u52a1\u5668\u5f00\u59cb\u8fd0\u884c\u5230\u53d1\u9001\u8bf7\u6c42\u5230\u6700\u540e\u7684\u670d\u52a1\u5668\u5173\u95ed\uff0c\u5e26\u7740\u6240\u6709\u51fd\u6570\u540d\u8fc7\u4e00\u904d\u5177\u4f53\u7684\u670d\u52a1\u5668\u8fd0\u884c\u6d41\u7a0b\u3002<\/p>\n","protected":false},"author":2,"featured_media":17919,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1351,43,44],"topic":[],"class_list":["post-17920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-tingwebserver","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \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\/17920.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e49\u6b21\uff0c\u6536\u85cf45\u6b21\u3002\/ \u521d\u59cb\u5316\u65f6\u95f4\u69fd\u81f3\u6b64\uff0cTingWebServer\u7684\u6240\u6709\u4ee3\u7801\u90fd\u7559\u51fa\u4e86\u6ce8\u91ca\u548c\u51fd\u6570\u89e3\u91ca\uff0c\u4e0b\u4e00\u7bc7\u5c06\u4f1a\u4ece\u670d\u52a1\u5668\u5f00\u59cb\u8fd0\u884c\u5230\u53d1\u9001\u8bf7\u6c42\u5230\u6700\u540e\u7684\u670d\u52a1\u5668\u5173\u95ed\uff0c\u5e26\u7740\u6240\u6709\u51fd\u6570\u540d\u8fc7\u4e00\u904d\u5177\u4f53\u7684\u670d\u52a1\u5668\u8fd0\u884c\u6d41\u7a0b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/17920.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T16:23:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418162313-68027c713989a.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=\"15 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17920.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/17920.html\",\"name\":\"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T16:23:14+00:00\",\"dateModified\":\"2025-04-18T16:23:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/17920.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/17920.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17920.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03\"}]},{\"@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":"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \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\/17920.html","og_locale":"zh_CN","og_type":"article","og_title":"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e49\u6b21\uff0c\u6536\u85cf45\u6b21\u3002\/ \u521d\u59cb\u5316\u65f6\u95f4\u69fd\u81f3\u6b64\uff0cTingWebServer\u7684\u6240\u6709\u4ee3\u7801\u90fd\u7559\u51fa\u4e86\u6ce8\u91ca\u548c\u51fd\u6570\u89e3\u91ca\uff0c\u4e0b\u4e00\u7bc7\u5c06\u4f1a\u4ece\u670d\u52a1\u5668\u5f00\u59cb\u8fd0\u884c\u5230\u53d1\u9001\u8bf7\u6c42\u5230\u6700\u540e\u7684\u670d\u52a1\u5668\u5173\u95ed\uff0c\u5e26\u7740\u6240\u6709\u51fd\u6570\u540d\u8fc7\u4e00\u904d\u5177\u4f53\u7684\u670d\u52a1\u5668\u8fd0\u884c\u6d41\u7a0b\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/17920.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T16:23:14+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418162313-68027c713989a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"15 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/17920.html","url":"https:\/\/www.wsisp.com\/helps\/17920.html","name":"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T16:23:14+00:00","dateModified":"2025-04-18T16:23:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/17920.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/17920.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/17920.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"TingWebserver\u670d\u52a1\u5668\u4ee3\u7801\u89e3\u8bfb03"}]},{"@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\/17920","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=17920"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17920\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/17919"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=17920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=17920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=17920"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=17920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}