{"id":165285,"date":"2020-10-03T07:56:56","date_gmt":"2020-10-02T23:56:56","guid":{"rendered":"http:\/\/4563.org\/?p=165285"},"modified":"2020-10-03T07:56:56","modified_gmt":"2020-10-02T23:56:56","slug":"c-%e8%af%ad%e8%a8%80%e9%87%8c%e4%b8%8d%e6%94%af%e6%8c%81%e7%9a%84-tcp-%e7%aa%97%e5%8f%a3%e5%a4%a7%e5%b0%8f%e8%b0%83%e6%95%b4%e5%90%97","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=165285","title":{"rendered":"C \u8bed\u8a00\u91cc\u4e0d\u652f\u6301\u7684 TCP \u7a97\u53e3\u5927\u5c0f\u8c03\u6574\u5417"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  C \u8bed\u8a00\u91cc\u4e0d\u652f\u6301\u7684 TCP \u7a97\u53e3\u5927\u5c0f\u8c03\u6574\u5417               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : holinhot <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)\u7f16\u8bd1\u7684\u65f6\u5019\u62a5\u9519\u8bef\u3002<\/p>\n<p>*<em>server2.c: In function \u2018create_server_fd\u2019: server2.c:81:42: error: \u2018TCP_WINDOW_CLAMP\u2019 undeclared (first use in this function) if (setsockopt(serverfd, SOL_SOCKET, TCP_WINDOW_CLAMP, (char <em>)&amp; WINDOW_CLAMP, sizeof(WINDOW_CLAMP)) &lt; 0) ^ server2.c:81:42: note: each undeclared identifier is reported only once for each function it appears in<\/em><\/em><\/p>\n<pre><code>int serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);     int REUSEADDR = 1;     int REUSEPORT = 1;     int WINDOW_CLAMP = 1;     if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&amp;REUSEADDR, sizeof(REUSEADDR)) &lt; 0)         perror(\"setsockopt(SO_REUSEADDR) failed\");     if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&amp;REUSEPORT, sizeof(REUSEPORT)) &lt; 0)         perror(\"setsockopt(SO_REUSEPORT) failed\");     if (setsockopt(serverfd, SOL_SOCKET, TCP_WINDOW_CLAMP, (char *)&amp; WINDOW_CLAMP, sizeof(WINDOW_CLAMP)) &lt; 0)         perror(\"setsockopt(TCP_WINDOW_CLAMP) failed\");       if (serverfd == -1)         EXIT(\"create socket fail\"); <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3638948\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jjshare <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5934\u6587\u4ef6\u6ca1\u5f15\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3638949\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : holinhot <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jjshare \u6709\u5f15\u5165\uff0c\u524d\u9762\u52a0\u7684\u4e24\u4e2a SO_REUSEPORT \u548c SO_REUSEADDR \u6ca1\u95ee\u9898<\/p>\n<p>#include &lt;sys\/types.h&gt;<br \/>#include &lt;sys\/socket.h&gt;<br \/>#include &lt;netinet\/in.h&gt;<br \/>#include &lt;arpa\/inet.h&gt;<br \/>#include &lt;stdio.h&gt;<br \/>#include &lt;stdlib.h&gt;<br \/>#include &lt;unistd.h&gt;<br \/>#include &lt;string.h&gt;<br \/>#include &lt;pthread.h&gt;<br \/>#include &lt;ctype.h&gt;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3638950\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jedihy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             #include &lt;netinet\/tcp.h&gt;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3638951\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : holinhot <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jedihy \u5f15\u5165 include &lt;netinet\/tcp.h&gt;\u662f\u4e0d\u62a5\u9519\u8bef\u4e86\uff0c\u4e0d\u8fc7 TCP_WINDOW_CLAMP \u53c2\u6570\u4e0d\u751f\u6548\u3002\u7528 python \u6d4b\u8bd5 TCP_WINDOW_CLAMP \u662f\u53ef\u4ee5\u751f\u6548\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3638952\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : holinhot <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jedihy \u53ef\u4ee5\u4e86 TCP_WINDOW_CLAMP \u662f IPPROTO_TCP \u4e0b\u7684\u53c2\u6570\u3002c \u65b0\u624b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3638953\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : BrettD <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u62a5\u7684\u662f\u8bed\u6cd5\u9519\u8bef\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>C \u8bed\u8a00\u91cc\u4e0d\u652f\u6301\u7684 TCP \u7a97\u53e3\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165285"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165285"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165285\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165285"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}