{"id":22680,"date":"2025-04-19T06:13:31","date_gmt":"2025-04-18T22:13:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/22680.html"},"modified":"2025-04-19T06:13:31","modified_gmt":"2025-04-18T22:13:31","slug":"linux%e9%ab%98%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%bc%80%e5%8f%91%ef%bc%88%e5%85%ad%ef%bc%89webserver%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%a1%b9%e7%9b%ae-%e4%b8%aa%e4%ba%ba%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/22680.html","title":{"rendered":"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3"},"content":{"rendered":"<h3>1 \u9879\u76ee\u672c\u8eab\u6784\u67b6<\/h3>\n<h4>1.1 \u5927\u6846\u67b6\u5b9e\u73b0<\/h4>\n<p>\u4e3a\u4ec0\u4e48\u8981\u7528\u7ebf\u7a0b\u6c60\u548c\u4e92\u65a5\u9501&#xff1f;<\/p>\n<p>&#xff1a;\u521b\u5efa\u7ebf\u7a0b&amp;\u9500\u6bc1\u7ebf\u7a0b\u4f1a\u8017\u8d39\u8ba1\u7b97\u673a\u8d44\u6e90&#xff0c;\u91c7\u7528\u7ebf\u7a0b\u6c60\u53ef\u4ee5\u89e3\u51b3\u8ba1\u7b97\u673a\u65e0\u9650\u5236\u521b\u5efa\u7ebf\u7a0b\u7684\u60c5\u51b5\u3002\u5f53\u6709\u65b0\u7684\u4efb\u52a1\u5230\u6765\u65f6\u53ef\u4ee5\u53bb\u7ebf\u7a0b\u6c60\u4e2d\u5bfb\u627e\u7a7a\u95f2\u7ebf\u7a0b\u53bb\u670d\u52a1\u3002\u9501\u673a\u5236\u7528\u6765\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"408\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221327-6802ce877f085.png\" width=\"928\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"504\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221327-6802ce87acb88.png\" width=\"928\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1108\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221327-6802ce87e0431.png\" width=\"928\" \/><\/p>\n<\/p>\n<h4>1.2 \u5404\u4e2a\u6a21\u5757\u5177\u4f53\u4ee3\u7801&#xff08;\u6846\u67b6&#xff09;<\/h4>\n<h5>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e92\u65a5\u9501 &#8212; locker.h<\/h5>\n<p>#ifndef LOCKER_H<br \/>\n#define LOCKER_H<\/p>\n<p>#include &lt;pthread.h&gt;<br \/>\n#include &lt;exception&gt;    \/\/ \u5f02\u5e38<br \/>\n#include &lt;semaphore.h&gt;<\/p>\n<p>\/\/ \u7ebf\u7a0b\u540c\u6b65\u673a\u5236\u5206\u88c5\u7c7b<\/p>\n<p>\/\/ \u4e92\u65a5\u9501\u7c7b<br \/>\nclass locker {<br \/>\npublic:<br \/>\n    \/\/ \u6784\u9020\u51fd\u6570<br \/>\n    locker(){<br \/>\n        if(pthread_mutex_init(&amp;m_mutex, NULL) !&#061; 0){<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u4e0a\u9501<br \/>\n    bool lock() {<br \/>\n        return pthread_mutex_lock(&amp;m_mutex) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    \/\/ \u89e3\u9501<br \/>\n    bool unlock() {<br \/>\n        return pthread_mutex_unlock(&amp;m_mutex) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    pthread_mutex_t * get() {<br \/>\n        return &amp;m_mutex;<br \/>\n    }<\/p>\n<p>    \/\/ \u6790\u6784\u51fd\u6570<br \/>\n    ~locker() {<br \/>\n        pthread_mutex_destroy(&amp;m_mutex);<br \/>\n    }<br \/>\nprivate:<br \/>\n    pthread_mutex_t m_mutex;    \/\/ \u4e92\u65a5\u9501<br \/>\n};<\/p>\n<p>\/\/ \u6761\u4ef6\u53d8\u91cf\u7c7b<br \/>\nclass cond {<br \/>\npublic:<br \/>\n    cond() {<br \/>\n        if(pthread_cond_init(&amp;m_cond, NULL) !&#061; 0){<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    ~cond() {<br \/>\n        pthread_cond_destroy(&amp;m_cond);<br \/>\n    }<\/p>\n<p>    bool wait(pthread_mutex_t * mutex) {<br \/>\n        return pthread_cond_wait(&amp;m_cond, mutex) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    bool timewait(pthread_mutex_t * mutex, struct timespec t) {<br \/>\n        return pthread_cond_timedwait(&amp;m_cond, mutex, &amp;t) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    bool signal() {<br \/>\n        return pthread_cond_signal(&amp;m_cond) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    bool broadcast() {<br \/>\n        return pthread_cond_broadcast(&amp;m_cond) &#061;&#061; 0;<br \/>\n    }<br \/>\nprivate:<br \/>\n    pthread_cond_t m_cond;<br \/>\n};<\/p>\n<p>\/\/ \u4fe1\u53f7\u91cf\u7c7b<br \/>\nclass sem {<br \/>\npublic:<br \/>\n    sem() {<br \/>\n        if(sem_init(&amp;m_sem, 0, 0) !&#061; 0) {<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    sem(int num) {<br \/>\n        if(sem_init(&amp;m_sem, 0, num) !&#061; 0) {<br \/>\n            throw std::exception();<br \/>\n        }<br \/>\n    }   <\/p>\n<p>    ~sem() {<br \/>\n        sem_destroy(&amp;m_sem);<br \/>\n    }<\/p>\n<p>    \/\/ \u7b49\u5f85\u4fe1\u53f7\u91cf<br \/>\n    bool wait() {<br \/>\n        return sem_wait(&amp;m_sem) &#061;&#061; 0;<br \/>\n    }<\/p>\n<p>    \/\/ \u589e\u52a0\u4fe1\u53f7\u91cf<br \/>\n    bool post() {<br \/>\n        return sem_post(&amp;m_sem) &#061;&#061; 0;<br \/>\n    }<br \/>\nprivate:<br \/>\n    sem_t m_sem;<br \/>\n};<\/p>\n<p>#endif <\/p>\n<h5>\u00a0 \u00a0 \u00a0 \u00a0 \u7ebf\u7a0b\u6c60 &#8212; threadpool.h<\/h5>\n<p>#ifndef THREADPOOL_H<br \/>\n#define THREADPOOL_H<\/p>\n<p>#include &lt;pthread.h&gt;<br \/>\n#include &lt;list&gt;<br \/>\n#include &#034;locker.h&#034;<br \/>\n#include &lt;exception&gt;<br \/>\n#include &lt;cstdio&gt;<\/p>\n<p>\/\/ \u7ebf\u7a0b\u6c60\u7c7b \u5b9a\u4e49\u6210\u6a21\u677f\u7c7b&#xff1a;\u4e3a\u4e86\u4ee3\u7801\u7684\u590d\u7528<br \/>\ntemplate&lt;typename T&gt;<br \/>\nclass threadpool {<br \/>\npublic:<br \/>\n    threadpool(int thread_number &#061; 8, int m_max_requests &#061; 10000);<br \/>\n    ~threadpool();<br \/>\n    \/\/ \u6dfb\u52a0\u4efb\u52a1<br \/>\n    bool append(T * request);<\/p>\n<p>private:<br \/>\n    static void* worker(void * arg);<br \/>\n    void run();<\/p>\n<p>private:<br \/>\n    \/\/ \u7ebf\u7a0b\u6570\u91cf<br \/>\n    int m_thread_number;<\/p>\n<p>    \/\/ \u5bb9\u5668&#xff1a;\u7ebf\u7a0b\u6c60\u6570\u7ec4&#xff0c;\u5927\u5c0f\u4e3a\u7ebf\u7a0b\u6570\u91cf<br \/>\n    pthread_t * m_threads;<\/p>\n<p>    \/\/ \u8bf7\u6c42\u961f\u5217\u4e2d\u6700\u591a\u5141\u8bb8\u7684\u7b49\u5f85\u5904\u7406\u7684\u8bf7\u6c42\u6570\u91cf<br \/>\n    int m_max_requests;<\/p>\n<p>    \/\/ \u8bf7\u6c42\u961f\u5217<br \/>\n    std::list&lt; T*&gt; m_workqueue;<\/p>\n<p>    \/\/ \u4e92\u65a5\u9501<br \/>\n    locker m_queuelocker;<\/p>\n<p>    \/\/ \u4fe1\u53f7\u91cf&#xff1a;\u7528\u6765\u5224\u65ad\u662f\u5426\u6709\u4efb\u52a1\u8981\u5904\u7406<br \/>\n    sem m_queuestat;<\/p>\n<p>    \/\/ \u662f\u5426\u7ed3\u675f\u7ebf\u7a0b<br \/>\n    bool m_stop;<\/p>\n<p>};<\/p>\n<p>\/\/ \u6784\u9020\u51fd\u6570<br \/>\ntemplate&lt;typename T&gt;<br \/>\nthreadpool&lt;T&gt;::threadpool(int thread_number, int m_max_requests):<br \/>\n    m_thread_number(thread_number),m_max_requests(m_max_requests),<br \/>\n    m_stop(false), m_threads(NULL) {<\/p>\n<p>        if((thread_number &lt;&#061; 0) || (m_max_requests &lt;&#061; 0) ) {<br \/>\n             throw std::exception();<br \/>\n        }<\/p>\n<p>        \/\/ new\u4e00\u4e2a\u6570\u7ec4\u7a7a\u95f4<br \/>\n        m_threads &#061; new pthread_t[m_thread_number];<br \/>\n            \/\/ \u4ece\u5806\u4e2d\u5206\u914d m_thread_number \u4e2a pthread_t \u7c7b\u578b\u7684\u5185\u5b58&#xff0c;\u8fd4\u56de\u5230\u6307\u9488 m_thread \u4e2d<br \/>\n        if(!m_thread_number) {<br \/>\n            throw std::exception();<br \/>\n        }<\/p>\n<p>        \/\/ \u521b\u5efathread_num\u4e2a\u7ebf\u7a0b&#xff0c;\u5e76\u5c06\u5b83\u4eec\u8bbe\u7f6e\u4e3a\u7ebf\u7a0b\u8131\u79bb<br \/>\n        for(int i &#061; 0; i &lt; thread_number; &#043;&#043;i) {<br \/>\n            printf(&#034;create the %dth thread\\\\n&#034;, i);<\/p>\n<p>            \/\/ \u521b\u5efa\u7ebf\u7a0b&#xff1a;\u5728C&#043;&#043;\u4e2d&#xff0c;\u7b2c\u4e09\u4e2a\u53c2\u6570worker\u9700\u8981\u8bbe\u7f6e\u4e3a\u9759\u6001\u51fd\u6570<br \/>\n            if(pthread_create(m_threads &#043; i, NULL, worker, this) !&#061; 0) {<br \/>\n                delete [] m_threads;<br \/>\n                throw std::exception();<br \/>\n            }<\/p>\n<p>            \/\/ \u8bbe\u7f6e\u7ebf\u7a0b\u5206\u79bb<br \/>\n            if(pthread_detach(m_threads[i])) {<br \/>\n                delete[] m_threads;<br \/>\n                throw std::exception();<br \/>\n            }<br \/>\n        }<\/p>\n<p>    }<\/p>\n<p>\/\/ \u6790\u6784\u51fd\u6570<br \/>\ntemplate&lt;typename T&gt;<br \/>\nthreadpool&lt;T&gt;::~threadpool() {<br \/>\n    delete[] m_threads;<br \/>\n    m_stop &#061; true;<br \/>\n}<\/p>\n<p>\/\/ \u6dfb\u52a0\u4efb\u52a1\u51fd\u6570&#xff1a;\u7b49\u5f85\u5904\u7406\u8bf7\u6c42\u6570\u91cf<br \/>\ntemplate&lt;typename T&gt;<br \/>\nbool threadpool&lt;T&gt;::append(T * request) {<\/p>\n<p>    m_queuelocker.lock();   \/\/ \u4e0a\u9501&#xff0c;\u5f00\u59cb\u64cd\u4f5c<br \/>\n    if(m_workqueue.size() &gt; m_max_requests) {<br \/>\n        m_queuelocker.unlock();<br \/>\n        return false;<br \/>\n    }<\/p>\n<p>    m_workqueue.push_back(request); \/\/ \u5c06\u5143\u7d20\u6dfb\u52a0\u5230\u5bb9\u5668\u672b\u5c3e<br \/>\n    m_queuelocker.unlock(); \/\/ \u89e3\u9501&#xff0c;\u505c\u6b62\u64cd\u4f5c<br \/>\n    m_queuestat.post(); \/\/ \u89e3\u9501&#xff0c;\u4fe1\u53f7\u91cf&#043;1<br \/>\n    return true;<br \/>\n}<\/p>\n<p>\/\/ \u9759\u6001worker &#8212; \u5728\u521b\u5efa\u7ebf\u7a0b\u51fd\u6570\u4e2d\u4e3a\u53c2\u6570<br \/>\ntemplate&lt;typename T&gt;<br \/>\nvoid* threadpool&lt;T&gt;::worker(void * arg) {<br \/>\n    threadpool * pool &#061; (threadpool *) arg;<br \/>\n    pool-&gt;run();    \/\/ \u8c03\u7528private\u4e2d\u7684\u65b9\u6cd5run()<br \/>\n    return pool;    \/\/ \u8fd4\u56de\u8be5\u5bf9\u8c61<br \/>\n}<\/p>\n<p>template&lt;typename T&gt;<br \/>\nvoid threadpool&lt;T&gt;::run() {<br \/>\n    while(!m_stop) {<br \/>\n        m_queuestat.wait();    \/\/ \u82e5\u8be5\u4fe1\u53f7\u91cf\u6709\u503c&#xff0c;\u5219\u4e0d\u4f1a\u963b\u585e&#xff0c;\u4fe1\u53f7\u91cf-1&#xff1b;\u82e5\u4e3a0&#xff0c;\u5219\u963b\u585e\u7b49\u5f85<br \/>\n        m_queuelocker.lock();   \/\/ \u4e0a\u9501&#xff0c;\u5f00\u59cb\u64cd\u4f5c<br \/>\n        if(m_workqueue.empty()) {<br \/>\n            m_queuelocker.unlock();<br \/>\n            continue;<br \/>\n        }<\/p>\n<p>        T* requests &#061; m_workqueue.front();  \/\/ \u53d6\u51fa\u961f\u9996\u5143\u7d20<br \/>\n        m_workqueue.pop_front();   \/\/ \u53d6\u51fa\u7b2c\u4e00\u4e2a\u5143\u7d20<br \/>\n        m_queuelocker.unlock();<\/p>\n<p>        if(!requests) {<br \/>\n            continue;<br \/>\n        }<\/p>\n<p>        requests-&gt;process();    \/\/\u8fd0\u884c\u4efb\u52a1<br \/>\n    }<\/p>\n<p>}<\/p>\n<p>#endif <\/p>\n<h5>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0http\u8fde\u63a5\u90e8\u5206 &#8212; http_coon.h<\/h5>\n<p>#ifndef HTTPCONNECTION_H<br \/>\n#define HTTPCONNECTION_H<\/p>\n<p>#include &lt;sys\/epoll.h&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;signal.h&gt;<br \/>\n#include &lt;sys\/types.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;sys\/stat.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 &#034;locker.h&#034;<br \/>\n#include &lt;sys\/uio.h&gt;<\/p>\n<p>class http_conn {<br \/>\npublic:<\/p>\n<p>    static int m_epollfd;   \/\/ \u6240\u6709\u7684socket\u4e0a\u7684\u4e8b\u4ef6\u90fd\u88ab\u6ce8\u518c\u5230\u540c\u4e00\u4e2aepoll\u5bf9\u8c61\u4e2d&#xff0c;\u6240\u4ee5\u8bbe\u7f6e\u6210\u9759\u6001\u7684<br \/>\n    static int m_user_count;    \/\/ \u7edf\u8ba1\u7528\u6237\u7684\u6570\u91cf<\/p>\n<p>    http_conn() {<\/p>\n<p>    }<br \/>\n    ~http_conn() {<\/p>\n<p>    }<br \/>\n    void process();    \/\/ \u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42<br \/>\n    void init(int sockfd, const sockaddr_in &amp; addr);    \/\/ \u521d\u59cb\u5316\u65b0\u63a5\u6536\u7684\u8fde\u63a5<br \/>\n    void close_conn();  \/\/ \u5173\u95ed\u8fde\u63a5<br \/>\n    bool read();    \/\/ \u975e\u963b\u585e\u7684\u8bfb<br \/>\n    bool write();   \/\/ \u975e\u963b\u585e\u7684\u5199<\/p>\n<p>private:<br \/>\n    int m_sockfd;   \/\/ \u8be5http\u8fde\u63a5\u7684socket\u5957\u63a5\u5b57<br \/>\n    sockaddr_in m_address;  \/\/ \u901a\u4fe1\u7684socket\u5730\u5740<\/p>\n<p>};<\/p>\n<p>#endif <\/p>\n<h5>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0http\u8fde\u63a5\u90e8\u5206 &#8212; http_coon.cpp<\/h5>\n<p>#include &#034;http_conn.h&#034;<\/p>\n<p>int http_conn::m_epollfd &#061; -1;<br \/>\nint http_conn::m_user_count &#061; 0;<\/p>\n<p>\/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u975e\u963b\u585e<br \/>\nint setnonblocking(int fd) {<br \/>\n    int old_flag &#061; fcntl(fd, F_GETFL);<br \/>\n    int new_flag &#061; old_flag | O_NONBLOCK;<br \/>\n    fcntl(fd, F_SETFL, new_flag);<br \/>\n}<\/p>\n<p>\/\/ \u7528\u6765\u5411epoll\u4e2d\u6dfb\u52a0\u9700\u8981\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\nvoid addfd(int epollfd, int fd, bool one_shot) {<br \/>\n    epoll_event event;<br \/>\n    event.data.fd &#061; fd;<br \/>\n    event.events &#061; EPOLLIN | EPOLLRDHUP;<\/p>\n<p>    if(one_shot) {<br \/>\n        event.events |&#061; EPOLLONESHOT;   \/\/ \u6309\u4f4d\u6216\u5e76\u8d4b\u503c<br \/>\n    }<\/p>\n<p>    epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &amp;event);<\/p>\n<p>    \/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u975e\u963b\u585e<br \/>\n    setnonblocking(fd);    \/\/**<br \/>\n}<\/p>\n<p>\/\/ \u4eceepoll\u4e2d\u79fb\u9664\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\nvoid removefd(int epollfd, int fd) {<br \/>\n    epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, 0);<br \/>\n    close(fd);<br \/>\n}<\/p>\n<p>\/\/ \u4fee\u6539\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u91cd\u7f6esocket\u4e0a\u7684EPOLLONESHOT\u4e8b\u4ef6&#xff0c;\u4ee5\u786e\u4fdd\u4e0b\u4e00\u6b21\u53ef\u8bfb\u65f6&#xff0c;EPOLLIN\u4e8b\u4ef6\u53ef\u88ab\u89e6\u53d1<br \/>\nvoid modfd(int epollfd, int fd, int ev) {<br \/>\n    epoll_event event;<br \/>\n    event.data.fd &#061; fd;<br \/>\n    event.events &#061; ev | EPOLLONESHOT | EPOLLRDHUP;<br \/>\n    epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, &amp;event);<br \/>\n}<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u8fde\u63a5<br \/>\nvoid http_conn::init(int sockfd, const sockaddr_in &amp; addr) {<br \/>\n    m_sockfd &#061; sockfd;<br \/>\n    m_address &#061; addr;<\/p>\n<p>    \/\/ \u8bbe\u7f6esockfd\u7684\u7aef\u53e3\u590d\u7528<br \/>\n    int reuse &#061; 1;<br \/>\n    setsockopt(m_sockfd, SOL_SOCKET, SO_REUSEADDR, &amp;reuse, sizeof(reuse));<\/p>\n<p>    \/\/ \u6dfb\u52a0\u5230epoll\u5bf9\u8c61\u4e2d<br \/>\n    addfd(m_epollfd, m_sockfd, true);    \/\/\u6dfb\u52a0EPOLLEPOLLONESHOT\u4e8b\u4ef6<br \/>\n    m_user_count&#043;&#043;;    \/\/ \u603b\u7528\u6237\u6570&#043;1<br \/>\n}<\/p>\n<p>\/\/ \u5173\u95ed\u8fde\u63a5<br \/>\nvoid http_conn::close_conn() {<br \/>\n    if(m_sockfd !&#061; -1) {<br \/>\n        \/\/ \u5220\u9664<br \/>\n        removefd(m_epollfd, m_sockfd);<br \/>\n        m_sockfd &#061; -1;  \/\/ \u5f53sockfd\u4e3a-1\u65f6&#xff0c;\u5c31\u6ca1\u6709\u7528\u4e86<br \/>\n        m_user_count&#8211;;    \/\/ \u5173\u95ed\u8fde\u63a5&#xff0c;\u5ba2\u6237\u603b\u6570\u91cf-1<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u5faa\u73af\u8bfb\u53d6\u5ba2\u6237\u6570\u636e&#xff0c;\u76f4\u5230\u65e0\u6570\u636e\u53ef\u8bfb\u6216\u8005\u5bf9\u65b9\u5173\u95ed\u8fde\u63a5<br \/>\nbool http_conn::read() {<br \/>\n    printf(&#034;read data\\\\n&#034;);<br \/>\n    return true;<br \/>\n}<\/p>\n<p>bool http_conn::write() {<br \/>\n    printf(&#034;write data\\\\n&#034;);<br \/>\n    return true;<br \/>\n}<\/p>\n<p>\/\/ \u4e1a\u52a1\u903b\u8f91<br \/>\n\/\/ \u7531\u7ebf\u7a0b\u6c60\u4e2d\u7684\u5de5\u4f5c\u7ebf\u7a0b\u8c03\u7528&#xff0c;\u8fd9\u662f\u5904\u7406HTTP\u8bf7\u6c42\u7684\u5165\u53e3\u51fd\u6570<br \/>\nvoid http_conn::process() {<br \/>\n    \/\/ \u89e3\u6790HTTP\u8bf7\u6c42<\/p>\n<p>    printf(&#034;parse request, create response\\\\n&#034;);<\/p>\n<p>    \/\/ \u751f\u6210\u54cd\u5e94<\/p>\n<p>} <\/p>\n<h5>\u00a0 \u00a0 \u00a0 \u00a0 main.cpp\u00a0<\/h5>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.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;unistd.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include &lt;fcntl.h&gt;<br \/>\n#include &lt;sys\/epoll.h&gt;<br \/>\n#include &#034;locker.h&#034;<br \/>\n#include &#034;threadpool.h&#034;<br \/>\n#include &lt;signal.h&gt;<br \/>\n#include &#034;http_conn.h&#034;<\/p>\n<p>#define MAX_FD 65535    \/\/ \u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2a\u6570<br \/>\n#define MAX_EVENT_NUMBER 10000     \/\/ \u4e00\u6b21\u76d1\u542c\u7684\u6700\u5927\u7684\u65f6\u95f4\u6570\u91cf<\/p>\n<p>\/\/ \u6dfb\u52a0\u4fe1\u53f7\u6355\u6349<br \/>\nvoid addsig(int sig, void(handler)(int)) {<br \/>\n    struct sigaction sa;    \/\/ \u521b\u5efa\u4e00\u4e2asigaction\u7ed3\u6784\u4f53\u53d8\u91cfsa<br \/>\n    memset(&amp;sa, &#039;\\\\0&#039;, sizeof(sa));<br \/>\n    sa.sa_handler &#061; handler;    \/\/ \u51fd\u6570\u6307\u9488 \u6307\u5411\u7684\u51fd\u6570\u5c31\u662f\u4fe1\u53f7\u6355\u6349\u5230\u4e4b\u540e\u7684\u5904\u7406\u51fd\u6570<br \/>\n    sigfillset(&amp;sa.sa_mask);    \/\/ \u5c06\u4fe1\u53f7\u96c6\u4e2d\u7684\u6240\u6709\u6807\u5fd7\u4f4d\u90fd\u7f6e\u4e3a1<br \/>\n    sigaction(sig, &amp;sa, NULL);    \/\/ \u68c0\u67e5\u6216\u6539\u53d8\u4fe1\u53f7\u7684\u5904\u7406&#xff0c;\u8fdb\u884c\u4fe1\u53f7\u6355\u6349<br \/>\n        \/\/ \u9700\u8981\u6355\u6349\u7684\u4fe1\u53f7\u7f16\u53f7\u6216\u5b8f\u503c&#xff0c;\u6355\u6349\u540e\u7684\u5904\u7406\u52a8\u4f5c&#xff0c;\u5bf9\u4e0a\u4e00\u6b21\u6355\u6349\u76f8\u5173\u7684\u8bbe\u7f6e<\/p>\n<p>}<\/p>\n<p>\/\/ \u6dfb\u52a0\u6587\u4ef6\u63cf\u8ff0\u7b26\u5230epoll\u4e2d<br \/>\nextern void addfd(int epollfd, int fd, bool oneshot);<br \/>\n\/\/ \u4eceepoll\u4e2d\u5220\u9664\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\nextern void removefd(int epollfd, int fd);<br \/>\n\/\/ \u4fee\u6539\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\nextern void modfd(int epollfd, int fd, int ev);<\/p>\n<p>\/*<br \/>\n    \u4f20\u9012\u53c2\u6570&#xff1a;argc &#8212; \u7aef\u53e3\u53f7<br \/>\n*\/<br \/>\nint main(int argc, char * argv[]) {<\/p>\n<p>    if( argc &lt;&#061; 1) {<br \/>\n        printf(&#034;\u6309\u7167\u5982\u4e0b\u683c\u5f0f\u8fd0\u884c&#xff1a;%s port_number\\\\n&#034;, basename(argv[0]));<br \/>\n        exit(-1);<br \/>\n    }<\/p>\n<p>    \/\/ \u83b7\u53d6\u7aef\u53e3\u53f7<br \/>\n    int port &#061; atoi(argv[1]);<\/p>\n<p>    \/\/ \u5bf9SIGPIPE\u4fe1\u53f7\u8fdb\u884c\u5904\u7406<br \/>\n    addsig(SIGPIPE, SIG_IGN);  \/\/\u5ffd\u7565\u8be5\u4fe1\u53f7<\/p>\n<p>    \/\/ \u521b\u5efa\u7ebf\u7a0b\u6c60\u5e76\u521d\u59cb\u5316<br \/>\n    threadpool&lt;http_conn&gt; * pool &#061;  NULL;<br \/>\n    try {<br \/>\n        pool &#061; new threadpool&lt;http_conn&gt;;<br \/>\n    } catch(&#8230;) {<br \/>\n        exit(-1);<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efa\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u7528\u4e8e\u4fdd\u5b58\u6240\u6709\u7684\u5ba2\u6237\u7aef\u4fe1\u606f<br \/>\n    http_conn * users &#061; new http_conn[ MAX_FD ];<\/p>\n<p>    int listenfd &#061; socket(PF_INET, SOCK_STREAM, 0);    \/\/ \u521b\u5efa\u4e00\u4e2a\u76d1\u542c\u7684\u5957\u63a5\u5b57<br \/>\n    \/*<br \/>\n    if(listenfd &#061; -1) {<br \/>\n        printf(&#034;error socket\\\\n&#034;);<br \/>\n        perror(&#034;socket&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    *\/<br \/>\n    \/\/ \u8bbe\u7f6e\u7aef\u53e3\u590d\u7528<br \/>\n    int reuse &#061; 1;<br \/>\n    setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &amp;reuse, sizeof(reuse));<\/p>\n<p>    \/\/ \u7ed1\u5b9a<br \/>\n    struct sockaddr_in address;<br \/>\n    address.sin_family &#061; AF_INET;<br \/>\n    address.sin_addr.s_addr &#061; INADDR_ANY;   \/\/ \u4efb\u4f55\u53ef\u4ee5\u7ed1\u5b9a\u7684<br \/>\n    address.sin_port &#061; htons(port);    \/\/ \u76d1\u542c\u7aef\u53e3 \u4e3b\u673a\u5b57\u8282\u5e8f&#8211;&gt;\u7f51\u7edc\u5b57\u8282\u5e8f<\/p>\n<p>    bind(listenfd, (struct sockaddr*)&amp;address, sizeof(address));<br \/>\n    \/*<br \/>\n    if(ret &#061; -1) {<br \/>\n        perror(&#034;bind&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    *\/<\/p>\n<p>    \/\/ \u76d1\u542c<br \/>\n    listen(listenfd, 5);<br \/>\n    \/*<br \/>\n    if(ret &#061;&#061; -1) {<br \/>\n        perror(&#034;listen&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    *\/<\/p>\n<p>    \/\/ \u521b\u5efaepoll\u5bf9\u8c61&#xff0c;\u4e8b\u4ef6\u6570\u7ec4&#xff0c;\u6dfb\u52a0\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n    epoll_event events[ MAX_EVENT_NUMBER ];<br \/>\n    int epollfd &#061; epoll_create(5);<\/p>\n<p>    \/\/ \u5c06\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6dfb\u52a0\u5230epoll\u5bf9\u8c61\u4e2d<br \/>\n    addfd(epollfd, listenfd, false);    \/\/ \u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0d\u9700\u8981\u6dfb\u52a0EPOLLONESHOT\u4e8b\u4ef6<br \/>\n    http_conn::m_epollfd &#061; epollfd;<\/p>\n<p>    \/\/\u4e3b\u7ebf\u7a0b\u4e0d\u65ad\u5faa\u73af\u68c0\u67e5\u6709\u54ea\u4e9b\u4e8b\u4ef6\u53d1\u751f<br \/>\n    while(true) {<br \/>\n        \/\/ \u68c0\u6d4b\u5230\u4e86\u51e0\u4e2a\u4e8b\u4ef6<br \/>\n        int num &#061; epoll_wait(epollfd, events, MAX_EVENT_NUMBER, -1);<br \/>\n        if((num &lt; 0) &amp;&amp; (errno !&#061; EINTR)) {<br \/>\n            \/\/ \u8c03\u7528\u5931\u8d25<br \/>\n            printf(&#034;epoll failure\\\\n&#034;);<br \/>\n            break;<br \/>\n        }<\/p>\n<p>        \/\/ \u5faa\u73af\u904d\u5386\u4e8b\u4ef6\u6570\u7ec4<br \/>\n        for(int i &#061; 0; i &lt; num; i&#043;&#043;) {<br \/>\n            \/\/ \u83b7\u53d6\u76d1\u542c\u5230\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n            int sockfd &#061; events[i].data.fd;<br \/>\n            if(sockfd &#061;&#061; listenfd) {<br \/>\n                \/\/ \u6709\u5ba2\u6237\u7aef\u8fde\u63a5\u8fdb\u6765<br \/>\n                struct sockaddr_in client_address;<br \/>\n                socklen_t client_addrlen &#061; sizeof(client_address);<\/p>\n<p>                \/\/ \u8fde\u63a5\u5ba2\u6237\u7aef<br \/>\n                int connfd &#061; accept(listenfd, (struct sockaddr*)&amp;client_address, &amp;client_addrlen);<\/p>\n<p>                if(http_conn::m_user_count &gt;&#061; MAX_FD) {<br \/>\n                    \/\/ \u8bf4\u660e\u76ee\u524d\u8fde\u63a5\u6570\u6ee1\u4e86<br \/>\n                    \/\/ \u7ed9\u5ba2\u6237\u7aef\u5199\u4e00\u4e2a\u4fe1\u606f&#xff1a;\u670d\u52a1\u5668\u6b63\u5fd9&#xff08;\u3002\u3002\u3002&#xff09;<br \/>\n                    close(connfd);<br \/>\n                    continue;<br \/>\n                }<\/p>\n<p>                \/\/ \u5c06\u65b0\u7684\u5ba2\u6237\u6570\u636e\u521d\u59cb\u5316&#xff0c;\u653e\u5165\u6570\u7ec4\u4e2d(\u628aconnfd\u4f5c\u4e3ausers\u7684\u7d22\u5f15)<br \/>\n                users[connfd].init(connfd, client_address);    \/\/ \u521d\u59cb\u5316<\/p>\n<p>            } else if(events[i].events &amp; (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) {<\/p>\n<p>                \/\/ \u5bf9\u65b9\u5f02\u5e38\u65ad\u5f00\u6216\u8005\u9519\u8bef\u7b49\u4e8b\u4ef6<br \/>\n                \/\/ \u5173\u95ed\u8fde\u63a5<br \/>\n                users[sockfd].close_conn();<\/p>\n<p>            } else if(events[i].events &amp; EPOLLIN) {<\/p>\n<p>                \/\/ \u5224\u65ad\u8bfb\u4e8b\u4ef6<br \/>\n                if(users[sockfd].read()) {<br \/>\n                    \/\/ \u4e00\u6b21\u6027\u628a\u6240\u6709\u6570\u636e\u90fd\u8bfb\u51fa\u6765<br \/>\n                    pool-&gt;append(users &#043; sockfd);   \/\/**<br \/>\n                } else {<br \/>\n                    users[sockfd].close_conn();<br \/>\n                }<\/p>\n<p>            } else if(events[i].events &amp; EPOLLOUT) {<\/p>\n<p>                \/\/ \u5224\u65ad\u5199\u4e8b\u4ef6<br \/>\n                if( !users[sockfd].write() ){<br \/>\n                    \/\/ \u4e00\u6b21\u6027\u5199\u5b8c\u6240\u6709\u6570\u636e<br \/>\n                    users[sockfd].close_conn();<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    close(epollfd);<br \/>\n    close(listenfd);<br \/>\n    delete [] users;<br \/>\n    delete pool;<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<h3>1.3 \u6d4b\u8bd5\u8fd0\u884c&#xff08;\u6846\u67b6&#xff09;<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2460 \u7f16\u8bd1\u540e\u751f\u6210\u201ca.out\u201d\u7684exe\u6587\u4ef6&#xff0c;\u8f93\u5165\u547d\u4ee4\u8fd0\u884c&#xff08;\u6211\u7684Linux\u7684ip\u5730\u5740\u4e3a192.168.200.133&#xff09;<\/p>\n<p>.\/a.out 10000    \/\/ 10000\u662f\u7aef\u53e3\u53f7  <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u2461 \u5728Windows\u7f51\u9875\u4e2d&#xff08;\u6216Linux\u7684\u706b\u72d0\u6d4f\u89c8\u5668&#xff09;\u8f93\u5165\u7f51\u5740\u8fde\u63a5<\/p>\n<p>http:\/\/192.168.200.133:10000 <\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6b64\u65f6xshell\u4e2d\u663e\u793a\u8fd0\u884c\u7ed3\u679c<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"233\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221328-6802ce8864e21.png\" width=\"373\" \/><\/p>\n<\/p>\n<h3>2 \u89e3\u6790HTTP\u62a5\u6587<\/h3>\n<p>\u4e3b\u8981\u662f\u5bf9http_conn\u4e2d\u7684\u5177\u4f53\u5b9e\u73b0\u8fdb\u884c\u7f16\u5199<\/p>\n<h4>2.1 read\u90e8\u5206<\/h4>\n<p>\u5728\u7c7b\u4e2d\u589e\u52a0\u5982\u4e0b\u4fe1\u606f&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"972\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221328-6802ce8882f5a.png\" width=\"1200\" \/><\/p>\n<p>\u5c06\u6dfb\u52a0\u76d1\u542c\u6587\u4ef6\u6539\u6210\u8fb9\u6cbf\u89e6\u53d1&#xff1a;&#xff08;\u5b58\u5728\u95ee\u9898&#xff1a;listenfd\u4e5f\u53d8\u6210\u4e86\u8fb9\u6cbf\u89e6\u53d1&#xff09;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"495\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221329-6802ce89013b5.png\" width=\"986\" \/><\/p>\n<p>read() :\u00a0<\/p>\n<p>\/\/ \u5faa\u73af\u8bfb\u53d6\u5ba2\u6237\u6570\u636e&#xff0c;\u76f4\u5230\u65e0\u6570\u636e\u53ef\u8bfb\u6216\u8005\u5bf9\u65b9\u5173\u95ed\u8fde\u63a5<br \/>\nbool http_conn::read() {<\/p>\n<p>    if(m_read_idx &gt;&#061; READ_BUFFER_SIZE) {<br \/>\n        return false;<br \/>\n    }<\/p>\n<p>    \/\/ \u5b9a\u4e49\u4e00\u4e2a\u8bfb\u53d6\u5230\u7684\u5b57\u8282<br \/>\n    int bytes_read &#061; 0;<br \/>\n    while (1)<br \/>\n    {<br \/>\n        bytes_read &#061; recv(m_sockfd, m_read_buf &#043; m_read_idx, READ_BUFFER_SIZE &#8211; m_read_idx, 0);<br \/>\n        if(bytes_read &#061;&#061; -1) {<br \/>\n            if(errno &#061;&#061; EAGAIN || errno &#061;&#061; EWOULDBLOCK) {<br \/>\n                \/\/ \u975e\u963b\u585e\u7684\u8bfb\u7684\u65f6\u5019\u4f1a\u51fa\u73b0\u8fd9\u4e24\u4e2a\u9519\u8bef &#8212; \u6ca1\u6709\u6570\u636e\u7684\u60c5\u51b5<br \/>\n                break;  \/\/ \u5df2\u8bfb\u5b8c&#xff0c;\u9000\u51fa\u5faa\u73af<br \/>\n            }<br \/>\n            return false;<br \/>\n        } else if(bytes_read &#061;&#061; 0) {<br \/>\n            \/\/ \u5bf9\u65b9\u5173\u95ed\u8fde\u63a5<br \/>\n            return false;<br \/>\n        }<br \/>\n        m_read_idx &#043;&#061; bytes_read;<br \/>\n    }<\/p>\n<p>    printf(&#034;read data:%s\\\\n&#034;,m_read_buf);<br \/>\n    return true;<br \/>\n} <\/p>\n<p>\u6d4b\u8bd5\u8fd0\u884c&#xff1a;\u8bfb\u53d6\u5230\u7684\u8bf7\u6c42\u62a5\u6587<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"514\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221329-6802ce8934068.png\" width=\"851\" \/><\/p>\n<h4>2.2 \u6709\u9650\u72b6\u6001\u673a<\/h4>\n<p>&#xff08;http_conn.h&#xff09;\u5229\u7528\u679a\u4e3e\u8bbe\u7f6e\u72b6\u6001&#xff08;\u8bf7\u6c42\u65b9\u6cd5\u3001\u4e3b\u72b6\u6001\u673a\u3001\u4ece\u72b6\u6001\u673a&#xff09;&#xff1a;<\/p>\n<p>    \/\/ HTTP\u8bf7\u6c42\u65b9\u6cd5&#xff0c;\u8fd9\u91cc\u53ea\u652f\u6301GET<br \/>\n    enum METHOD {GET &#061; 0, POST, HEAD, PUT, DELETE, TRACE, OPTIONS, CONNECT};<\/p>\n<p>    \/*<br \/>\n        \u89e3\u6790\u5ba2\u6237\u7aef\u8bf7\u6c42\u65f6&#xff0c;\u4e3b\u72b6\u6001\u673a \u7684\u72b6\u6001<br \/>\n        CHECK_STATE_REQUESTLINE:\u5f53\u524d\u6b63\u5728\u5206\u6790 \u8bf7\u6c42\u884c<br \/>\n        CHECK_STATE_HEADER:\u5f53\u524d\u6b63\u5728\u5206\u6790 \u5934\u90e8\u5b57\u6bb5<br \/>\n        CHECK_STATE_CONTENT:\u5f53\u524d\u6b63\u5728\u89e3\u6790 \u8bf7\u6c42\u4f53<br \/>\n    *\/<br \/>\n    enum CHECK_STATE { CHECK_STATE_REQUESTLINE &#061; 0, CHECK_STATE_HEADER, CHECK_STATE_CONTENT };<\/p>\n<p>    \/\/ \u4ece\u72b6\u6001\u673a \u7684\u4e09\u79cd\u53ef\u80fd\u72b6\u6001&#xff0c;\u5373\u884c\u7684\u8bfb\u53d6\u72b6\u6001&#xff0c;\u5206\u522b\u8868\u793a<br \/>\n    \/\/ 1.\u8bfb\u53d6\u5230\u4e00\u4e2a\u5b8c\u6574\u7684\u884c 2.\u884c\u51fa\u9519 3.\u884c\u6570\u636e\u5c1a\u4e14\u4e0d\u5b8c\u6574<br \/>\n    enum LINE_STATUS { LINE_OK &#061; 0, LINE_BAD, LINE_OPEN };<\/p>\n<p>    \/*<br \/>\n        \u670d\u52a1\u5668\u5904\u7406HTTP\u8bf7\u6c42\u7684\u53ef\u80fd\u7ed3\u679c&#xff0c;\u62a5\u6587\u89e3\u6790\u7684\u7ed3\u679c<br \/>\n        NO_REQUEST          :   \u8bf7\u6c42\u4e0d\u5b8c\u6574&#xff0c;\u9700\u8981\u7ee7\u7eed\u8bfb\u53d6\u5ba2\u6237\u6570\u636e<br \/>\n        GET_REQUEST         :   \u8868\u793a\u83b7\u5f97\u4e86\u4e00\u4e2a\u5b8c\u6210\u7684\u5ba2\u6237\u8bf7\u6c42<br \/>\n        BAD_REQUEST         :   \u8868\u793a\u5ba2\u6237\u8bf7\u6c42\u8bed\u6cd5\u9519\u8bef<br \/>\n        NO_RESOURCE         :   \u8868\u793a\u670d\u52a1\u5668\u6ca1\u6709\u8d44\u6e90<br \/>\n        FORBIDDEN_REQUEST   :   \u8868\u793a\u5ba2\u6237\u5bf9\u8d44\u6e90\u6ca1\u6709\u8db3\u591f\u7684\u8bbf\u95ee\u6743\u9650<br \/>\n        FILE_REQUEST        :   \u6587\u4ef6\u8bf7\u6c42,\u83b7\u53d6\u6587\u4ef6\u6210\u529f<br \/>\n        INTERNAL_ERROR      :   \u8868\u793a\u670d\u52a1\u5668\u5185\u90e8\u9519\u8bef<br \/>\n        CLOSED_CONNECTION   :   \u8868\u793a\u5ba2\u6237\u7aef\u5df2\u7ecf\u5173\u95ed\u8fde\u63a5\u4e86<br \/>\n    *\/<br \/>\n    enum HTTP_CODE { NO_REQUEST, GET_REQUEST, BAD_REQUEST, NO_RESOURCE, FORBIDDEN_REQUEST, FILE_REQUEST, INTERNAL_ERROR, CLOSED_CONNECTION };<\/p>\n<h4>2.3 \u5177\u4f53\u4ee3\u7801\u5b9e\u73b0&#xff08;\u5b8c\u6574&#xff09;<\/h4>\n<\/p>\n<h3>3 C&#043;&#043;\u76f8\u5173\u77e5\u8bc6\u70b9<\/h3>\n<h4>3.1 \u629b\u51fa\u5f02\u5e38<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw \u5173\u952e\u5b57\u7528\u6765\u663e\u5f0f\u5730\u629b\u51fa\u5f02\u5e38&#xff1b;C&#043;&#043;\u4e2d\u7684 throw\u8be6\u89e3_c&#043;&#043; throw-CSDN\u535a\u5ba2<\/p>\n<p>#include &lt;exception&gt;<\/p>\n<p>throw std::exception(); <\/p>\n<h4>3.2 new<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4ece\u5806\u4e2d\u5206\u914d\u5185\u5b58&#xff0c;\u5e76\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u6240\u5206\u914d\u5185\u5b58\u7684\u6307\u9488<\/p>\n<h4>3.3 this\u6307\u9488<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6307\u5411\u5f53\u524d\u5bf9\u8c61\u7684\u5730\u5740&#xff08;\u8c03\u7528\u8be5\u6210\u5458\u51fd\u6570\u7684\u5bf9\u8c61\u7684\u5730\u5740&#xff09;<\/p>\n<h4>3.4 basename \u7528\u6cd5<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u83b7\u53d6\u5f53\u524d\u8def\u5f84\u6700\u540e\u4e00\u4e2a<\/p>\n<h4>3.5 memset \u5185\u5b58\u521d\u59cb\u5316\u51fd\u6570<\/h4>\n<p>memset(\u6307\u5411\u5185\u5b58\u533a\u57df\u7684\u6307\u9488&#xff0c;\u8981\u8bbe\u7f6e\u7684\u7279\u5b9a\u503c&#xff0c;\u8981\u8bbe\u7f6e\u7684\u5b57\u8282\u6bb5);<\/p>\n<h4>3.6 try-catch<\/h4>\n<p>try {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u8bed\u53e5<\/p>\n<p>} catch {<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5904\u7406\u5f02\u5e38\u8bed\u53e5<\/p>\n<p>}<\/p>\n<h4>3.7 extern \u5173\u952e\u5b57<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5728\u522b\u7684\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e86&#xff0c;\u63d0\u9192\u7f16\u8bd1\u5668\u53bb\u627e<\/p>\n<h4>3.8 \u7c7b\u4f5c\u7528\u57df<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5982\u672c\u9879\u76ee&#xff0c;\u5728http_conn.h\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u679a\u4e3e\u7c7b&#xff0c;\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6210\u5458\u51fd\u6570\u8fd4\u56de\u8fd9\u4e9b\u679a\u4e3e\u7c7b\u3002&#xff08;\u7c7b\u5185\u5b9a\u4e49&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5728\u7c7b\u5916\u5b9e\u73b0\u65f6&#xff08;http_conn.cpp&#xff09;\u9700\u5728\u679a\u4e3e\u7c7b\u548c\u6210\u5458\u51fd\u6570\u540d\u524d\u90fd\u52a0\u4e0a\u7c7b\u7684\u4f5c\u7528\u57df&#xff0c;\u4e0d\u7136\u4f1a\u62a5\u9519\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"94\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221329-6802ce896903a.png\" width=\"826\" \/><\/p>\n<h4>3.9 \u5185\u8054\u51fd\u6570inline<\/h4>\n<p>\u53c2\u8003\u8d44\u6599&#xff1a;<\/p>\n<p>\u3010C&#043;&#043;\u3011C&#043;&#043;\u4e2d\u5185\u8054\u51fd\u6570\u8be6\u89e3&#xff08;\u641e\u6e05\u5185\u8054\u7684\u672c\u8d28\u53ca\u7528\u6cd5&#xff09;-CSDN\u535a\u5ba2<\/p>\n<h4>3.10 \u7528\u5230\u7684string\u5e93\u4e2d\u7684\u4e00\u4e9b\u51fd\u6570<\/h4>\n<\/p>\n<h3>4 \u95ee\u9898\u89e3\u51b3<\/h3>\n<h4>4.1 \u7f16\u8bd1\u9519\u8bef<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5728\u5b8c\u6210\u4e3b\u4f53\u6846\u67b6\u540e\u8fdb\u884c\u7f16\u8bd1&#xff08;gcc *.cpp -pthread&#xff09;\u63d0\u793a\u9519\u8bef\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"726\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221329-6802ce8986487.png\" width=\"1200\" \/><\/p>\n<p>\u89e3\u51b3\u53c2\u8003\u8d44\u6599&#xff1a;\u4f7f\u7528gcc\u7f16\u8bd1c&#043;&#043;\u7a0b\u5e8f\u65f6\u51fa\u73b0\u7c7b\u4f3c\u5bf9\u2018operator new[](unsigned long)\u2019\u672a\u5b9a\u4e49\u7684\u5f15\u7528_\u5bf9\u2018operator new(unsigned long)\u2019\u672a\u5b9a\u4e49\u7684\u5f15\u7528-CSDN\u535a\u5ba2<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u6dfb\u52a0-lstdc&#043;&#043;&#xff0c;\u5373\u53ef\u7f16\u8bd1\u6210\u529f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"84\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221329-6802ce89ea81e.png\" width=\"771\" \/><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e28\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u2460 \u7f16\u8bd1\u540e\u751f\u6210\u201ca.out\u201d\u7684exe\u6587\u4ef6\uff0c\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff08\u6211\u7684Linux\u7684ip\u5730\u5740\u4e3a192.168.200.133\uff09\u5982\u672c\u9879\u76ee\uff0c\u5728http_conn.h\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u679a\u4e3e\u7c7b\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6210\u5458\u51fd\u6570\u8fd4\u56de\u8fd9\u4e9b\u679a\u4e3e\u7c7b\u3002\u5728\u7c7b\u5916\u5b9e\u73b0\u65f6\uff08http_conn.cpp\uff09\u9700\u5728\u679a\u4e3e\u7c7b\u548c\u6210\u5458\u51fd\u6570\u540d\u524d\u90fd\u52a0\u4e0a\u7c7b\u7684\u4f5c\u7528\u57df\uff0c\u4e0d\u7136\u4f1a\u62a5\u9519\u3002\u2461 \u5728Windows\u7f51\u9875\u4e2d\uff08\u6216Linux\u7684\u706b\u72d0\u6d4f\u89c8\u5668\uff09\u8f93\u5165\u7f51\u5740\u8fde\u63a5\u3002memset(\u6307\u5411\u5185\u5b58\u533a\u57df\u7684\u6307\u9488\uff0c\u8981\u8bbe\u7f6e\u7684\u7279\u5b9a\u503c\uff0c\u8981\u8bbe\u7f6e\u7684\u5b57\u8282\u6bb5);\u6307\u5411\u5f53\u524d\u5bf9\u8c61\u7684\u5730\u5740\uff08\u8c03\u7528\u8be5\u6210\u5458\u51fd\u6570\u7684\u5bf9\u8c61\u7684\u5730\u5740\uff09\/\/ \u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u8bed\u53e5\u3002_\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee<\/p>\n","protected":false},"author":2,"featured_media":22670,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[190],"topic":[],"class_list":["post-22680","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \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\/22680.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e28\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u2460 \u7f16\u8bd1\u540e\u751f\u6210\u201ca.out\u201d\u7684exe\u6587\u4ef6\uff0c\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff08\u6211\u7684Linux\u7684ip\u5730\u5740\u4e3a192.168.200.133\uff09\u5982\u672c\u9879\u76ee\uff0c\u5728http_conn.h\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u679a\u4e3e\u7c7b\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6210\u5458\u51fd\u6570\u8fd4\u56de\u8fd9\u4e9b\u679a\u4e3e\u7c7b\u3002\u5728\u7c7b\u5916\u5b9e\u73b0\u65f6\uff08http_conn.cpp\uff09\u9700\u5728\u679a\u4e3e\u7c7b\u548c\u6210\u5458\u51fd\u6570\u540d\u524d\u90fd\u52a0\u4e0a\u7c7b\u7684\u4f5c\u7528\u57df\uff0c\u4e0d\u7136\u4f1a\u62a5\u9519\u3002\u2461 \u5728Windows\u7f51\u9875\u4e2d\uff08\u6216Linux\u7684\u706b\u72d0\u6d4f\u89c8\u5668\uff09\u8f93\u5165\u7f51\u5740\u8fde\u63a5\u3002memset(\u6307\u5411\u5185\u5b58\u533a\u57df\u7684\u6307\u9488\uff0c\u8981\u8bbe\u7f6e\u7684\u7279\u5b9a\u503c\uff0c\u8981\u8bbe\u7f6e\u7684\u5b57\u8282\u6bb5);\u6307\u5411\u5f53\u524d\u5bf9\u8c61\u7684\u5730\u5740\uff08\u8c03\u7528\u8be5\u6210\u5458\u51fd\u6570\u7684\u5bf9\u8c61\u7684\u5730\u5740\uff09\/\/ \u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u8bed\u53e5\u3002_\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/22680.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-18T22:13:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221327-6802ce877f085.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\/22680.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/22680.html\",\"name\":\"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T22:13:31+00:00\",\"dateModified\":\"2025-04-18T22:13:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/22680.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/22680.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/22680.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3\"}]},{\"@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":"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \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\/22680.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e28\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\u2460 \u7f16\u8bd1\u540e\u751f\u6210\u201ca.out\u201d\u7684exe\u6587\u4ef6\uff0c\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff08\u6211\u7684Linux\u7684ip\u5730\u5740\u4e3a192.168.200.133\uff09\u5982\u672c\u9879\u76ee\uff0c\u5728http_conn.h\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u679a\u4e3e\u7c7b\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6210\u5458\u51fd\u6570\u8fd4\u56de\u8fd9\u4e9b\u679a\u4e3e\u7c7b\u3002\u5728\u7c7b\u5916\u5b9e\u73b0\u65f6\uff08http_conn.cpp\uff09\u9700\u5728\u679a\u4e3e\u7c7b\u548c\u6210\u5458\u51fd\u6570\u540d\u524d\u90fd\u52a0\u4e0a\u7c7b\u7684\u4f5c\u7528\u57df\uff0c\u4e0d\u7136\u4f1a\u62a5\u9519\u3002\u2461 \u5728Windows\u7f51\u9875\u4e2d\uff08\u6216Linux\u7684\u706b\u72d0\u6d4f\u89c8\u5668\uff09\u8f93\u5165\u7f51\u5740\u8fde\u63a5\u3002memset(\u6307\u5411\u5185\u5b58\u533a\u57df\u7684\u6307\u9488\uff0c\u8981\u8bbe\u7f6e\u7684\u7279\u5b9a\u503c\uff0c\u8981\u8bbe\u7f6e\u7684\u5b57\u8282\u6bb5);\u6307\u5411\u5f53\u524d\u5bf9\u8c61\u7684\u5730\u5740\uff08\u8c03\u7528\u8be5\u6210\u5458\u51fd\u6570\u7684\u5bf9\u8c61\u7684\u5730\u5740\uff09\/\/ \u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u8bed\u53e5\u3002_\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee","og_url":"https:\/\/www.wsisp.com\/helps\/22680.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T22:13:31+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418221327-6802ce877f085.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\/22680.html","url":"https:\/\/www.wsisp.com\/helps\/22680.html","name":"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T22:13:31+00:00","dateModified":"2025-04-18T22:13:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/22680.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/22680.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/22680.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5f00\u53d1\uff08\u516d\uff09webserver\u670d\u52a1\u5668\u9879\u76ee \u4e2a\u4eba\u603b\u7ed3"}]},{"@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\/22680","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=22680"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/22680\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/22670"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=22680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=22680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=22680"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=22680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}