{"id":47,"date":"2025-04-09T17:14:36","date_gmt":"2025-04-09T09:14:36","guid":{"rendered":"http:\/\/120.76.99.214\/?p=47"},"modified":"2025-11-24T16:43:36","modified_gmt":"2025-11-24T08:43:36","slug":"webserver%e9%a2%84%e5%a4%87%e7%9f%a5%e8%af%86%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/www.tgwttt.xyz\/?p=47","title":{"rendered":"webserver\u9884\u5907\u77e5\u8bc6\u5b66\u4e60"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">STL \u5faa\u73af\u961f\u5217\u7f16\u5199<\/h2>\n\n\n\n<p>\u5728c++linux\u7cfb\u7edf\u7f16\u7a0b\u6a21\u5757\uff0c\u5faa\u73af\u961f\u5217\u662f\u5f88\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff08\u793a\u610f\u56fe\u5982\u4e0b\uff09\uff0c\u4f46\u662fc++ stl\u5e93\u5374\u6ca1\u6709\u7ed9\u51fa\u4e00\u4e2a\u5bb9\u5668\u53bb\u5b58\u50a8\uff0c\u65e2\u7136\u6ca1\u6709\u8f6e\u5b50\uff0c\u5c31\u7531\u6211\u4eec\u81ea\u5df1\u9020\u8f6e\u5b50<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"422\" src=\"http:\/\/120.76.99.214\/wp-content\/uploads\/2025\/04\/image-2.png\" alt=\"\" class=\"wp-image-48\" srcset=\"https:\/\/www.tgwttt.xyz\/wp-content\/uploads\/2025\/04\/image-2.png 721w, https:\/\/www.tgwttt.xyz\/wp-content\/uploads\/2025\/04\/image-2-300x176.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/figure>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include <iostream>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <unistd.h>\n#include <sys\/ipc.h>\n#include <sys\/shm.h>\n#include <sys\/types.h>\n#include <sys\/sem.h>\n\nusing namespace std;\n\ntemplate<class TT, int MaxLength>\nclass squeue\n{\nprivate:\n    bool m_inited;\n    TT m_data[MaxLength];\n    int m_head;\n    int m_tail;\n    int m_length;\n\n    \/\/ \u7981\u6b62\u62f7\u8d1d\u6784\u9020\u548c\u8d4b\u503c\u64cd\u4f5c\n    squeue(const squeue&) = delete;\n    squeue& operator=(const squeue&) = delete;\n\npublic:\n    squeue() {\n        init();\n    }\n\n    void init() {\n        if (!m_inited) {\n            m_head = 0;\n            m_tail = MaxLength - 1;\n            m_length = 0;\n            memset(m_data, 0, sizeof(m_data)); \/\/ \u4fee\u6b63\u62fc\u5199\u9519\u8bef\uff1ameset -> memset\n            m_inited = true;\n        }\n    }\n\n    bool push(const TT& ee) {\n        if (full()) {\n            cout << \"add fail\" << endl;\n            return false;\n        } else {\n            m_tail = (m_tail + 1) % MaxLength;\n            m_data[m_tail] = ee;\n            m_length++;\n        }\n        return true;\n    }\n\n    int size() {\n        return m_length;\n    }\n\n    bool empty() {\n        if (m_length == 0) return true; \/\/ \u4fee\u6b63\u62fc\u5199\u9519\u8bef\uff1am_lenth -> m_length\n        return false;\n    }\n\n    bool full() {\n        if (m_length == MaxLength) return true; \/\/ \u4fee\u6b63\u62fc\u5199\u9519\u8bef\uff1aMaxLenth -> MaxLength\n        return false;\n    }\n\n    TT& front() {\n        return m_data[m_head];\n    }\n\n    bool pop() {\n        if (empty()) { \/\/ \u4fee\u6b63\uff1a\u76f4\u63a5\u8c03\u7528empty()\u51fd\u6570\n            return false;\n        } else {\n            m_head = (m_head + 1) % MaxLength;\n            m_length--;\n        }\n        return true;\n    }\n\n    bool printsqueue() const { \/\/ \u6dfb\u52a0const\u4fee\u9970\u7b26\n        for (int ii = 0; ii < m_length; ii++) {\n            cout << m_data[(m_head + ii) % MaxLength] << endl;\n        }\n        return true; \/\/ \u6dfb\u52a0\u8fd4\u56de\u503c\n    }\n\n    TT&#038; back() {\n        return m_data[m_tail];\n    }\n};\n\u5728linux\u548cwindows\u4e0b\u9762\u7ed3\u679c\u4e00\u6837\uff0c\u6709\u4e9b\u5934\u6587\u4ef6\u662f\u535a\u4e3b\u4e3a\u4e86\u65b9\u4fbf\u540e\u7eed\u4ee3\u7801\u5199\u7684\uff0c\u5927\u5bb6\u53ef\u4ee5\u5ffd\u7565\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>STL \u5faa\u73af\u961f\u5217\u7f16\u5199 \u5728c++linux\u7cfb\u7edf\u7f16\u7a0b\u6a21\u5757\uff0c\u5faa\u73af\u961f\u5217\u662f\u5f88\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff08\u793a\u610f\u56fe\u5982\u4e0b\uff09\uff0c\u4f46\u662fc++ st&#8230;<\/p>\n","protected":false},"author":1,"featured_media":48,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":4,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions\/893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/media\/48"}],"wp:attachment":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}